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 62f03f52..5ebe371c 100644 --- a/projects/ucap-webmessenger-app/src/app/services/app.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/app.service.ts @@ -7,7 +7,9 @@ import { Store } from '@ngrx/store'; import { ProtocolService } from '@ucap-webmessenger/protocol'; import { SVC_TYPE_LOGOUT, - SSVC_TYPE_LOGOUT_RES + SSVC_TYPE_LOGOUT_RES, + SSVC_TYPE_LOGOUT_REMOTE_NOTI, + AuthenticationProtocolService } from '@ucap-webmessenger/protocol-authentication'; import * as AuthenticationStore from '../store/account/authentication'; @@ -16,17 +18,39 @@ import * as AuthenticationStore from '../store/account/authentication'; 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( - res => - res.serviceType === SVC_TYPE_LOGOUT && - res.subServiceType === SSVC_TYPE_LOGOUT_RES + message => + message.subServiceType === SSVC_TYPE_LOGOUT_RES || + message.subServiceType === SSVC_TYPE_LOGOUT_REMOTE_NOTI ), - tap(res => { - this.store.dispatch(AuthenticationStore.logout()); + 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(); 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 e44e9edf..1a006447 100644 --- a/projects/ucap-webmessenger-protocol-authentication/src/lib/models/logout.ts +++ b/projects/ucap-webmessenger-protocol-authentication/src/lib/models/logout.ts @@ -1,7 +1,25 @@ -import { ProtocolRequest, ProtocolResponse } from '@ucap-webmessenger/protocol'; +import { DeviceType } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolNotification +} from '@ucap-webmessenger/protocol'; // 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 LogoutRemoteRequest extends ProtocolRequest { + targetDeviceType?: DeviceType; + requestDeviceType?: DeviceType; +} +export interface LogoutRemoteResponse extends ProtocolResponse { + targetDeviceType?: DeviceType; + resultCode?: number; +} + +export interface LogoutRemoteNotification extends ProtocolNotification { + requestDeviceType?: 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 dea6c3ec..a1ba23b5 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 @@ -6,17 +6,25 @@ import { map } from 'rxjs/operators'; import { ProtocolService, PacketBody, - PacketBodyValue + PacketBodyValue, + ServerMessage } from '@ucap-webmessenger/protocol'; import { LoginRequest, LoginResponse } from '../models/login'; import { SVC_TYPE_LOGIN, SSVC_TYPE_LOGIN_REQ, SVC_TYPE_LOGOUT, - SSVC_TYPE_LOGOUT_REQ + SSVC_TYPE_LOGOUT_REQ, + SSVC_TYPE_LOGOUT_REMOTE_REQ } from '../types/service'; import { RoleCode } from '../types/role-code'; -import { LogoutRequest, LogoutResponse } from '../models/logout'; +import { + LogoutRequest, + LogoutResponse, + LogoutRemoteRequest, + LogoutRemoteResponse, + LogoutRemoteNotification +} from '../models/logout'; @Injectable({ providedIn: 'root' @@ -58,53 +66,97 @@ export class AuthenticationProtocolService { .call(SVC_TYPE_LOGIN, SSVC_TYPE_LOGIN_REQ, ...bodyList) .pipe( map(res => { - return { - loginId: res.bodyList[0], - userSeq: res.bodyList[1], - userInfo: res.bodyList[2], - token: res.bodyList[3], - companyCode: res.bodyList[4], - departmentCode: res.bodyList[5], - userId: res.bodyList[6], - passwordEncodingType: res.bodyList[7], - encriptionKey: res.bodyList[8], - existingPid: res.bodyList[9] === 'Y' ? true : false, - roleCode: res.bodyList[10] as RoleCode, - statusMessage1: res.bodyList[11], - statusMessage2: res.bodyList[12], - statusMessage3: res.bodyList[13], - fileDownloadAllow: res.bodyList[14] === 'Y' ? true : false, - fileRetentionPeriod: res.bodyList[15], - passwordValidityPeriod: res.bodyList[16], - privateInformationAgree: res.bodyList[17] === 'Y' ? true : false, - madn: res.bodyList[18], - hardPhoneSadn: res.bodyList[19], - fmcSadn: res.bodyList[20], - pbxIndex: res.bodyList[21], - passwordExpired: res.bodyList[22] === 'Y' ? true : false, - validAccount: res.bodyList[23] === 'Y' ? true : false, - validDevice: res.bodyList[24] === 'Y' ? true : false, - useableDevice: res.bodyList[25] === 'Y' ? true : false, - deviceScreenForcedLock: res.bodyList[26] === 'Y' ? true : false, - tokenString: res.bodyList[27], - havePermissionsForIntegratedMessageBox: - res.bodyList[28] === 'Y' ? true : false, - talkWithMeBotSeq: res.bodyList[29], - pinCode: res.bodyList[30], - permissionsForViewSchedule: res.bodyList[31], - havePermissionsForDevice: res.bodyList[32] === 'Y' ? true : false - } as LoginResponse; + return this.decodeLoginResponse(res); }) ); } + public decodeLoginResponse(message: ServerMessage): LoginResponse { + return { + loginId: message.bodyList[0], + userSeq: message.bodyList[1], + userInfo: message.bodyList[2], + token: message.bodyList[3], + companyCode: message.bodyList[4], + departmentCode: message.bodyList[5], + userId: message.bodyList[6], + passwordEncodingType: message.bodyList[7], + encriptionKey: message.bodyList[8], + existingPid: message.bodyList[9] === 'Y' ? true : false, + roleCode: message.bodyList[10] as RoleCode, + statusMessage1: message.bodyList[11], + statusMessage2: message.bodyList[12], + statusMessage3: message.bodyList[13], + fileDownloadAllow: message.bodyList[14] === 'Y' ? true : false, + fileRetentionPeriod: message.bodyList[15], + passwordValidityPeriod: message.bodyList[16], + privateInformationAgree: message.bodyList[17] === 'Y' ? true : false, + madn: message.bodyList[18], + hardPhoneSadn: message.bodyList[19], + fmcSadn: message.bodyList[20], + pbxIndex: message.bodyList[21], + passwordExpired: message.bodyList[22] === 'Y' ? true : false, + validAccount: message.bodyList[23] === 'Y' ? true : false, + validDevice: message.bodyList[24] === 'Y' ? true : false, + useableDevice: message.bodyList[25] === 'Y' ? true : false, + deviceScreenForcedLock: message.bodyList[26] === 'Y' ? true : false, + tokenString: message.bodyList[27], + havePermissionsForIntegratedMessageBox: + message.bodyList[28] === 'Y' ? true : false, + talkWithMeBotSeq: message.bodyList[29], + pinCode: message.bodyList[30], + permissionsForViewSchedule: message.bodyList[31], + havePermissionsForDevice: message.bodyList[32] === 'Y' ? true : false + } as LoginResponse; + } + public logout(req: LogoutRequest): Observable { return this.protocolService .call(SVC_TYPE_LOGOUT, SSVC_TYPE_LOGOUT_REQ) .pipe( map(res => { - return {} as LogoutResponse; + return this.decodeLogoutResponse(res); }) ); } + + public decodeLogoutResponse(message: ServerMessage): LogoutResponse { + return {} as LogoutResponse; + } + + public logoutRemote( + req: LogoutRemoteRequest + ): Observable { + const bodyList: PacketBody[] = []; + + bodyList.push( + { type: PacketBodyValue.String, value: req.targetDeviceType }, + { type: PacketBodyValue.String, value: req.requestDeviceType } + ); + + return this.protocolService + .call(SVC_TYPE_LOGOUT, SSVC_TYPE_LOGOUT_REMOTE_REQ, ...bodyList) + .pipe( + map(res => { + return this.decodeLogoutRemoteResponse(res); + }) + ); + } + + public decodeLogoutRemoteResponse( + message: ServerMessage + ): LogoutRemoteResponse { + return { + targetDeviceType: message.bodyList[0], + resultCode: message.bodyList[1] + } as LogoutRemoteResponse; + } + + public decodeLogoutRemoteNotification( + message: ServerMessage + ): LogoutRemoteNotification { + return { + requestDeviceType: message.bodyList[0] + } as LogoutRemoteNotification; + } } diff --git a/projects/ucap-webmessenger-protocol/src/lib/models/protocol.ts b/projects/ucap-webmessenger-protocol/src/lib/models/protocol.ts index 8c595995..b042de4e 100644 --- a/projects/ucap-webmessenger-protocol/src/lib/models/protocol.ts +++ b/projects/ucap-webmessenger-protocol/src/lib/models/protocol.ts @@ -5,3 +5,6 @@ export interface ProtocolRequest { export interface ProtocolResponse { _id?: string; } + +// tslint:disable-next-line: no-empty-interface +export interface ProtocolNotification {}