import { Injectable } from '@angular/core'; import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; import { Observable } from 'rxjs'; import { take, map } from 'rxjs/operators'; 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'; import { AuthenticationProtocolService, SSOMode } from '@ucap-webmessenger/protocol-authentication'; import { LocaleCode } from '@ucap-webmessenger/core'; @Injectable() export class MessengerResolver implements Resolve { constructor( private store: Store, private sessionStorageService: SessionStorageService, private publicApiService: PublicApiService, private protocolService: ProtocolService, private authenticationProtocolService: AuthenticationProtocolService, private innerProtocolService: InnerProtocolService ) {} resolve( route: ActivatedRouteSnapshot, state: RouterStateSnapshot ): void | Observable | Promise { const loginInfo = this.sessionStorageService.get(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( map(connRes => { 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( map(loginRes => { console.log('loginRes', loginRes); }) ) .subscribe(); }) ) .subscribe(); }) .catch(reason => {}); }) ); } }