diff --git a/src/app/channel/activeChannel.js b/src/app/channel/activeChannel.js index 33a5014..daa5e49 100644 --- a/src/app/channel/activeChannel.js +++ b/src/app/channel/activeChannel.js @@ -150,6 +150,8 @@ class activeChannel{ var userObj = this.userList.get(userDB.user); //get channel rank for current user const chanRank = await chanDB.getChannelRankByUserDoc(userDB); + //Keep track of whether or not user has connected to this channel on another tab/device yet + let first = false; //If user is already connected if(userObj){ @@ -161,6 +163,8 @@ class activeChannel{ await userDB.populate('flair'); //Set user object userObj = new connectedUser(userDB, chanRank, this, socket); + //Throw first flag + first = true; } //Set user entry in userlist @@ -175,7 +179,7 @@ class activeChannel{ this.webRTCHandler.defineListeners(socket); //Hand off the connection initiation to it's user object - const activeUser = await userObj.handleConnection(userDB, chanDB, socket) + const activeUser = await userObj.handleConnection(userDB, chanDB, socket, first) //Send out the userlist this.broadcastUserList(socket.chan); diff --git a/src/app/channel/connectedUser.js b/src/app/channel/connectedUser.js index b70e63a..d0b09ae 100644 --- a/src/app/channel/connectedUser.js +++ b/src/app/channel/connectedUser.js @@ -96,11 +96,12 @@ class connectedUser{ * @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access * @param {Mongoose.Document} chanDB - Channnel Document Passthrough to save on DB Access * @param {Socket} socket - Requesting Socket + * @param {Boolean} first - thrown true if this is the socket for this user on this channel * @returns {activeUser} active user object generated by the new connection */ - async handleConnection(userDB, chanDB, socket){ + async handleConnection(userDB, chanDB, socket, first){ //send metadata to client - this.sendClientMetadata(); + this.sendClientMetadata(undefined, undefined, first); //Send out emotes this.sendSiteEmotes(); @@ -122,7 +123,6 @@ class connectedUser{ await userDB.tattooIPRecord(socket.handshake.address); } - //Return active user object for use by activeChannel and channelManager objects return this; } @@ -179,8 +179,9 @@ class connectedUser{ * Sends glut of required initial metadata to the client upon a new connection * @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access * @param {Mongoose.Document} chanDB - Channnel Document Passthrough to save on DB Access + * @param {Boolean} welcome - Whether or not to throw welcome wagon, ensures we dont welcome before the metadata is sent */ - async sendClientMetadata(userDB, chanDB){ + async sendClientMetadata(userDB, chanDB, welcome){ //Get flairList from DB and setup flairList array const flairListDB = await flairModel.find({}); var flairList = []; @@ -238,8 +239,11 @@ class connectedUser{ //Send off the metadata to our user's clients this.emit("clientMetadata", {user: userObj, flairList, queueLock, chatBuffer, streamType: chanDB.settings.streamType}); - //Broadcast the welcome wagon - this.channel.welcomeWagon(userDB.user); + //If we where told to welcome the user + if(welcome){ + //Broadcast the welcome wagon + this.channel.welcomeWagon(userDB.user); + } } /**