]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/notification/user-notification-socket.service.ts
Lazy import some modules
[github/Chocobozzz/PeerTube.git] / client / src / app / core / notification / user-notification-socket.service.ts
index f367d9ae465d823c4fd6290fad8960ba08091a0f..29337d3a718add3ffcec687c483415f835b85230 100644 (file)
@@ -21,21 +21,22 @@ export class UserNotificationSocket {
     this.notificationSubject.next({ type, notification })
   }
 
-  getMyNotificationsSocket () {
-    const socket = this.getSocket()
-
-    socket.on('new-notification', (n: UserNotificationServer) => this.dispatch('new', n))
+  async getMyNotificationsSocket () {
+    await this.initSocket()
 
     return this.notificationSubject.asObservable()
   }
 
-  private getSocket () {
-    if (this.socket) return this.socket
+  private async initSocket () {
+    if (this.socket) return
+
+    // 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() }
     })
 
-    return this.socket
+    this.socket.on('new-notification', (n: UserNotificationServer) => this.dispatch('new', n))
   }
 }