2019-12-24 08:31:03 +00:00
|
|
|
import { Injectable, Inject } from '@angular/core';
|
2019-09-19 05:15:43 +00:00
|
|
|
import {
|
|
|
|
Resolve,
|
|
|
|
ActivatedRouteSnapshot,
|
|
|
|
RouterStateSnapshot
|
|
|
|
} from '@angular/router';
|
2019-12-13 05:38:42 +00:00
|
|
|
import { Observable, throwError, forkJoin, of } from 'rxjs';
|
2019-10-02 05:34:17 +00:00
|
|
|
import {
|
|
|
|
map,
|
|
|
|
tap,
|
|
|
|
catchError,
|
|
|
|
take,
|
|
|
|
switchMap,
|
|
|
|
withLatestFrom
|
|
|
|
} from 'rxjs/operators';
|
2019-09-19 05:15:43 +00:00
|
|
|
|
2019-10-02 05:34:17 +00:00
|
|
|
import { Store, select } from '@ngrx/store';
|
2019-09-19 05:15:43 +00:00
|
|
|
|
2019-11-29 07:08:24 +00:00
|
|
|
import { ProtocolService, ServerErrorCode } from '@ucap-webmessenger/protocol';
|
2019-09-19 05:15:43 +00:00
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
2019-10-15 05:58:11 +00:00
|
|
|
import {
|
|
|
|
PublicApiService,
|
|
|
|
VersionInfo2Response
|
|
|
|
} from '@ucap-webmessenger/api-public';
|
2019-09-19 05:15:43 +00:00
|
|
|
|
2019-09-27 03:53:21 +00:00
|
|
|
import {
|
|
|
|
LoginInfo,
|
|
|
|
KEY_LOGIN_INFO,
|
|
|
|
EnvironmentsInfo,
|
2019-12-13 05:38:42 +00:00
|
|
|
KEY_ENVIRONMENTS_INFO,
|
2020-01-09 05:24:09 +00:00
|
|
|
KEY_URL_INFO,
|
|
|
|
KEY_AUTH_INFO
|
2019-10-04 04:45:02 +00:00
|
|
|
} from '@app/types';
|
2019-09-19 05:15:43 +00:00
|
|
|
import { InnerProtocolService } from '@ucap-webmessenger/protocol-inner';
|
2019-09-19 06:51:42 +00:00
|
|
|
import {
|
|
|
|
AuthenticationProtocolService,
|
2019-09-24 09:42:53 +00:00
|
|
|
SSOMode,
|
|
|
|
LoginResponse
|
2019-09-19 06:51:42 +00:00
|
|
|
} from '@ucap-webmessenger/protocol-authentication';
|
2019-09-24 09:42:53 +00:00
|
|
|
|
2019-09-24 00:23:30 +00:00
|
|
|
import * as AuthenticationStore from '@app/store/account/authentication';
|
2019-10-02 05:34:17 +00:00
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2020-01-09 05:24:09 +00:00
|
|
|
import {
|
|
|
|
QueryProtocolService,
|
|
|
|
AuthResponse
|
|
|
|
} from '@ucap-webmessenger/protocol-query';
|
2019-10-02 05:34:17 +00:00
|
|
|
import { OptionProtocolService } from '@ucap-webmessenger/protocol-option';
|
|
|
|
|
2019-12-17 06:13:25 +00:00
|
|
|
import { TranslateService as UCapTranslateService } from '@ucap-webmessenger/ui';
|
|
|
|
|
2019-10-02 05:34:17 +00:00
|
|
|
import * as AppStore from '@app/store';
|
2019-10-07 07:29:38 +00:00
|
|
|
import * as CompanyStore from '@app/store/setting/company';
|
2019-10-02 05:34:17 +00:00
|
|
|
import * as VersionInfoStore from '@app/store/setting/version-info';
|
2019-10-04 04:45:02 +00:00
|
|
|
import * as OptionStore from '@app/store/messenger/option';
|
|
|
|
import * as QueryStore from '@app/store/messenger/query';
|
2019-10-02 05:34:17 +00:00
|
|
|
import * as SyncStore from '@app/store/messenger/sync';
|
2019-12-13 05:38:42 +00:00
|
|
|
import { KEY_LOGIN_RES_INFO, KEY_VER_INFO } from '@app/types';
|
2019-09-19 05:15:43 +00:00
|
|
|
|
2019-11-28 04:44:41 +00:00
|
|
|
import { environment } from '../../environments/environment';
|
2019-11-29 07:08:24 +00:00
|
|
|
import { SnackBarService } from '@ucap-webmessenger/ui';
|
2019-12-12 08:15:09 +00:00
|
|
|
import { AppNativeService } from '@app/services/native.service';
|
2019-12-13 05:38:42 +00:00
|
|
|
import {
|
|
|
|
ExternalApiService,
|
|
|
|
UrlInfoResponse,
|
|
|
|
DaesangUrlInfoResponse
|
|
|
|
} from '@ucap-webmessenger/api-external';
|
|
|
|
import { StatusCode } from '@ucap-webmessenger/api';
|
2019-12-24 08:31:03 +00:00
|
|
|
import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native';
|
2019-11-28 04:44:41 +00:00
|
|
|
|
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(
|
2019-12-24 08:31:03 +00:00
|
|
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
2019-09-19 05:15:43 +00:00
|
|
|
private store: Store<any>,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
|
|
|
private publicApiService: PublicApiService,
|
2019-12-13 05:38:42 +00:00
|
|
|
private externalApiService: ExternalApiService,
|
2019-09-19 05:15:43 +00:00
|
|
|
private protocolService: ProtocolService,
|
2019-10-02 05:34:17 +00:00
|
|
|
private queryProtocolService: QueryProtocolService,
|
|
|
|
private optionProtocolService: OptionProtocolService,
|
2019-09-19 06:51:42 +00:00
|
|
|
private authenticationProtocolService: AuthenticationProtocolService,
|
2019-10-02 05:34:17 +00:00
|
|
|
private innerProtocolService: InnerProtocolService,
|
2019-12-12 08:15:09 +00:00
|
|
|
private appNativeService: AppNativeService,
|
2019-11-29 07:08:24 +00:00
|
|
|
private snackBarService: SnackBarService,
|
2019-10-02 05:34:17 +00:00
|
|
|
private logger: NGXLogger
|
2019-09-19 05:15:43 +00:00
|
|
|
) {}
|
|
|
|
|
|
|
|
resolve(
|
2019-10-02 05:34:17 +00:00
|
|
|
activatedRouteSnapshot: ActivatedRouteSnapshot,
|
|
|
|
routerStateSnapshot: RouterStateSnapshot
|
2019-09-19 05:15:43 +00:00
|
|
|
): void | Observable<void> | Promise<void> {
|
2019-12-24 08:31:03 +00:00
|
|
|
return new Promise<void>(async (resolve, reject) => {
|
2019-10-02 05:34:17 +00:00
|
|
|
let loginRes: LoginResponse;
|
|
|
|
|
|
|
|
const loginInfo = this.sessionStorageService.get<LoginInfo>(
|
|
|
|
KEY_LOGIN_INFO
|
|
|
|
);
|
|
|
|
const environmentsInfo = this.sessionStorageService.get<EnvironmentsInfo>(
|
|
|
|
KEY_ENVIRONMENTS_INFO
|
|
|
|
);
|
|
|
|
|
2019-12-24 08:31:03 +00:00
|
|
|
let localIp = '';
|
|
|
|
let localMac = '';
|
|
|
|
|
|
|
|
// get network info
|
|
|
|
await this.nativeService
|
|
|
|
.getNetworkInfo()
|
|
|
|
.then(result => {
|
|
|
|
if (!!result && result.length > 0) {
|
|
|
|
if (!!result[0].ip) {
|
|
|
|
localIp = result[0].ip;
|
|
|
|
}
|
|
|
|
if (!!result[0].mac) {
|
|
|
|
localMac = result[0].mac;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(reason => {});
|
|
|
|
|
2019-10-02 05:34:17 +00:00
|
|
|
this.publicApiService
|
|
|
|
.versionInfo2({
|
|
|
|
deviceType: environmentsInfo.deviceType,
|
|
|
|
companyGroupType: loginInfo.companyGroupType,
|
|
|
|
companyCode: loginInfo.companyCode,
|
|
|
|
loginId: loginInfo.loginId
|
|
|
|
})
|
|
|
|
.pipe(
|
|
|
|
take(1),
|
2019-10-04 01:19:55 +00:00
|
|
|
tap(res => {
|
2019-10-15 05:58:11 +00:00
|
|
|
this.sessionStorageService.set<VersionInfo2Response>(
|
|
|
|
KEY_VER_INFO,
|
|
|
|
res
|
|
|
|
);
|
2019-10-04 01:19:55 +00:00
|
|
|
this.store.dispatch(VersionInfoStore.versionInfo2Success({ res }));
|
|
|
|
}),
|
2019-10-02 05:34:17 +00:00
|
|
|
switchMap(res => {
|
2019-10-04 01:19:55 +00:00
|
|
|
return this.protocolService.connect(res.serverIp);
|
2019-10-02 05:34:17 +00:00
|
|
|
}),
|
2019-12-13 07:51:44 +00:00
|
|
|
switchMap(() => {
|
2019-12-13 05:38:42 +00:00
|
|
|
return this.externalApiService
|
|
|
|
.urlInfoDaesang({
|
|
|
|
deviceType: environmentsInfo.deviceType,
|
|
|
|
loginId: loginInfo.loginId
|
|
|
|
})
|
|
|
|
.pipe(
|
|
|
|
map(response => {
|
|
|
|
if (response.statusCode === StatusCode.Success) {
|
|
|
|
this.sessionStorageService.set<
|
|
|
|
UrlInfoResponse | DaesangUrlInfoResponse
|
|
|
|
>(KEY_URL_INFO, response);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(this.logger.error({ error })))
|
|
|
|
);
|
|
|
|
}),
|
2019-10-02 05:34:17 +00:00
|
|
|
switchMap(() => this.innerProtocolService.conn({})),
|
|
|
|
switchMap(res => {
|
2019-11-29 07:08:24 +00:00
|
|
|
return this.authenticationProtocolService
|
|
|
|
.login({
|
|
|
|
loginId: loginInfo.loginId,
|
|
|
|
loginPw: loginInfo.loginPw,
|
|
|
|
deviceType: environmentsInfo.deviceType,
|
|
|
|
deviceId: ' ',
|
|
|
|
token: '',
|
|
|
|
localeCode: loginInfo.localeCode,
|
|
|
|
pushId: ' ',
|
|
|
|
companyCode: loginInfo.companyCode,
|
|
|
|
passwordEncodingType: 1,
|
|
|
|
clientVersion: '',
|
|
|
|
reconnect: false,
|
2019-12-24 08:31:03 +00:00
|
|
|
ip: localIp,
|
|
|
|
hostName: localMac,
|
2019-11-29 07:08:24 +00:00
|
|
|
ssoMode: SSOMode.AUTH,
|
|
|
|
userSpecificInformation: 'PRO_000482',
|
2019-12-24 08:31:03 +00:00
|
|
|
andId: '',
|
|
|
|
andPushRefreshYn: ''
|
2019-11-29 07:08:24 +00:00
|
|
|
})
|
|
|
|
.pipe(
|
|
|
|
catchError(err => {
|
|
|
|
switch (err as ServerErrorCode) {
|
|
|
|
case ServerErrorCode.ERRCD_IDPW:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return throwError(err);
|
|
|
|
})
|
|
|
|
);
|
2019-10-02 05:34:17 +00:00
|
|
|
}),
|
2019-10-04 01:19:55 +00:00
|
|
|
switchMap(res => {
|
|
|
|
loginRes = res;
|
2019-10-11 09:01:39 +00:00
|
|
|
|
|
|
|
this.sessionStorageService.set<LoginResponse>(KEY_LOGIN_RES_INFO, {
|
|
|
|
...loginRes
|
|
|
|
});
|
|
|
|
|
2019-10-04 01:19:55 +00:00
|
|
|
return forkJoin([
|
2019-10-02 05:34:17 +00:00
|
|
|
this.queryProtocolService.auth({
|
|
|
|
deviceType: environmentsInfo.deviceType
|
|
|
|
}),
|
|
|
|
this.optionProtocolService.regView({})
|
2019-10-04 01:19:55 +00:00
|
|
|
]);
|
|
|
|
}),
|
2019-10-02 09:09:39 +00:00
|
|
|
map(([authRes, regViewRes]) => {
|
2019-10-02 05:34:17 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
OptionStore.regViewSuccess({ res: regViewRes })
|
|
|
|
);
|
2020-01-09 05:24:09 +00:00
|
|
|
|
|
|
|
this.sessionStorageService.set<AuthResponse>(KEY_AUTH_INFO, {
|
|
|
|
...authRes
|
|
|
|
});
|
|
|
|
|
2019-10-02 05:34:17 +00:00
|
|
|
this.store.dispatch(QueryStore.authSuccess({ res: authRes }));
|
2019-10-04 01:19:55 +00:00
|
|
|
|
2019-10-07 07:29:38 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
CompanyStore.companyList({
|
2019-11-28 04:44:41 +00:00
|
|
|
companyGroupCode: environment.companyConfig.companyGroupCode
|
2019-10-07 07:29:38 +00:00
|
|
|
})
|
|
|
|
);
|
2019-10-02 05:34:17 +00:00
|
|
|
}),
|
|
|
|
withLatestFrom(
|
|
|
|
this.store.pipe(
|
2019-10-11 02:58:03 +00:00
|
|
|
select(
|
|
|
|
AppStore.MessengerSelector.SyncSelector.selectBuddy2SyncDate
|
|
|
|
)
|
2019-10-02 05:34:17 +00:00
|
|
|
),
|
|
|
|
this.store.pipe(
|
2019-10-11 02:58:03 +00:00
|
|
|
select(
|
|
|
|
AppStore.MessengerSelector.SyncSelector.selectGroup2SyncDate
|
|
|
|
)
|
2019-10-02 09:09:39 +00:00
|
|
|
),
|
|
|
|
this.store.pipe(
|
2019-10-11 02:58:03 +00:00
|
|
|
select(AppStore.MessengerSelector.SyncSelector.selectRoomSyncDate)
|
2019-10-02 05:34:17 +00:00
|
|
|
)
|
|
|
|
),
|
2019-10-02 09:09:39 +00:00
|
|
|
map(([_, buddy2SyncDate, group2SyncDate, roomSyncDate]) => {
|
2019-10-02 05:34:17 +00:00
|
|
|
this.store.dispatch(SyncStore.buddy2({ syncDate: buddy2SyncDate }));
|
|
|
|
this.store.dispatch(SyncStore.group2({ syncDate: group2SyncDate }));
|
2019-10-02 09:09:39 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
SyncStore.room({
|
|
|
|
syncDate: roomSyncDate,
|
|
|
|
localeCode: loginInfo.localeCode
|
|
|
|
})
|
|
|
|
);
|
2019-10-04 04:45:02 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
QueryStore.dept({
|
|
|
|
divCd: 'ORG',
|
|
|
|
companyCode: loginInfo.companyCode
|
|
|
|
})
|
|
|
|
);
|
2019-10-02 05:34:17 +00:00
|
|
|
}),
|
|
|
|
catchError(err => {
|
|
|
|
return throwError(err);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe(
|
|
|
|
() => {
|
|
|
|
this.store.dispatch(
|
|
|
|
AuthenticationStore.loginSuccess({
|
2019-10-04 01:19:55 +00:00
|
|
|
loginRes
|
2019-10-02 05:34:17 +00:00
|
|
|
})
|
|
|
|
);
|
2019-11-28 04:19:19 +00:00
|
|
|
this.store.dispatch(AuthenticationStore.postLogin({ loginRes }));
|
2019-12-12 08:15:09 +00:00
|
|
|
this.appNativeService.subscribeAfterLogin();
|
2019-10-02 05:34:17 +00:00
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
);
|
2019-09-24 09:42:53 +00:00
|
|
|
});
|
2019-09-19 05:15:43 +00:00
|
|
|
}
|
|
|
|
}
|