refactoring of notification
This commit is contained in:
parent
376069d8ad
commit
fa070c24d7
|
@ -1,16 +1,15 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { filter, tap } from 'rxjs/operators';
|
import { tap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
|
|
||||||
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
|
||||||
import {
|
import {
|
||||||
SVC_TYPE_LOGOUT,
|
|
||||||
SSVC_TYPE_LOGOUT_RES,
|
SSVC_TYPE_LOGOUT_RES,
|
||||||
SSVC_TYPE_LOGOUT_REMOTE_NOTI,
|
SSVC_TYPE_LOGOUT_REMOTE_NOTI,
|
||||||
decodeLogout,
|
AuthenticationProtocolService,
|
||||||
decodeLogoutRemoteNotification
|
LogoutResponse,
|
||||||
|
LogoutRemoteNotification
|
||||||
} from '@ucap-webmessenger/protocol-authentication';
|
} from '@ucap-webmessenger/protocol-authentication';
|
||||||
|
|
||||||
import * as AuthenticationStore from '../store/account/authentication';
|
import * as AuthenticationStore from '../store/account/authentication';
|
||||||
|
@ -19,36 +18,29 @@ import { NGXLogger } from 'ngx-logger';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppNotificationService {
|
export class AppNotificationService {
|
||||||
constructor(
|
constructor(
|
||||||
private protocolService: ProtocolService,
|
private authenticationProtocolService: AuthenticationProtocolService,
|
||||||
private store: Store<any>,
|
private store: Store<any>,
|
||||||
private logger: NGXLogger
|
private logger: NGXLogger
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public subscribe(): void {
|
public subscribe(): void {
|
||||||
this.protocolService.serverMessage
|
this.authenticationProtocolService.logoutNotification$
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(
|
tap(notiOrRes => {
|
||||||
message =>
|
switch (notiOrRes.Type) {
|
||||||
message.serviceType === SVC_TYPE_LOGOUT &&
|
case SSVC_TYPE_LOGOUT_RES:
|
||||||
message.subServiceType === SSVC_TYPE_LOGOUT_RES
|
{
|
||||||
),
|
const res = notiOrRes as LogoutResponse;
|
||||||
tap(message => {
|
}
|
||||||
const logoutRes = decodeLogout(message);
|
break;
|
||||||
this.logger.debug('logoutRes', logoutRes);
|
case SSVC_TYPE_LOGOUT_REMOTE_NOTI:
|
||||||
this.store.dispatch(AuthenticationStore.logout());
|
{
|
||||||
})
|
const noti = notiOrRes as LogoutRemoteNotification;
|
||||||
)
|
}
|
||||||
.subscribe();
|
break;
|
||||||
|
default:
|
||||||
this.protocolService.serverMessage
|
break;
|
||||||
.pipe(
|
}
|
||||||
filter(
|
|
||||||
message =>
|
|
||||||
message.serviceType === SVC_TYPE_LOGOUT &&
|
|
||||||
message.subServiceType === SSVC_TYPE_LOGOUT_REMOTE_NOTI
|
|
||||||
),
|
|
||||||
tap(message => {
|
|
||||||
const logoutRemoteNoti = decodeLogoutRemoteNotification(message);
|
|
||||||
this.store.dispatch(AuthenticationStore.logout());
|
this.store.dispatch(AuthenticationStore.logout());
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable, Subject } from 'rxjs';
|
||||||
import { map, take } from 'rxjs/operators';
|
import { map, take, filter, tap, share } from 'rxjs/operators';
|
||||||
|
|
||||||
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
||||||
import {
|
import {
|
||||||
|
@ -15,7 +15,9 @@ import {
|
||||||
SSVC_TYPE_LOGIN_REQ,
|
SSVC_TYPE_LOGIN_REQ,
|
||||||
SVC_TYPE_LOGOUT,
|
SVC_TYPE_LOGOUT,
|
||||||
SSVC_TYPE_LOGOUT_REQ,
|
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';
|
} from '../types/service';
|
||||||
import {
|
import {
|
||||||
LogoutRequest,
|
LogoutRequest,
|
||||||
|
@ -27,14 +29,57 @@ import {
|
||||||
encodeLogoutRemote,
|
encodeLogoutRemote,
|
||||||
decodeLogoutRemote,
|
decodeLogoutRemote,
|
||||||
LogoutRemoteRequest,
|
LogoutRemoteRequest,
|
||||||
LogoutRemoteResponse
|
LogoutRemoteResponse,
|
||||||
|
decodeLogoutRemoteNotification,
|
||||||
|
LogoutRemoteNotification
|
||||||
} from '../protocols/logout-remote';
|
} from '../protocols/logout-remote';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthenticationProtocolService {
|
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> {
|
public login(req: LoginRequest): Observable<LoginResponse> {
|
||||||
return this.protocolService
|
return this.protocolService
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable, Subject } from 'rxjs';
|
||||||
import { map, takeWhile, timeout, take } from 'rxjs/operators';
|
import {
|
||||||
|
map,
|
||||||
|
takeWhile,
|
||||||
|
timeout,
|
||||||
|
take,
|
||||||
|
share,
|
||||||
|
filter,
|
||||||
|
tap
|
||||||
|
} from 'rxjs/operators';
|
||||||
|
|
||||||
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
||||||
|
|
||||||
|
@ -22,7 +30,8 @@ import {
|
||||||
SSVC_TYPE_EVENT_PUSH_CL_REQ,
|
SSVC_TYPE_EVENT_PUSH_CL_REQ,
|
||||||
SSVC_TYPE_EVENT_READ_REQ,
|
SSVC_TYPE_EVENT_READ_REQ,
|
||||||
SSVC_TYPE_EVENT_DEL_REQ,
|
SSVC_TYPE_EVENT_DEL_REQ,
|
||||||
SSVC_TYPE_EVENT_CANCEL_REQ
|
SSVC_TYPE_EVENT_CANCEL_REQ,
|
||||||
|
SSVC_TYPE_EVENT_CANCEL_NOTI
|
||||||
} from '../types/service';
|
} from '../types/service';
|
||||||
import {
|
import {
|
||||||
SendRequest,
|
SendRequest,
|
||||||
|
@ -47,14 +56,44 @@ import {
|
||||||
CancelRequest,
|
CancelRequest,
|
||||||
CancelResponse,
|
CancelResponse,
|
||||||
encodeCancel,
|
encodeCancel,
|
||||||
decodeCancel
|
decodeCancel,
|
||||||
|
CancelNotification,
|
||||||
|
decodeCancelNotification
|
||||||
} from '../protocols/cancel';
|
} from '../protocols/cancel';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class EventProtocolService {
|
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> {
|
public info(req: InfoRequest): Observable<InfoResponse | InfoData> {
|
||||||
return this.protocolService
|
return this.protocolService
|
||||||
|
|
|
@ -14,8 +14,9 @@ export interface ProtocolStream {
|
||||||
Type?: number;
|
Type?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line: no-empty-interface
|
export interface ProtocolNotification {
|
||||||
export interface ProtocolNotification {}
|
Type?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ProtocolMessage {
|
export interface ProtocolMessage {
|
||||||
serviceType: number;
|
serviceType: number;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user