next-ucap-messenger/projects/ucap-webmessenger-protocol-umg/src/lib/services/umg-protocol.service.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-09-18 06:02:21 +00:00
import { Injectable } from '@angular/core';
2019-12-17 07:39:02 +00:00
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;
2019-09-18 06:02:21 +00:00
@Injectable({
providedIn: 'root'
})
export class UmgProtocolService {
2019-12-17 07:39:02 +00:00
private notificationSubject: Subject<Notifications>;
public notification$: Observable<Notifications>;
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();
}
2019-09-18 06:02:21 +00:00
}