]> git.r.bdr.sh - rbdr/forum/blob - app/socket_coordinator.js
Remove server
[rbdr/forum] / app / socket_coordinator.js
1 import { socketServer } from './config/config';
2
3 const internals = {
4
5 socket: null, // stores the socket connection
6
7 connect() {
8
9 internals.socket = new WebSocket(socketServer);
10 }
11 };
12
13 export const onMessage = function (listener) {
14
15 if (!internals.socket) {
16 internals.connect();
17 }
18
19 internals.socket.addEventListener('message', (message) => {
20
21 listener(JSON.parse(message.data));
22 });
23 };