next-ucap-messenger/projects/ucap-webmessenger-app/src/app/services/notification.service.ts

50 lines
1.3 KiB
TypeScript

import { Injectable } from '@angular/core';
import { tap } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import {
SSVC_TYPE_LOGOUT_RES,
SSVC_TYPE_LOGOUT_REMOTE_NOTI,
AuthenticationProtocolService,
LogoutResponse,
LogoutRemoteNotification
} from '@ucap-webmessenger/protocol-authentication';
import * as AuthenticationStore from '../store/account/authentication';
import { NGXLogger } from 'ngx-logger';
@Injectable()
export class AppNotificationService {
constructor(
private authenticationProtocolService: AuthenticationProtocolService,
private store: Store<any>,
private logger: NGXLogger
) {}
public subscribe(): void {
this.authenticationProtocolService.logoutNotification$
.pipe(
tap(notiOrRes => {
switch (notiOrRes.Type) {
case SSVC_TYPE_LOGOUT_RES:
{
const res = notiOrRes as LogoutResponse;
}
break;
case SSVC_TYPE_LOGOUT_REMOTE_NOTI:
{
const noti = notiOrRes as LogoutRemoteNotification;
}
break;
default:
break;
}
this.store.dispatch(AuthenticationStore.logout());
})
)
.subscribe();
}
}