X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fpeertube-socket.ts;h=17748fd1813186509ab5c63a54ebfc8771475703;hb=1b42d73f44811eec1b7ddd72dd0d640a57c3376c;hp=eb84ecd4bbb134a3216f2ca62576b9459f0a7274;hpb=88108880bbdba473cfe36ecbebc1c3c4f972e102;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/peertube-socket.ts b/server/lib/peertube-socket.ts index eb84ecd4b..17748fd18 100644 --- a/server/lib/peertube-socket.ts +++ b/server/lib/peertube-socket.ts @@ -8,7 +8,7 @@ class PeerTubeSocket { private static instance: PeerTubeSocket - private userNotificationSockets: { [ userId: number ]: SocketIO.Socket } = {} + private userNotificationSockets: { [ userId: number ]: SocketIO.Socket[] } = {} private constructor () {} @@ -22,22 +22,26 @@ class PeerTubeSocket { logger.debug('User %d connected on the notification system.', userId) - this.userNotificationSockets[userId] = socket + if (!this.userNotificationSockets[userId]) this.userNotificationSockets[userId] = [] + + this.userNotificationSockets[userId].push(socket) socket.on('disconnect', () => { logger.debug('User %d disconnected from SocketIO notifications.', userId) - delete this.userNotificationSockets[userId] + this.userNotificationSockets[userId] = this.userNotificationSockets[userId].filter(s => s !== socket) }) }) } sendNotification (userId: number, notification: UserNotificationModel) { - const socket = this.userNotificationSockets[userId] + const sockets = this.userNotificationSockets[userId] - if (!socket) return + if (!sockets) return - socket.emit('new-notification', notification.toFormattedJSON()) + for (const socket of sockets) { + socket.emit('new-notification', notification.toFormattedJSON()) + } } static get Instance () {