--- /dev/null
+import { socketServer } from './config/config';
+
+const internals = {
+
+ socket: null, // stores the socket connection
+
+ connect() {
+
+ internals.socket = new WebSocket(socketServer);
+ }
+};
+
+export const onMessage = function (listener) {
+
+ if (!internals.socket) {
+ internals.connect();
+ }
+
+ internals.socket.addEventListener('message', (message) => {
+
+ listener(JSON.parse(message.data));
+ });
+};