2019-09-19 09:22:13 +00:00
|
|
|
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,
|
2019-09-20 02:39:09 +00:00
|
|
|
decodeLogout,
|
|
|
|
decodeLogoutRemoteNotification
|
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(
|
|
|
|
private protocolService: ProtocolService,
|
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 {
|
|
|
|
this.protocolService.serverMessage
|
|
|
|
.pipe(
|
|
|
|
filter(
|
|
|
|
message =>
|
|
|
|
message.serviceType === SVC_TYPE_LOGOUT &&
|
|
|
|
message.subServiceType === SSVC_TYPE_LOGOUT_RES
|
|
|
|
),
|
|
|
|
tap(message => {
|
2019-09-20 02:39:09 +00:00
|
|
|
const logoutRes = decodeLogout(message);
|
2019-09-26 02:11:22 +00:00
|
|
|
this.logger.debug('logoutRes', logoutRes);
|
2019-09-19 09:22:13 +00:00
|
|
|
this.store.dispatch(AuthenticationStore.logout());
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
|
|
|
|
this.protocolService.serverMessage
|
|
|
|
.pipe(
|
|
|
|
filter(
|
|
|
|
message =>
|
|
|
|
message.serviceType === SVC_TYPE_LOGOUT &&
|
|
|
|
message.subServiceType === SSVC_TYPE_LOGOUT_REMOTE_NOTI
|
|
|
|
),
|
|
|
|
tap(message => {
|
2019-09-20 02:39:09 +00:00
|
|
|
const logoutRemoteNoti = decodeLogoutRemoteNotification(message);
|
2019-09-19 09:22:13 +00:00
|
|
|
this.store.dispatch(AuthenticationStore.logout());
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
}
|