Website Summary Files Commits Branches @commit @diff @stats
path: root / scripts / services / socketService.js
diff options
context:
space:
mode:
Commit3c9420b438ed145753b53ff661736197b7ad78d8 (patch)
Author
 ivaylo.zhelev <ivaylo.zhelev@solarwinds.com>
2021-02-27 10:57:02 +0200
Committer
 ivaylo.zhelev <ivaylo.zhelev@solarwinds.com>
2021-02-27 10:57:02 +0200
Filesc03dd894abfeb348a3fc966e452dcce96062e881 /scripts/services/socketService.js
pusg-front-end-3c9420b438ed145753b53ff661736197b7ad78d8.tar
pusg-front-end-3c9420b438ed145753b53ff661736197b7ad78d8.tar.gz
pusg-front-end-3c9420b438ed145753b53ff661736197b7ad78d8.zip
Parentda2a65c1d3d1742d25707bf645485d24c618aca5 (diff)
Added User Participants functionality
1 files changed, 25 insertions, 2 deletions
-rw-r--r--scripts/services/socketService.js27
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);
+ }
}
}