Website Summary Files Commits Branches @commit @diff @stats
path: root / scripts / services
diff options
context:
space:
mode:
2 files changed, 18 insertions, 23 deletions
-rw-r--r--scripts/services/socketService.js33
-rw-r--r--scripts/services/userService.js8
diff --git a/scripts/services/socketService.js b/scripts/services/socketService.js
index 186ac3b..b2153f2 100644
--- a/scripts/services/socketService.js
+++ b/scripts/services/socketService.js
@@ -23,8 +23,7 @@ class SocketService {
});
this.gameConnection.on('StartGame', ([color]) => {
- window.location.hash = '#/play';
- app.config.USER.COLOR = color;
+ app.eventService.triggerEvent('GameStart', color)
});
this.gameConnection.on('OtherUp', () => {
@@ -73,39 +72,26 @@ class SocketService {
.build();
}
+ disconnectHome() {
+ this.homeConnection.stop();
+ this.homeConnection = null;
+ }
+
initHomeReceivers() {
this.homeConnection.on('OnConnected', ([message]) => {
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');
- }
- });
+ app.eventService.triggerEvent('OnLoggedIn', users);
});
this.homeConnection.on('OnLoggedOut', (users) => {
- users.forEach(user => {
- app.htmlService.getElement(`#${user}`).remove();
- });
+ app.eventService.triggerEvent('OnLoggedOut', users);
});
this.homeConnection.on('ReceiveMessage', ([user, message]) => {
- const messageNode = app.htmlService
- .getElementFromTemplate('message', {
- user: user,
- message: message
- });
-
- app.htmlService.attachElement(app.htmlService.createElement(messageNode)
- , '.history-messages');
+ app.eventService.triggerEvent('OnReceiveMessage', [user, message]);
});
}
@@ -130,6 +116,7 @@ class SocketService {
send(location, method, ...args) {
if(location === 'home') {
+ console.log(this.homeConnection);
this.homeConnection?.invoke(method, ...args);
}
if(location === 'game') {
diff --git a/scripts/services/userService.js b/scripts/services/userService.js
index 03bb313..512de48 100644
--- a/scripts/services/userService.js
+++ b/scripts/services/userService.js
@@ -12,10 +12,18 @@ class UserService {
if (username) {
app.socketService.send('home', 'Login', username);
this.user = username;
+ app.eventService.triggerEvent('LoggedIn');
}
}
}
+ refreshLogin() {
+ if(this.user) {
+ app.socketService.send('home', 'Login', this.user);
+ app.eventService.triggerEvent('LoggedIn');
+ }
+ }
+
isLoggedIn() {
return this.user;
}