]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/peertube-socket.ts
Add live notification tests
[github/Chocobozzz/PeerTube.git] / server / lib / peertube-socket.ts
index c918a8685d05856627c1b58b13471a2381d30309..c4df399caa3c4977e2d9290101e80972159b578b 100644 (file)
@@ -6,6 +6,7 @@ import { UserNotificationModelForApi } from '@server/types/models/user'
 import { LiveVideoEventPayload, LiveVideoEventType } from '@shared/models'
 import { logger } from '../helpers/logger'
 import { authenticateSocket } from '../middlewares'
+import { isIdValid } from '@server/helpers/custom-validators/misc'
 
 class PeerTubeSocket {
 
@@ -39,8 +40,17 @@ class PeerTubeSocket {
 
     this.liveVideosNamespace = io.of('/live-videos')
       .on('connection', socket => {
-        socket.on('subscribe', ({ videoId }) => socket.join(videoId))
-        socket.on('unsubscribe', ({ videoId }) => socket.leave(videoId))
+        socket.on('subscribe', ({ videoId }) => {
+          if (!isIdValid(videoId)) return
+
+          socket.join(videoId)
+        })
+
+        socket.on('unsubscribe', ({ videoId }) => {
+          if (!isIdValid(videoId)) return
+
+          socket.leave(videoId)
+        })
       })
   }