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';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AppNotificationService {
|
|
|
|
constructor(
|
|
|
|
private protocolService: ProtocolService,
|
|
|
|
private store: Store<any>
|
|
|
|
) {}
|
|
|
|
|
|
|
|
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-19 09:22:13 +00:00
|
|
|
console.log('logoutRes', logoutRes);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|