import { Injectable } from '@angular/core'; import { filter, tap } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { ProtocolService } from '@ucap-webmessenger/protocol'; import { SVC_TYPE_LOGOUT, SSVC_TYPE_LOGOUT_RES, SSVC_TYPE_LOGOUT_REMOTE_NOTI, AuthenticationProtocolService } from '@ucap-webmessenger/protocol-authentication'; import * as AuthenticationStore from '../store/account/authentication'; @Injectable() export class AppService { constructor( private protocolService: ProtocolService, private authenticationProtocolService: AuthenticationProtocolService, private store: Store ) { this.protocolService.serverMessage .pipe( filter(message => message.serviceType === SVC_TYPE_LOGOUT), filter( message => message.subServiceType === SSVC_TYPE_LOGOUT_RES || message.subServiceType === SSVC_TYPE_LOGOUT_REMOTE_NOTI ), tap(message => { switch (message.subServiceType) { case SSVC_TYPE_LOGOUT_RES: { const logoutRes = this.authenticationProtocolService.decodeLogoutResponse( message ); this.store.dispatch(AuthenticationStore.logout()); } break; case SSVC_TYPE_LOGOUT_REMOTE_NOTI: { const logoutRemoteNoti = this.authenticationProtocolService.decodeLogoutRemoteNotification( message ); this.store.dispatch(AuthenticationStore.logout()); } break; default: break; } }) ) .subscribe(); } public postInit(): Promise { return new Promise((resolve, reject) => { resolve(); }); } }