diff --git a/src/app/channel/connectedUser.js b/src/app/channel/connectedUser.js index 81b3220..03bea6e 100644 --- a/src/app/channel/connectedUser.js +++ b/src/app/channel/connectedUser.js @@ -226,9 +226,6 @@ class connectedUser{ } }); - //Get schedule as a temporary array - const queue = await this.channel.queue.prepQueue(chanDB); - //Get schedule lock status const queueLock = this.channel.queue.locked; @@ -236,7 +233,7 @@ class connectedUser{ const chatBuffer = this.channel.chatBuffer.buffer; //Send off the metadata to our user's clients - this.emit("clientMetadata", {user: userObj, flairList, queue, queueLock, chatBuffer}); + this.emit("clientMetadata", {user: userObj, flairList, queueLock, chatBuffer}); } /** diff --git a/src/app/channel/media/queue.js b/src/app/channel/media/queue.js index 9f68021..8284420 100644 --- a/src/app/channel/media/queue.js +++ b/src/app/channel/media/queue.js @@ -1607,7 +1607,18 @@ class queue{ * @param {Mongoose.Document} chanDB - Pass through Channel Document to save on DB Transactions */ async broadcastQueue(chanDB){ - this.server.io.in(this.channel.name).emit('queue',{queue: await this.prepQueue(chanDB)}); + //Broadcast queue to authenticated sockets within the channels room inside the protected 'queue-broadcast' namespace + this.server.queueBroadcastManager.namespace.in(this.channel.name).emit('queue',{queue: await this.prepQueue(chanDB)}); + } + + /** + * Broadcasts channel queue to a single socket + * @param {Mongoose.Document} chanDB - Pass through Channel Document to save on DB Transactions + * @param {Socket} socket - Socket to send queue to + */ + async emitQueue(chanDB, socket){ + //Broadcast queue to authenticated sockets within the channels room inside the protected 'queue-broadcast' namespace + socket.emit('queue',{queue: await this.prepQueue(chanDB)}); } /** diff --git a/src/app/channel/media/queueBroadcastManager.js b/src/app/channel/media/queueBroadcastManager.js index c72a1c3..61e0497 100644 --- a/src/app/channel/media/queueBroadcastManager.js +++ b/src/app/channel/media/queueBroadcastManager.js @@ -55,6 +55,15 @@ class queueBroadcastManager extends auxServer{ //Set socket channel value socket.chan = socketUtils.getChannelName(socket); + //Pull active channel + const activeChannel = this.chanServer.activeChannels.get(socket.chan); + + //If there isn't an active channel + if(activeChannel == null){ + //Drop the connection + return; + } + //Pull channel DB const chanDB = (await channelModel.findOne({name: socket.chan})); @@ -69,6 +78,9 @@ class queueBroadcastManager extends auxServer{ //Throw the user into the channels room within the queue-broadcast instance socket.join(socket.chan); + //Send the queue down to our newly connected user + activeChannel.queue.emitQueue(chanDB, socket); + //Define listeners this.defineListeners(socket); } diff --git a/www/js/channel/channel.js b/www/js/channel/channel.js index e63a8a0..6220ed0 100644 --- a/www/js/channel/channel.js +++ b/www/js/channel/channel.js @@ -113,7 +113,8 @@ class channel{ this.socket.on("error", utils.ux.displayResponseError); - this.socket.on("queue", (data) => { + this.queueBroadcastSocket.on("queue", (data) => { + console.log(data); this.queue = new Map(data.queue); }); @@ -138,9 +139,6 @@ class channel{ //should it have its own event listener instead? Guess it's a stylistic choice :P this.chatBox.handleClientInfo(data); - //Store queue for use by the queue panel - this.queue = new Map(data.queue); - //Store queue lock status this.queueLock = data.queueLock; } diff --git a/www/js/channel/panels/queuePanel/queuePanel.js b/www/js/channel/panels/queuePanel/queuePanel.js index 2b05766..a872c92 100644 --- a/www/js/channel/panels/queuePanel/queuePanel.js +++ b/www/js/channel/panels/queuePanel/queuePanel.js @@ -137,8 +137,7 @@ class queuePanel extends panelObj{ defineListeners(){ //Render queue when we receive a new copy of the queue data from the server //Render queue should be called within an arrow function so that it's called with default parameters, and not handed an event as a date - this.client.socket.on("clientMetadata", () => {this.renderQueue();}); - this.client.socket.on("queue", () => {this.renderQueue();}); + this.client.queueBroadcastSocket.on("queue", () => {this.renderQueue();}); this.client.socket.on("start", this.handleStart.bind(this)); this.client.socket.on("end", this.handleEnd.bind(this)); this.client.socket.on("lock", this.handleScheduleLock.bind(this));