+
+ this.liveVideosNamespace = io.of('/live-videos')
+ .on('connection', socket => {
+ 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)
+ })
+ })
+
+ io.of('/runners')
+ .use(authenticateRunnerSocket)
+ .on('connection', socket => {
+ const runner: MRunner = socket.handshake.auth.runner
+
+ logger.debug(`New runner "${runner.name}" connected to the notification system.`)
+
+ this.runnerSockets.add(socket)
+
+ socket.on('disconnect', () => {
+ logger.debug(`Runner "${runner.name}" disconnected from the notification system.`)
+
+ this.runnerSockets.delete(socket)
+ })
+ })
+ }
+
+ sendNotification (userId: number, notification: UserNotificationModelForApi) {
+ const sockets = this.userNotificationSockets[userId]
+ if (!sockets) return
+
+ logger.debug('Sending user notification to user %d.', userId)
+
+ const notificationMessage = notification.toFormattedJSON()
+ for (const socket of sockets) {
+ socket.emit('new-notification', notificationMessage)
+ }