diff options
Diffstat (limited to 'client/src/app/core/notification')
-rw-r--r-- | client/src/app/core/notification/user-notification-socket.service.ts | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/client/src/app/core/notification/user-notification-socket.service.ts b/client/src/app/core/notification/user-notification-socket.service.ts index f367d9ae4..29337d3a7 100644 --- a/client/src/app/core/notification/user-notification-socket.service.ts +++ b/client/src/app/core/notification/user-notification-socket.service.ts | |||
@@ -21,21 +21,22 @@ export class UserNotificationSocket { | |||
21 | this.notificationSubject.next({ type, notification }) | 21 | this.notificationSubject.next({ type, notification }) |
22 | } | 22 | } |
23 | 23 | ||
24 | getMyNotificationsSocket () { | 24 | async getMyNotificationsSocket () { |
25 | const socket = this.getSocket() | 25 | await this.initSocket() |
26 | |||
27 | socket.on('new-notification', (n: UserNotificationServer) => this.dispatch('new', n)) | ||
28 | 26 | ||
29 | return this.notificationSubject.asObservable() | 27 | return this.notificationSubject.asObservable() |
30 | } | 28 | } |
31 | 29 | ||
32 | private getSocket () { | 30 | private async initSocket () { |
33 | if (this.socket) return this.socket | 31 | if (this.socket) return |
32 | |||
33 | // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function | ||
34 | const io: typeof import ('socket.io-client') = (await import('socket.io-client') as any).default | ||
34 | 35 | ||
35 | this.socket = io(environment.apiUrl + '/user-notifications', { | 36 | this.socket = io(environment.apiUrl + '/user-notifications', { |
36 | query: { accessToken: this.auth.getAccessToken() } | 37 | query: { accessToken: this.auth.getAccessToken() } |
37 | }) | 38 | }) |
38 | 39 | ||
39 | return this.socket | 40 | this.socket.on('new-notification', (n: UserNotificationServer) => this.dispatch('new', n)) |
40 | } | 41 | } |
41 | } | 42 | } |