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,7 +42,8 @@ export class AppMessengerResolver implements Resolve<void> {
): void | Observable<void> | Promise<void> {
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
return this.publicApiService
return new Promise<void>((resolve, reject) => {
this.publicApiService
.versionInfo2({
deviceType: loginInfo.deviceType,
companyGroupType: 'C',
@ -50,19 +52,15 @@ export class AppMessengerResolver implements Resolve<void> {
})
.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({
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,
@ -81,8 +79,7 @@ export class AppMessengerResolver implements Resolve<void> {
productId: 'PRO_000482',
productName: 'EZMessenger'
})
.pipe(
take(1),
),
map(loginRes => {
this.store.dispatch(
AuthenticationStore.loginSuccess({
@ -91,18 +88,17 @@ export class AppMessengerResolver implements Resolve<void> {
);
}),
catchError(err => {
return of(
AuthenticationStore.loginFailure({ error: err })
);
return throwError(err);
})
)
.subscribe();
})
)
.subscribe();
})
.catch(reason => {});
})
.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,11 +75,8 @@ export class Effects {
() =>
this.actions$.pipe(
ofType(webLoginSuccess),
tap(params => {
this.nativeService
.checkForUpdates()
.pipe(
take(1),
switchMap(params =>
this.nativeService.checkForUpdates().pipe(
map((update: boolean) => {
if (!update) {
this.appAuthenticationService.login(
@ -84,8 +88,7 @@ export class Effects {
}),
catchError(error => of(error))
)
.subscribe();
})
)
),
{ dispatch: false }
);

View File

@ -54,14 +54,15 @@ export class ProtocolService {
.pipe(share());
}
public connect(serverIp: string | null = null): Promise<void> {
return new Promise<void>((resolve, reject) => {
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 => {
resolve();
subscriber.next();
return getResponses(this.input$);
}),
retryWhen(errors =>
@ -117,6 +118,9 @@ export class ProtocolService {
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 {