refactoring of notification

This commit is contained in:
병준 박 2019-10-08 16:15:36 +09:00
parent 376069d8ad
commit fa070c24d7
4 changed files with 118 additions and 41 deletions

View File

@ -1,16 +1,15 @@
import { Injectable } from '@angular/core';
import { filter, tap } from 'rxjs/operators';
import { 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,
decodeLogout,
decodeLogoutRemoteNotification
AuthenticationProtocolService,
LogoutResponse,
LogoutRemoteNotification
} from '@ucap-webmessenger/protocol-authentication';
import * as AuthenticationStore from '../store/account/authentication';
@ -19,36 +18,29 @@ import { NGXLogger } from 'ngx-logger';
@Injectable()
export class AppNotificationService {
constructor(
private protocolService: ProtocolService,
private authenticationProtocolService: AuthenticationProtocolService,
private store: Store<any>,
private logger: NGXLogger
) {}
public subscribe(): void {
this.protocolService.serverMessage
this.authenticationProtocolService.logoutNotification$
.pipe(
filter(
message =>
message.serviceType === SVC_TYPE_LOGOUT &&
message.subServiceType === SSVC_TYPE_LOGOUT_RES
),
tap(message => {
const logoutRes = decodeLogout(message);
this.logger.debug('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 => {
const logoutRemoteNoti = decodeLogoutRemoteNotification(message);
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());
})
)

View File

@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { Observable, Subject } from 'rxjs';
import { map, take, filter, tap, share } from 'rxjs/operators';
import { ProtocolService } from '@ucap-webmessenger/protocol';
import {
@ -15,7 +15,9 @@ import {
SSVC_TYPE_LOGIN_REQ,
SVC_TYPE_LOGOUT,
SSVC_TYPE_LOGOUT_REQ,
SSVC_TYPE_LOGOUT_REMOTE_REQ
SSVC_TYPE_LOGOUT_REMOTE_REQ,
SSVC_TYPE_LOGOUT_RES,
SSVC_TYPE_LOGOUT_REMOTE_NOTI
} from '../types/service';
import {
LogoutRequest,
@ -27,14 +29,57 @@ import {
encodeLogoutRemote,
decodeLogoutRemote,
LogoutRemoteRequest,
LogoutRemoteResponse
LogoutRemoteResponse,
decodeLogoutRemoteNotification,
LogoutRemoteNotification
} from '../protocols/logout-remote';
@Injectable({
providedIn: 'root'
})
export class AuthenticationProtocolService {
constructor(private protocolService: ProtocolService) {}
private logoutNotificationSubject: Subject<
LogoutResponse | LogoutRemoteNotification
>;
public logoutNotification$: Observable<
LogoutResponse | LogoutRemoteNotification
>;
constructor(private protocolService: ProtocolService) {
this.logoutNotificationSubject = new Subject();
this.logoutNotification$ = this.logoutNotificationSubject
.asObservable()
.pipe(share());
this.protocolService.serverMessage
.pipe(
filter(message => message.serviceType === SVC_TYPE_LOGOUT),
tap(message => {
switch (message.subServiceType) {
case SSVC_TYPE_LOGOUT_RES:
{
this.logoutNotificationSubject.next({
...decodeLogout(message),
Type: SSVC_TYPE_LOGOUT_RES
});
}
break;
case SSVC_TYPE_LOGOUT_REMOTE_NOTI:
{
this.logoutNotificationSubject.next({
...decodeLogoutRemoteNotification(message),
Type: SSVC_TYPE_LOGOUT_REMOTE_NOTI
});
}
break;
default:
break;
}
})
)
.subscribe();
}
public login(req: LoginRequest): Observable<LoginResponse> {
return this.protocolService

View File

@ -1,7 +1,15 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map, takeWhile, timeout, take } from 'rxjs/operators';
import { Observable, Subject } from 'rxjs';
import {
map,
takeWhile,
timeout,
take,
share,
filter,
tap
} from 'rxjs/operators';
import { ProtocolService } from '@ucap-webmessenger/protocol';
@ -22,7 +30,8 @@ import {
SSVC_TYPE_EVENT_PUSH_CL_REQ,
SSVC_TYPE_EVENT_READ_REQ,
SSVC_TYPE_EVENT_DEL_REQ,
SSVC_TYPE_EVENT_CANCEL_REQ
SSVC_TYPE_EVENT_CANCEL_REQ,
SSVC_TYPE_EVENT_CANCEL_NOTI
} from '../types/service';
import {
SendRequest,
@ -47,14 +56,44 @@ import {
CancelRequest,
CancelResponse,
encodeCancel,
decodeCancel
decodeCancel,
CancelNotification,
decodeCancelNotification
} from '../protocols/cancel';
@Injectable({
providedIn: 'root'
})
export class EventProtocolService {
constructor(private protocolService: ProtocolService) {}
private eventNotificationSubject: Subject<CancelNotification>;
public eventNotification$: Observable<CancelNotification>;
constructor(private protocolService: ProtocolService) {
this.eventNotificationSubject = new Subject();
this.eventNotification$ = this.eventNotificationSubject
.asObservable()
.pipe(share());
this.protocolService.serverMessage
.pipe(
filter(message => message.serviceType === SVC_TYPE_EVENT),
tap(message => {
switch (message.subServiceType) {
case SSVC_TYPE_EVENT_CANCEL_NOTI:
{
this.eventNotificationSubject.next({
...decodeCancelNotification(message),
Type: SSVC_TYPE_EVENT_CANCEL_NOTI
});
}
break;
default:
break;
}
})
)
.subscribe();
}
public info(req: InfoRequest): Observable<InfoResponse | InfoData> {
return this.protocolService

View File

@ -14,8 +14,9 @@ export interface ProtocolStream {
Type?: number;
}
// tslint:disable-next-line: no-empty-interface
export interface ProtocolNotification {}
export interface ProtocolNotification {
Type?: number;
}
export interface ProtocolMessage {
serviceType: number;