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

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-09-19 09:22:13 +00:00
import { Injectable } from '@angular/core';
2019-10-08 07:15:36 +00:00
import { tap } from 'rxjs/operators';
2019-09-19 09:22:13 +00:00
import { Store } from '@ngrx/store';
import {
SSVC_TYPE_LOGOUT_RES,
SSVC_TYPE_LOGOUT_REMOTE_NOTI,
2019-10-08 07:15:36 +00:00
AuthenticationProtocolService,
LogoutResponse,
LogoutRemoteNotification
2019-09-19 09:22:13 +00:00
} from '@ucap-webmessenger/protocol-authentication';
import * as AuthenticationStore from '../store/account/authentication';
2019-09-26 02:11:22 +00:00
import { NGXLogger } from 'ngx-logger';
2019-09-19 09:22:13 +00:00
@Injectable()
export class AppNotificationService {
constructor(
2019-10-08 07:15:36 +00:00
private authenticationProtocolService: AuthenticationProtocolService,
2019-09-26 02:11:22 +00:00
private store: Store<any>,
private logger: NGXLogger
2019-09-19 09:22:13 +00:00
) {}
public subscribe(): void {
2019-10-08 07:15:36 +00:00
this.authenticationProtocolService.logoutNotification$
2019-09-19 09:22:13 +00:00
.pipe(
2019-10-08 07:15:36 +00:00
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;
}
2019-09-19 09:22:13 +00:00
this.store.dispatch(AuthenticationStore.logout());
})
)
.subscribe();
}
}