diff --git a/projects/ucap-webmessenger-app/src/app/guards/auth.guard.ts b/projects/ucap-webmessenger-app/src/app/guards/auth.guard.ts index 8aa88a76..0feb87b1 100644 --- a/projects/ucap-webmessenger-app/src/app/guards/auth.guard.ts +++ b/projects/ucap-webmessenger-app/src/app/guards/auth.guard.ts @@ -10,7 +10,7 @@ import { Store, select } from '@ngrx/store'; import { Observable } from 'rxjs'; import { map, take } from 'rxjs/operators'; -import { AuthenticationService } from '../services/authentication.service'; +import { AppAuthenticationService } from '../services/authentication.service'; @Injectable({ providedIn: 'root' @@ -18,7 +18,7 @@ import { AuthenticationService } from '../services/authentication.service'; export class AuthGuard implements CanActivate { constructor( private router: Router, - private authenticationService: AuthenticationService + private appAuthenticationService: AppAuthenticationService ) {} canActivate( @@ -30,7 +30,7 @@ export class AuthGuard implements CanActivate { | Observable | Promise { return new Promise((resolve, reject) => { - if (this.authenticationService.authenticated()) { + if (this.appAuthenticationService.authenticated()) { resolve(true); } else { this.router.navigateByUrl('/account/login'); diff --git a/projects/ucap-webmessenger-app/src/app/interceptors/loader.interceptor.ts b/projects/ucap-webmessenger-app/src/app/interceptors/loader.interceptor.ts index e3e4485f..e0fd1e7b 100644 --- a/projects/ucap-webmessenger-app/src/app/interceptors/loader.interceptor.ts +++ b/projects/ucap-webmessenger-app/src/app/interceptors/loader.interceptor.ts @@ -7,7 +7,7 @@ import { } from '@angular/common/http'; import { Observable } from 'rxjs'; import { finalize, delay } from 'rxjs/operators'; -import { LoaderService } from '../services/loader.service'; +import { AppLoaderService } from '../services/loader.service'; @Injectable() export class LoaderInterceptor implements HttpInterceptor { @@ -22,13 +22,13 @@ export class LoaderInterceptor implements HttpInterceptor { } console.warn('LoaderInterceptor'); - const loaderService = this.injector.get(LoaderService); + const appLoaderService = this.injector.get(AppLoaderService); - loaderService.show(); + appLoaderService.show(); return next.handle(req).pipe( delay(3000), - finalize(() => loaderService.hide()) + finalize(() => appLoaderService.hide()) ); } } diff --git a/projects/ucap-webmessenger-app/src/app/services/app.service.ts b/projects/ucap-webmessenger-app/src/app/services/app.service.ts index 5ebe371c..2ab032ab 100644 --- a/projects/ucap-webmessenger-app/src/app/services/app.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/app.service.ts @@ -1,63 +1,13 @@ 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, - AuthenticationProtocolService -} from '@ucap-webmessenger/protocol-authentication'; - -import * as AuthenticationStore from '../store/account/authentication'; +import { AppNotificationService } from './notification.service'; @Injectable() export class AppService { - constructor( - private protocolService: ProtocolService, - private authenticationProtocolService: AuthenticationProtocolService, - private store: Store - ) { - this.protocolService.serverMessage - .pipe( - filter(message => message.serviceType === SVC_TYPE_LOGOUT), - filter( - message => - message.subServiceType === SSVC_TYPE_LOGOUT_RES || - message.subServiceType === SSVC_TYPE_LOGOUT_REMOTE_NOTI - ), - 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; - } - }) - ) - .subscribe(); - } + constructor(private appNotificationService: AppNotificationService) {} public postInit(): Promise { return new Promise((resolve, reject) => { + this.appNotificationService.subscribe(); resolve(); }); } diff --git a/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts b/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts index ee825ca2..ea00f7f7 100644 --- a/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts @@ -13,7 +13,7 @@ import { LoginInfo, KEY_LOGIN_INFO } from '../types'; @Injectable({ providedIn: 'root' }) -export class AuthenticationService { +export class AppAuthenticationService { showLoader = false; constructor( diff --git a/projects/ucap-webmessenger-app/src/app/services/index.ts b/projects/ucap-webmessenger-app/src/app/services/index.ts index 6c72be22..9e6d24ef 100644 --- a/projects/ucap-webmessenger-app/src/app/services/index.ts +++ b/projects/ucap-webmessenger-app/src/app/services/index.ts @@ -1,5 +1,11 @@ import { AppService } from './app.service'; -import { AuthenticationService } from './authentication.service'; -import { LoaderService } from './loader.service'; +import { AppAuthenticationService } from './authentication.service'; +import { AppLoaderService } from './loader.service'; +import { AppNotificationService } from './notification.service'; -export const SERVICES = [AppService, AuthenticationService, LoaderService]; +export const SERVICES = [ + AppService, + AppAuthenticationService, + AppLoaderService, + AppNotificationService +]; diff --git a/projects/ucap-webmessenger-app/src/app/services/loader.service.ts b/projects/ucap-webmessenger-app/src/app/services/loader.service.ts index fe44bc82..dee5ddc1 100644 --- a/projects/ucap-webmessenger-app/src/app/services/loader.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/loader.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) -export class LoaderService { +export class AppLoaderService { showLoader = false; constructor() {} diff --git a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts new file mode 100644 index 00000000..2b55c3a5 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -0,0 +1,59 @@ +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, + AuthenticationProtocolService +} from '@ucap-webmessenger/protocol-authentication'; + +import * as AuthenticationStore from '../store/account/authentication'; + +@Injectable() +export class AppNotificationService { + constructor( + private protocolService: ProtocolService, + private authenticationProtocolService: AuthenticationProtocolService, + private store: Store + ) {} + + public subscribe(): void { + this.protocolService.serverMessage + .pipe( + filter( + message => + message.serviceType === SVC_TYPE_LOGOUT && + message.subServiceType === SSVC_TYPE_LOGOUT_RES + ), + tap(message => { + const logoutRes = this.authenticationProtocolService.decodeLogoutResponse( + message + ); + 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 => { + const logoutRemoteNoti = this.authenticationProtocolService.decodeLogoutRemoteNotification( + message + ); + this.store.dispatch(AuthenticationStore.logout()); + }) + ) + .subscribe(); + } +} diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts index 4cb92332..b3d81cea 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts @@ -29,7 +29,7 @@ import { logoutConfirmationDismiss } from './actions'; import { LoginInfo } from '../../../types'; -import { AuthenticationService } from '../../../services/authentication.service'; +import { AppAuthenticationService } from '../../../services/authentication.service'; @Injectable() export class Effects { @@ -73,7 +73,7 @@ export class Effects { take(1), map((update: boolean) => { if (!update) { - this.authenticationService.login( + this.appAuthenticationService.login( params.loginInfo, params.rememberMe ); @@ -104,7 +104,7 @@ export class Effects { ofType(logout), map(action => action), map(() => { - this.authenticationService.logout(); + this.appAuthenticationService.logout(); return loginRedirect(); }) ) @@ -136,7 +136,7 @@ export class Effects { private actions$: Actions, private router: Router, private piService: PiService, - private authenticationService: AuthenticationService, + private appAuthenticationService: AppAuthenticationService, private dialogService: DialogService, @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService ) {} diff --git a/projects/ucap-webmessenger-protocol-authentication/src/lib/models/logout.ts b/projects/ucap-webmessenger-protocol-authentication/src/lib/models/logout.ts index 1a006447..469b122d 100644 --- a/projects/ucap-webmessenger-protocol-authentication/src/lib/models/logout.ts +++ b/projects/ucap-webmessenger-protocol-authentication/src/lib/models/logout.ts @@ -8,8 +8,9 @@ import { // tslint:disable-next-line: no-empty-interface export interface LogoutRequest extends ProtocolRequest {} -// tslint:disable-next-line: no-empty-interface -export interface LogoutResponse extends ProtocolResponse {} +export interface LogoutResponse extends ProtocolResponse { + reasonCode?: number; +} export interface LogoutRemoteRequest extends ProtocolRequest { targetDeviceType?: DeviceType; diff --git a/projects/ucap-webmessenger-protocol-authentication/src/lib/services/authentication-protocol.service.ts b/projects/ucap-webmessenger-protocol-authentication/src/lib/services/authentication-protocol.service.ts index a1ba23b5..717f430c 100644 --- a/projects/ucap-webmessenger-protocol-authentication/src/lib/services/authentication-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-authentication/src/lib/services/authentication-protocol.service.ts @@ -121,7 +121,9 @@ export class AuthenticationProtocolService { } public decodeLogoutResponse(message: ServerMessage): LogoutResponse { - return {} as LogoutResponse; + return { + reasonCode: message.bodyList[0] + } as LogoutResponse; } public logoutRemote(