-import { Injectable } from '@angular/core'
+import { Injectable, NgZone } from '@angular/core'
import { environment } from '../../../environments/environment'
import { UserNotification as UserNotificationServer } from '../../../../../shared'
import { Subject } from 'rxjs'
private socket: SocketIOClient.Socket
constructor (
- private auth: AuthService
+ private auth: AuthService,
+ private ngZone: NgZone
) {}
dispatch (type: NotificationEvent, notification?: UserNotificationServer) {
// 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))
+ })
}
}