aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/notification/peertube-socket.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core/notification/peertube-socket.service.ts')
-rw-r--r--client/src/app/core/notification/peertube-socket.service.ts23
1 files changed, 8 insertions, 15 deletions
diff --git a/client/src/app/core/notification/peertube-socket.service.ts b/client/src/app/core/notification/peertube-socket.service.ts
index 50d5df68f..0db86d8e7 100644
--- a/client/src/app/core/notification/peertube-socket.service.ts
+++ b/client/src/app/core/notification/peertube-socket.service.ts
@@ -1,9 +1,9 @@
1import { Subject } from 'rxjs' 1import { Subject } from 'rxjs'
2import { Injectable, NgZone } from '@angular/core' 2import { io, Socket } from 'socket.io-client'
3import { Injectable } from '@angular/core'
3import { LiveVideoEventPayload, LiveVideoEventType, UserNotification as UserNotificationServer } from '@shared/models' 4import { LiveVideoEventPayload, LiveVideoEventType, UserNotification as UserNotificationServer } from '@shared/models'
4import { environment } from '../../../environments/environment' 5import { environment } from '../../../environments/environment'
5import { AuthService } from '../auth' 6import { AuthService } from '../auth'
6import { io, Socket } from 'socket.io-client'
7 7
8export type NotificationEvent = 'new' | 'read' | 'read-all' 8export type NotificationEvent = 'new' | 'read' | 'read-all'
9 9
@@ -18,8 +18,7 @@ export class PeerTubeSocket {
18 private liveVideosSocket: Socket 18 private liveVideosSocket: Socket
19 19
20 constructor ( 20 constructor (
21 private auth: AuthService, 21 private auth: AuthService
22 private ngZone: NgZone
23 ) {} 22 ) {}
24 23
25 async getMyNotificationsSocket () { 24 async getMyNotificationsSocket () {
@@ -53,15 +52,12 @@ export class PeerTubeSocket {
53 52
54 await this.importIOIfNeeded() 53 await this.importIOIfNeeded()
55 54
56 // Prevent protractor issues https://github.com/angular/angular/issues/11853 55 this.notificationSocket = this.io(environment.apiUrl + '/user-notifications', {
57 this.ngZone.runOutsideAngular(() => { 56 query: { accessToken: this.auth.getAccessToken() }
58 this.notificationSocket = this.io(environment.apiUrl + '/user-notifications', {
59 query: { accessToken: this.auth.getAccessToken() }
60 })
61 }) 57 })
62 58
63 this.notificationSocket.on('new-notification', (n: UserNotificationServer) => { 59 this.notificationSocket.on('new-notification', (n: UserNotificationServer) => {
64 this.ngZone.run(() => this.dispatchNotificationEvent('new', n)) 60 this.dispatchNotificationEvent('new', n)
65 }) 61 })
66 } 62 }
67 63
@@ -70,16 +66,13 @@ export class PeerTubeSocket {
70 66
71 await this.importIOIfNeeded() 67 await this.importIOIfNeeded()
72 68
73 // Prevent protractor issues https://github.com/angular/angular/issues/11853 69 this.liveVideosSocket = this.io(environment.apiUrl + '/live-videos')
74 this.ngZone.runOutsideAngular(() => {
75 this.liveVideosSocket = this.io(environment.apiUrl + '/live-videos')
76 })
77 70
78 const types: LiveVideoEventType[] = [ 'views-change', 'state-change' ] 71 const types: LiveVideoEventType[] = [ 'views-change', 'state-change' ]
79 72
80 for (const type of types) { 73 for (const type of types) {
81 this.liveVideosSocket.on(type, (payload: LiveVideoEventPayload) => { 74 this.liveVideosSocket.on(type, (payload: LiveVideoEventPayload) => {
82 this.ngZone.run(() => this.dispatchLiveVideoEvent(type, payload)) 75 this.dispatchLiveVideoEvent(type, payload)
83 }) 76 })
84 } 77 }
85 } 78 }