2019-09-19 05:15:43 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import {
|
|
|
|
Resolve,
|
|
|
|
ActivatedRouteSnapshot,
|
|
|
|
RouterStateSnapshot
|
|
|
|
} from '@angular/router';
|
2019-09-24 00:23:30 +00:00
|
|
|
import { Observable, of } from 'rxjs';
|
|
|
|
import { take, map, catchError } from 'rxjs/operators';
|
2019-09-19 05:15:43 +00:00
|
|
|
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
|
|
|
|
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
import { PublicApiService } from '@ucap-webmessenger/api-public';
|
|
|
|
|
|
|
|
import * as AppStore from '../store';
|
|
|
|
import * as VersionInfoStore from '../store/setting/version-info';
|
|
|
|
import { LoginInfo, KEY_LOGIN_INFO } from '../types';
|
|
|
|
import { InnerProtocolService } from '@ucap-webmessenger/protocol-inner';
|
2019-09-19 06:51:42 +00:00
|
|
|
import {
|
|
|
|
AuthenticationProtocolService,
|
|
|
|
SSOMode
|
|
|
|
} from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import { LocaleCode } from '@ucap-webmessenger/core';
|
2019-09-24 00:23:30 +00:00
|
|
|
import * as AuthenticationStore from '@app/store/account/authentication';
|
2019-09-19 05:15:43 +00:00
|
|
|
|
|
|
|
@Injectable()
|
2019-09-23 05:23:24 +00:00
|
|
|
export class AppMessengerResolver implements Resolve<void> {
|
2019-09-19 05:15:43 +00:00
|
|
|
constructor(
|
|
|
|
private store: Store<any>,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
|
|
|
private publicApiService: PublicApiService,
|
|
|
|
private protocolService: ProtocolService,
|
2019-09-19 06:51:42 +00:00
|
|
|
private authenticationProtocolService: AuthenticationProtocolService,
|
2019-09-19 05:15:43 +00:00
|
|
|
private innerProtocolService: InnerProtocolService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
resolve(
|
|
|
|
route: ActivatedRouteSnapshot,
|
|
|
|
state: RouterStateSnapshot
|
|
|
|
): 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(
|
2019-09-23 05:23:24 +00:00
|
|
|
take(1),
|
2019-09-19 06:51:42 +00:00
|
|
|
map(connRes => {
|
2019-09-24 00:03:36 +00:00
|
|
|
console.log('connRes', connRes);
|
2019-09-19 06:51:42 +00:00
|
|
|
this.authenticationProtocolService
|
|
|
|
.login({
|
|
|
|
loginId: loginInfo.loginId,
|
|
|
|
loginPw: loginInfo.loginPw,
|
|
|
|
deviceType: loginInfo.deviceType,
|
|
|
|
deviceId: ' ',
|
|
|
|
token: '',
|
|
|
|
localeCode: LocaleCode.Korean,
|
|
|
|
pushId: ' ',
|
|
|
|
companyCode: loginInfo.companyCode,
|
|
|
|
passwordEncodingType: 1,
|
|
|
|
clientVersion: '',
|
|
|
|
reconnect: false,
|
|
|
|
ip: 'localhost',
|
|
|
|
hostName: '',
|
|
|
|
ssoMode: SSOMode.AUTH,
|
|
|
|
userSpecificInformation: 'PRO_000482',
|
|
|
|
productId: 'PRO_000482',
|
|
|
|
productName: 'EZMessenger'
|
|
|
|
})
|
|
|
|
.pipe(
|
2019-09-23 05:23:24 +00:00
|
|
|
take(1),
|
2019-09-19 06:51:42 +00:00
|
|
|
map(loginRes => {
|
2019-09-24 00:23:30 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
AuthenticationStore.loginSuccess({
|
|
|
|
loginInfo: loginRes
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
catchError(err => {
|
|
|
|
return of(
|
|
|
|
AuthenticationStore.loginFailure({ error: err })
|
|
|
|
);
|
2019-09-19 06:51:42 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-09-19 05:15:43 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
})
|
|
|
|
.catch(reason => {});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|