From eff89ec032792a03d13bed26aad26e70770166ec Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 12 Mar 2018 16:37:42 +0900 Subject: [PATCH] ing --- package.json | 1 + src/app/app.module.ts | 3 +++ .../store/signin-init/signin-init.effect.ts | 9 ++++++++- src/packages/core/rpc/client/RPCClient.ts | 4 ++-- src/packages/core/rpc/client/rwc/RPCClientRWC.ts | 2 +- .../rwc/websocket/RPCClientWebsocketRWC.ts | 5 ++++- .../core/websocket/RxWebsocketSubject.ts | 16 +++++++++++++++- yarn.lock | 4 ++++ 8 files changed, 38 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6177628..35bc6a5 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "d3": "^4.13.0", "hammerjs": "^2.0.8", "ng2-odometer": "^1.1.3", + "ngx-cookie-service": "^1.0.10", "ngx-perfect-scrollbar": "^5.3.1", "rxjs": "^5.5.6", "zone.js": "^0.8.20", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index df912ab..9fa44c8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,6 +5,8 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { HttpClientModule } from '@angular/common/http'; +import { CookieService } from 'ngx-cookie-service'; + import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { RPCClientCodec } from 'packages/core/rpc/protocol/RPCClientCodec'; import { RPCClientJSONCodec } from 'packages/core/rpc/protocol/json/RPCClientJSONCodec'; @@ -56,6 +58,7 @@ import { RESTService } from './commons/service/rest.service'; { provide: RPCClient, useClass: RPCService }, + CookieService, ], declarations: [ AppComponent, diff --git a/src/app/commons/store/signin-init/signin-init.effect.ts b/src/app/commons/store/signin-init/signin-init.effect.ts index bdc1ab1..1ac07d1 100644 --- a/src/app/commons/store/signin-init/signin-init.effect.ts +++ b/src/app/commons/store/signin-init/signin-init.effect.ts @@ -14,6 +14,8 @@ import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; +import { CookieService } from 'ngx-cookie-service'; + import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { @@ -29,6 +31,7 @@ export class Effects { constructor( private actions$: Actions, private rpcClient: RPCClient, + private cookieService: CookieService, ) { } @Effect({ dispatch: false }) @@ -36,7 +39,11 @@ export class Effects { .ofType(ActionType.SigninSuccess) .do( () => { - this.rpcClient.connect(); + let queryString: string; + if (this.cookieService.check('AuthToken')) { + queryString = `AuthToken=${this.cookieService.get('AuthToken')}`; + } + this.rpcClient.connect(queryString); } ); diff --git a/src/packages/core/rpc/client/RPCClient.ts b/src/packages/core/rpc/client/RPCClient.ts index 1003971..6093355 100644 --- a/src/packages/core/rpc/client/RPCClient.ts +++ b/src/packages/core/rpc/client/RPCClient.ts @@ -27,8 +27,8 @@ export class RPCClient { /** * connect */ - public connect(): void { - this._rwc.connect(); + public connect(queryString?: string): void { + this._rwc.connect(queryString); this._rwc.readResponse().subscribe( (value: Object) => { this.onMessage(value); diff --git a/src/packages/core/rpc/client/rwc/RPCClientRWC.ts b/src/packages/core/rpc/client/rwc/RPCClientRWC.ts index 9b1f2ea..c18eb70 100644 --- a/src/packages/core/rpc/client/rwc/RPCClientRWC.ts +++ b/src/packages/core/rpc/client/rwc/RPCClientRWC.ts @@ -3,7 +3,7 @@ import { InjectionToken } from '@angular/core'; import { Observable } from 'rxjs/Observable'; export abstract class RPCClientRWC { - public abstract connect(): void; + public abstract connect(queryString?: string): void; public abstract readResponse(): Observable; public abstract writeRequest(data: any): void; public abstract disconnect(): void; diff --git a/src/packages/core/rpc/client/rwc/websocket/RPCClientWebsocketRWC.ts b/src/packages/core/rpc/client/rwc/websocket/RPCClientWebsocketRWC.ts index 64b4079..81c5b27 100644 --- a/src/packages/core/rpc/client/rwc/websocket/RPCClientWebsocketRWC.ts +++ b/src/packages/core/rpc/client/rwc/websocket/RPCClientWebsocketRWC.ts @@ -20,7 +20,10 @@ export class RPCClientWebsocketRWC extends RPCClientRWC { this._wsSocketSubject = new RxWebsocketSubject(this._config); } - public connect(): void { + public connect(queryString?: string): void { + if (undefined !== queryString) { + this._wsSocketSubject.queryString = queryString; + } this._wsSocketSubject.connect(); this._wsSocketSubject.subscribe( (value: Object) => { diff --git a/src/packages/core/websocket/RxWebsocketSubject.ts b/src/packages/core/websocket/RxWebsocketSubject.ts index be02808..e0d1e39 100644 --- a/src/packages/core/websocket/RxWebsocketSubject.ts +++ b/src/packages/core/websocket/RxWebsocketSubject.ts @@ -24,6 +24,7 @@ export class RxWebsocketSubject extends Subject { private _socket: WebSocketSubject; private _connectionObserver: Observer; private _connectionStatus: Observable; + private _queryString: string; public constructor(private _config: RxWebsocketSubjectConfig) { super(); @@ -55,12 +56,25 @@ export class RxWebsocketSubject extends Subject { }); } + public set queryString(query: string) { + this._queryString = query; + } + + public get queryString(): string | undefined { + return this._queryString; + } + public get connectionStatus(): Observable { return this._connectionStatus; } public connect(): void { - this._socket = new WebSocketSubject(this._wsSubjectConfig); + const wsSubjectConfig = Object.assign({}, this._wsSubjectConfig); + if (undefined !== this._queryString) { + wsSubjectConfig.url = wsSubjectConfig.url + '?' + this._queryString; + } + + this._socket = new WebSocketSubject(wsSubjectConfig); this._socket.subscribe( (m) => { this.next(m); diff --git a/yarn.lock b/yarn.lock index f805c32..3581a59 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4688,6 +4688,10 @@ ng2-odometer@^1.1.3: dependencies: odometer "^0.4.8" +ngx-cookie-service@^1.0.10: + version "1.0.10" + resolved "https://registry.yarnpkg.com/ngx-cookie-service/-/ngx-cookie-service-1.0.10.tgz#dc17ff4f1a0224cf3b0c7a7f52bff2b798396e3d" + ngx-perfect-scrollbar@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/ngx-perfect-scrollbar/-/ngx-perfect-scrollbar-5.3.1.tgz#7fcfb26a93554ac60d0444bfaa4b9487f23c5cbc"