bug of AppMessengerResolver is fixed

This commit is contained in:
병준 박 2019-09-24 18:42:53 +09:00
parent c49e7e5931
commit a198cf8ddf
6 changed files with 151 additions and 142 deletions

View File

@ -21,7 +21,7 @@ const routes: Routes = [
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
imports: [RouterModule.forRoot(routes, { enableTracing: true })],
exports: [RouterModule]
})
export class AppRoutingModule {}

View File

@ -4,10 +4,10 @@ import {
ActivatedRouteSnapshot,
RouterStateSnapshot
} from '@angular/router';
import { Observable, of } from 'rxjs';
import { take, map, catchError } from 'rxjs/operators';
import { Observable, throwError } from 'rxjs';
import { map, tap, mergeMap, catchError, take } from 'rxjs/operators';
import { Store, select } from '@ngrx/store';
import { Store } from '@ngrx/store';
import { ProtocolService } from '@ucap-webmessenger/protocol';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
@ -19,9 +19,10 @@ import { LoginInfo, KEY_LOGIN_INFO } from '../types';
import { InnerProtocolService } from '@ucap-webmessenger/protocol-inner';
import {
AuthenticationProtocolService,
SSOMode
SSOMode,
LoginResponse
} from '@ucap-webmessenger/protocol-authentication';
import { LocaleCode } from '@ucap-webmessenger/core';
import * as AuthenticationStore from '@app/store/account/authentication';
@Injectable()
@ -41,68 +42,63 @@ export class AppMessengerResolver implements Resolve<void> {
): void | Observable<void> | Promise<void> {
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
return this.publicApiService
.versionInfo2({
deviceType: loginInfo.deviceType,
companyGroupType: 'C',
companyCode: loginInfo.companyCode,
loginId: loginInfo.loginId
})
.pipe(
take(1),
map(res => {
this.store.dispatch(VersionInfoStore.fetchSuccess(res));
this.protocolService
.connect(res.serverIp)
.then(() => {
this.innerProtocolService
.conn({})
.pipe(
take(1),
map(connRes => {
console.log('connRes', connRes);
this.authenticationProtocolService
.login({
loginId: loginInfo.loginId,
loginPw: loginInfo.loginPw,
deviceType: loginInfo.deviceType,
deviceId: ' ',
token: '',
localeCode: loginInfo.localeCode,
pushId: ' ',
companyCode: loginInfo.companyCode,
passwordEncodingType: 1,
clientVersion: '',
reconnect: false,
ip: 'localhost',
hostName: '',
ssoMode: SSOMode.AUTH,
userSpecificInformation: 'PRO_000482',
productId: 'PRO_000482',
productName: 'EZMessenger'
})
.pipe(
take(1),
map(loginRes => {
this.store.dispatch(
AuthenticationStore.loginSuccess({
loginInfo: loginRes
})
);
}),
catchError(err => {
return of(
AuthenticationStore.loginFailure({ error: err })
);
})
)
.subscribe();
})
)
.subscribe();
})
.catch(reason => {});
return new Promise<void>((resolve, reject) => {
this.publicApiService
.versionInfo2({
deviceType: loginInfo.deviceType,
companyGroupType: 'C',
companyCode: loginInfo.companyCode,
loginId: loginInfo.loginId
})
);
.pipe(
take(1),
tap(versionInfo2Res => {
this.store.dispatch(VersionInfoStore.fetchSuccess(versionInfo2Res));
}),
mergeMap(versionInfo2Res =>
this.protocolService.connect(versionInfo2Res.serverIp)
),
mergeMap(() => this.innerProtocolService.conn({})),
mergeMap(connRres =>
this.authenticationProtocolService.login({
loginId: loginInfo.loginId,
loginPw: loginInfo.loginPw,
deviceType: loginInfo.deviceType,
deviceId: ' ',
token: '',
localeCode: loginInfo.localeCode,
pushId: ' ',
companyCode: loginInfo.companyCode,
passwordEncodingType: 1,
clientVersion: '',
reconnect: false,
ip: 'localhost',
hostName: '',
ssoMode: SSOMode.AUTH,
userSpecificInformation: 'PRO_000482',
productId: 'PRO_000482',
productName: 'EZMessenger'
})
),
map(loginRes => {
this.store.dispatch(
AuthenticationStore.loginSuccess({
loginInfo: loginRes
})
);
}),
catchError(err => {
return throwError(err);
})
)
.subscribe(
() => {
resolve();
},
err => {
reject();
}
);
});
}
}

View File

@ -4,7 +4,14 @@ import { Router } from '@angular/router';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { of } from 'rxjs';
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
import {
catchError,
exhaustMap,
map,
tap,
take,
switchMap
} from 'rxjs/operators';
import {
PiService,
@ -68,24 +75,20 @@ export class Effects {
() =>
this.actions$.pipe(
ofType(webLoginSuccess),
tap(params => {
this.nativeService
.checkForUpdates()
.pipe(
take(1),
map((update: boolean) => {
if (!update) {
this.appAuthenticationService.login(
params.loginInfo,
params.rememberMe
);
this.router.navigate(['/messenger']);
}
}),
catchError(error => of(error))
)
.subscribe();
})
switchMap(params =>
this.nativeService.checkForUpdates().pipe(
map((update: boolean) => {
if (!update) {
this.appAuthenticationService.login(
params.loginInfo,
params.rememberMe
);
this.router.navigate(['/messenger']);
}
}),
catchError(error => of(error))
)
)
),
{ dispatch: false }
);

View File

@ -54,69 +54,73 @@ export class ProtocolService {
.pipe(share());
}
public connect(serverIp: string | null = null): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.socket$ = makeWebSocketObservable(
`${this.moduleConfig.urls.base}${serverIp ? serverIp : ''}`
);
this.messages$ = this.socket$.pipe(
switchMap(getResponses => {
resolve();
return getResponses(this.input$);
}),
retryWhen(errors =>
errors.pipe(delay(this.moduleConfig.reconnect.delay))
),
share()
);
public connect(serverIp: string | null = null): Observable<void> {
return new Observable<void>(subscriber => {
try {
this.socket$ = makeWebSocketObservable(
`${this.moduleConfig.urls.base}${serverIp ? serverIp : ''}`
);
this.messages$ = this.socket$.pipe(
switchMap(getResponses => {
subscriber.next();
return getResponses(this.input$);
}),
retryWhen(errors =>
errors.pipe(delay(this.moduleConfig.reconnect.delay))
),
share()
);
this.messagesSubscription = this.messages$.subscribe(
(message: string) => {
const arg = message.split(PacketBodyDivider);
if (2 > arg.length) {
// OnError(3);
return;
}
this.messagesSubscription = this.messages$.subscribe(
(message: string) => {
const arg = message.split(PacketBodyDivider);
if (2 > arg.length) {
// OnError(3);
return;
}
const res = this.decodePacket(arg);
const res = this.decodePacket(arg);
let requestState: RequestState | null = null;
if (res.requestId) {
requestState = this.pendingRequests.get(res.requestId);
}
let requestState: RequestState | null = null;
if (res.requestId) {
requestState = this.pendingRequests.get(res.requestId);
}
if (SSVC_TYPE_ERROR_RES === res.message.subServiceType) {
const errorCode: ServerErrorCode = res.message
.bodyList[0] as ServerErrorCode;
if (SSVC_TYPE_ERROR_RES === res.message.subServiceType) {
const errorCode: ServerErrorCode = res.message
.bodyList[0] as ServerErrorCode;
if (requestState) {
requestState.subject.error(errorCode);
}
return;
}
if (requestState) {
requestState.subject.error(errorCode);
requestState.subject.next(res.message);
return;
}
return;
}
if (requestState) {
requestState.subject.next(res.message);
return;
this.serverMessageSubject.next(res.message);
},
(error: Error) => {
const { message } = error;
if (message === NormalClosureMessage) {
console.log('server closed the websocket connection normally');
} else {
console.log('socket was disconnected due to error:', message);
}
},
() => {
// The clean termination only happens in response to the last
// subscription to the observable being unsubscribed, any
// other closure is considered an error.
console.log('the connection was closed in response to the user');
}
this.serverMessageSubject.next(res.message);
},
(error: Error) => {
const { message } = error;
if (message === NormalClosureMessage) {
console.log('server closed the websocket connection normally');
} else {
console.log('socket was disconnected due to error:', message);
}
},
() => {
// The clean termination only happens in response to the last
// subscription to the observable being unsubscribed, any
// other closure is considered an error.
console.log('the connection was closed in response to the user');
}
);
);
} catch (error) {
subscriber.error(error);
}
});
}

View File

@ -8,7 +8,7 @@
{{ data.message }}
</div>
</mat-card-content>
<mat-card-actions class="button-farm flex-row">
<mat-card-actions *ngIf="!hideAction" class="button-farm flex-row">
<button
mat-stroked-button
(click)="onClickChoice(false)"

View File

@ -11,6 +11,7 @@ export interface ConfirmDialogData {
title: string;
message?: string;
html?: string;
hideAction?: boolean;
}
export interface ConfirmDialogResult {
@ -26,6 +27,8 @@ export class ConfirmDialogComponent implements OnInit {
@ViewChild('messageContainer', { static: true })
messageContainer: ElementRef;
hideAction = false;
constructor(
public dialogRef: MatDialogRef<ConfirmDialogComponent, ConfirmDialogResult>,
@Inject(MAT_DIALOG_DATA) public data: ConfirmDialogData
@ -35,6 +38,9 @@ export class ConfirmDialogComponent implements OnInit {
if (!!this.data.html) {
this.messageContainer.nativeElement.innerHTML = this.data.html;
}
if (!!this.data.hideAction) {
this.hideAction = this.data.hideAction;
}
}
onClickChoice(choice: boolean): void {