aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/peertube-socket.ts16
1 files changed, 10 insertions, 6 deletions
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 {
8 8
9 private static instance: PeerTubeSocket 9 private static instance: PeerTubeSocket
10 10
11 private userNotificationSockets: { [ userId: number ]: SocketIO.Socket } = {} 11 private userNotificationSockets: { [ userId: number ]: SocketIO.Socket[] } = {}
12 12
13 private constructor () {} 13 private constructor () {}
14 14
@@ -22,22 +22,26 @@ class PeerTubeSocket {
22 22
23 logger.debug('User %d connected on the notification system.', userId) 23 logger.debug('User %d connected on the notification system.', userId)
24 24
25 this.userNotificationSockets[userId] = socket 25 if (!this.userNotificationSockets[userId]) this.userNotificationSockets[userId] = []
26
27 this.userNotificationSockets[userId].push(socket)
26 28
27 socket.on('disconnect', () => { 29 socket.on('disconnect', () => {
28 logger.debug('User %d disconnected from SocketIO notifications.', userId) 30 logger.debug('User %d disconnected from SocketIO notifications.', userId)
29 31
30 delete this.userNotificationSockets[userId] 32 this.userNotificationSockets[userId] = this.userNotificationSockets[userId].filter(s => s !== socket)
31 }) 33 })
32 }) 34 })
33 } 35 }
34 36
35 sendNotification (userId: number, notification: UserNotificationModel) { 37 sendNotification (userId: number, notification: UserNotificationModel) {
36 const socket = this.userNotificationSockets[userId] 38 const sockets = this.userNotificationSockets[userId]
37 39
38 if (!socket) return 40 if (!sockets) return
39 41
40 socket.emit('new-notification', notification.toFormattedJSON()) 42 for (const socket of sockets) {
43 socket.emit('new-notification', notification.toFormattedJSON())
44 }
41 } 45 }
42 46
43 static get Instance () { 47 static get Instance () {