]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/notification/user-notification-socket.service.ts
Update build steps for localization
[github/Chocobozzz/PeerTube.git] / client / src / app / core / notification / user-notification-socket.service.ts
index 29337d3a718add3ffcec687c483415f835b85230..37f0bc32c11dea6ea39536c96e8c330c37f498a3 100644 (file)
@@ -1,8 +1,7 @@
-import { Injectable } from '@angular/core'
-import { environment } from '../../../environments/environment'
-import { UserNotification as UserNotificationServer } from '../../../../../shared'
 import { Subject } from 'rxjs'
-import * as io from 'socket.io-client'
+import { Injectable, NgZone } from '@angular/core'
+import { UserNotification as UserNotificationServer } from '@shared/models'
+import { environment } from '../../../environments/environment'
 import { AuthService } from '../auth'
 
 export type NotificationEvent = 'new' | 'read' | 'read-all'
@@ -14,7 +13,8 @@ export class UserNotificationSocket {
   private socket: SocketIOClient.Socket
 
   constructor (
-    private auth: AuthService
+    private auth: AuthService,
+    private ngZone: NgZone
   ) {}
 
   dispatch (type: NotificationEvent, notification?: UserNotificationServer) {
@@ -33,10 +33,12 @@ export class UserNotificationSocket {
     // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function
     const io: typeof import ('socket.io-client') = (await import('socket.io-client') as any).default
 
-    this.socket = io(environment.apiUrl + '/user-notifications', {
-      query: { accessToken: this.auth.getAccessToken() }
-    })
+    this.ngZone.runOutsideAngular(() => {
+      this.socket = io(environment.apiUrl + '/user-notifications', {
+        query: { accessToken: this.auth.getAccessToken() }
+      })
 
-    this.socket.on('new-notification', (n: UserNotificationServer) => this.dispatch('new', n))
+      this.socket.on('new-notification', (n: UserNotificationServer) => this.dispatch('new', n))
+    })
   }
 }