]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/peertube-socket.ts
Refactor video links building
[github/Chocobozzz/PeerTube.git] / server / lib / peertube-socket.ts
index 5fc5bc20b70c2d77e494ccc5eca2d77d45ec3407..0740e378e6f1d635b75d624d6e458420d75a2c83 100644 (file)
@@ -22,7 +22,7 @@ class PeerTubeSocket {
     io.of('/user-notifications')
       .use(authenticateSocket)
       .on('connection', socket => {
-        const userId = socket.handshake.query.user.id
+        const userId = socket.handshake.auth.user.id
 
         logger.debug('User %d connected on the notification system.', userId)
 
@@ -42,12 +42,14 @@ class PeerTubeSocket {
         socket.on('subscribe', ({ videoId }) => {
           if (!isIdValid(videoId)) return
 
+          /* eslint-disable @typescript-eslint/no-floating-promises */
           socket.join(videoId)
         })
 
         socket.on('unsubscribe', ({ videoId }) => {
           if (!isIdValid(videoId)) return
 
+          /* eslint-disable @typescript-eslint/no-floating-promises */
           socket.leave(videoId)
         })
       })
@@ -69,7 +71,18 @@ class PeerTubeSocket {
     const data: LiveVideoEventPayload = { state: video.state }
     const type: LiveVideoEventType = 'state-change'
 
-    logger.debug('Sending video live new state notification of %s.', video.url)
+    logger.debug('Sending video live new state notification of %s.', video.url, { state: video.state })
+
+    this.liveVideosNamespace
+      .in(video.id)
+      .emit(type, data)
+  }
+
+  sendVideoViewsUpdate (video: MVideo) {
+    const data: LiveVideoEventPayload = { views: video.views }
+    const type: LiveVideoEventType = 'views-change'
+
+    logger.debug('Sending video live views update notification of %s.', video.url, { views: video.views })
 
     this.liveVideosNamespace
       .in(video.id)