diff options
Diffstat (limited to 'client/src/app/core/notification/peertube-socket.service.ts')
-rw-r--r-- | client/src/app/core/notification/peertube-socket.service.ts | 23 |
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 @@ | |||
1 | import { Subject } from 'rxjs' | 1 | import { Subject } from 'rxjs' |
2 | import { Injectable, NgZone } from '@angular/core' | 2 | import { io, Socket } from 'socket.io-client' |
3 | import { Injectable } from '@angular/core' | ||
3 | import { LiveVideoEventPayload, LiveVideoEventType, UserNotification as UserNotificationServer } from '@shared/models' | 4 | import { LiveVideoEventPayload, LiveVideoEventType, UserNotification as UserNotificationServer } from '@shared/models' |
4 | import { environment } from '../../../environments/environment' | 5 | import { environment } from '../../../environments/environment' |
5 | import { AuthService } from '../auth' | 6 | import { AuthService } from '../auth' |
6 | import { io, Socket } from 'socket.io-client' | ||
7 | 7 | ||
8 | export type NotificationEvent = 'new' | 'read' | 'read-all' | 8 | export 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 | } |