diff options
Added User Participants functionality
1 files changed, 25 insertions, 2 deletions
| -rw-r--r-- | scripts/services/socketService.js | 27 |
diff --git a/scripts/services/socketService.js b/scripts/services/socketService.js index 89bbd45..186ac3b 100644 --- a/scripts/services/socketService.js +++ b/scripts/services/socketService.js @@ -78,6 +78,25 @@ class SocketService { console.log(message); }); + this.homeConnection.on('OnLoggedIn', (users) => { + users.forEach(user => { + if(!app.htmlService.getElement(`#${user}`)) { + const userNode = app.htmlService + .getElementFromTemplate('user', { + user: user, + }); + + app.htmlService.attachElement(app.htmlService.createElement(userNode), '.participants'); + } + }); + }); + + this.homeConnection.on('OnLoggedOut', (users) => { + users.forEach(user => { + app.htmlService.getElement(`#${user}`).remove(); + }); + }); + this.homeConnection.on('ReceiveMessage', ([user, message]) => { const messageNode = app.htmlService .getElementFromTemplate('message', { @@ -110,8 +129,12 @@ class SocketService { } send(location, method, ...args) { - if(location === 'home') this.homeConnection.invoke(method, ...args); - if(location === 'game') this.gameConnection.invoke(method, ...args); + if(location === 'home') { + this.homeConnection?.invoke(method, ...args); + } + if(location === 'game') { + this.gameConnection?.invoke(method, ...args); + } } } |