next-ucap-messenger/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts

66 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-09-19 05:15:43 +00:00
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';
@Injectable()
export class MessengerResolver implements Resolve<void> {
constructor(
private store: Store<any>,
private sessionStorageService: SessionStorageService,
private publicApiService: PublicApiService,
private protocolService: ProtocolService,
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(
take(1),
map(() => {
console.log('innerProtocolService.conn');
})
)
.subscribe();
})
.catch(reason => {});
})
);
}
}