65 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-09-19 10:40:16 +09:00
import { Injectable } from '@angular/core';
2019-09-19 17:03:39 +09:00
import { filter, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { ProtocolService } from '@ucap-webmessenger/protocol';
import {
SVC_TYPE_LOGOUT,
2019-09-19 18:05:59 +09:00
SSVC_TYPE_LOGOUT_RES,
SSVC_TYPE_LOGOUT_REMOTE_NOTI,
AuthenticationProtocolService
2019-09-19 17:03:39 +09:00
} from '@ucap-webmessenger/protocol-authentication';
import * as AuthenticationStore from '../store/account/authentication';
2019-09-19 10:40:16 +09:00
@Injectable()
export class AppService {
2019-09-19 17:03:39 +09:00
constructor(
private protocolService: ProtocolService,
2019-09-19 18:05:59 +09:00
private authenticationProtocolService: AuthenticationProtocolService,
2019-09-19 17:03:39 +09:00
private store: Store<any>
) {
this.protocolService.serverMessage
.pipe(
2019-09-19 18:05:59 +09:00
filter(message => message.serviceType === SVC_TYPE_LOGOUT),
2019-09-19 17:03:39 +09:00
filter(
2019-09-19 18:05:59 +09:00
message =>
message.subServiceType === SSVC_TYPE_LOGOUT_RES ||
message.subServiceType === SSVC_TYPE_LOGOUT_REMOTE_NOTI
2019-09-19 17:03:39 +09:00
),
2019-09-19 18:05:59 +09:00
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;
}
2019-09-19 17:03:39 +09:00
})
)
.subscribe();
}
2019-09-19 10:40:16 +09:00
public postInit(): Promise<void> {
return new Promise<void>((resolve, reject) => {
resolve();
});
}
}