import { Injectable } from '@angular/core'; import { Subject, Observable } from 'rxjs'; import { UmgNotiNotification, decodeUmgNotiNotification } from '../protocols/noti'; import { ProtocolService } from '@ucap-webmessenger/protocol'; import { share, filter, tap } from 'rxjs/operators'; import { SVC_TYPE_UMG, SSVC_TYPE_UMG_NOTI } from '../types/service'; type Notifications = UmgNotiNotification; @Injectable({ providedIn: 'root' }) export class UmgProtocolService { private notificationSubject: Subject; public notification$: Observable; constructor(private protocolService: ProtocolService) { this.notificationSubject = new Subject(); this.notification$ = this.notificationSubject.asObservable().pipe(share()); this.protocolService.serverMessage .pipe( filter(message => message.serviceType === SVC_TYPE_UMG), tap(message => { switch (message.subServiceType) { case SSVC_TYPE_UMG_NOTI: { this.notificationSubject.next( decodeUmgNotiNotification(message) ); } break; default: break; } }) ) .subscribe(); } }