aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/peertube-socket.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-22 10:33:22 +0200
committerChocobozzz <me@florianbigard.com>2019-08-22 10:33:22 +0200
commit015d9dec91ecb7a17e4e79407d187aac8a19206d (patch)
tree658d712879e35740aa333199b5a3ecdfe5e9633a /server/lib/peertube-socket.ts
parent7c58378a57a1540534b9fc47bf06c9f64a1ebc6b (diff)
downloadPeerTube-015d9dec91ecb7a17e4e79407d187aac8a19206d.tar.gz
PeerTube-015d9dec91ecb7a17e4e79407d187aac8a19206d.tar.zst
PeerTube-015d9dec91ecb7a17e4e79407d187aac8a19206d.zip
Fix socket notification with multiple user tabs
Diffstat (limited to 'server/lib/peertube-socket.ts')
-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 () {