X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fpeertube-socket.ts;h=2e4b15b380e16f5f772e6e3c8629569a6f32d6b1;hb=d573926e9b94fb19c8f51c53f71fc853182e1761;hp=1c7b09175720c287c74751a9a9f3042a334bd066;hpb=453e83ea5d81d203ba34bc43cd5c2c750ba40568;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/peertube-socket.ts b/server/lib/peertube-socket.ts index 1c7b09175..2e4b15b38 100644 --- a/server/lib/peertube-socket.ts +++ b/server/lib/peertube-socket.ts @@ -2,13 +2,13 @@ import * as SocketIO from 'socket.io' import { authenticateSocket } from '../middlewares' import { logger } from '../helpers/logger' import { Server } from 'http' -import { UserNotificationModelForApi } from '@server/typings/models/user' +import { UserNotificationModelForApi } from '@server/types/models/user' class PeerTubeSocket { private static instance: PeerTubeSocket - private userNotificationSockets: { [ userId: number ]: SocketIO.Socket } = {} + private userNotificationSockets: { [ userId: number ]: SocketIO.Socket[] } = {} private constructor () {} @@ -22,22 +22,27 @@ 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: UserNotificationModelForApi) { - const socket = this.userNotificationSockets[userId] + const sockets = this.userNotificationSockets[userId] - if (!socket) return + if (!sockets) return - socket.emit('new-notification', notification.toFormattedJSON()) + const notificationMessage = notification.toFormattedJSON() + for (const socket of sockets) { + socket.emit('new-notification', notificationMessage) + } } static get Instance () {