This commit is contained in:
crusader 2018-03-12 16:37:42 +09:00
parent 18c59571bd
commit eff89ec032
8 changed files with 38 additions and 6 deletions

View File

@ -39,6 +39,7 @@
"d3": "^4.13.0", "d3": "^4.13.0",
"hammerjs": "^2.0.8", "hammerjs": "^2.0.8",
"ng2-odometer": "^1.1.3", "ng2-odometer": "^1.1.3",
"ngx-cookie-service": "^1.0.10",
"ngx-perfect-scrollbar": "^5.3.1", "ngx-perfect-scrollbar": "^5.3.1",
"rxjs": "^5.5.6", "rxjs": "^5.5.6",
"zone.js": "^0.8.20", "zone.js": "^0.8.20",

View File

@ -5,6 +5,8 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { CookieService } from 'ngx-cookie-service';
import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { RPCClient } from 'packages/core/rpc/client/RPCClient';
import { RPCClientCodec } from 'packages/core/rpc/protocol/RPCClientCodec'; import { RPCClientCodec } from 'packages/core/rpc/protocol/RPCClientCodec';
import { RPCClientJSONCodec } from 'packages/core/rpc/protocol/json/RPCClientJSONCodec'; import { RPCClientJSONCodec } from 'packages/core/rpc/protocol/json/RPCClientJSONCodec';
@ -56,6 +58,7 @@ import { RESTService } from './commons/service/rest.service';
{ {
provide: RPCClient, useClass: RPCService provide: RPCClient, useClass: RPCService
}, },
CookieService,
], ],
declarations: [ declarations: [
AppComponent, AppComponent,

View File

@ -14,6 +14,8 @@ import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take'; import 'rxjs/add/operator/take';
import { CookieService } from 'ngx-cookie-service';
import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { RPCClient } from 'packages/core/rpc/client/RPCClient';
import { import {
@ -29,6 +31,7 @@ export class Effects {
constructor( constructor(
private actions$: Actions, private actions$: Actions,
private rpcClient: RPCClient, private rpcClient: RPCClient,
private cookieService: CookieService,
) { } ) { }
@Effect({ dispatch: false }) @Effect({ dispatch: false })
@ -36,7 +39,11 @@ export class Effects {
.ofType(ActionType.SigninSuccess) .ofType(ActionType.SigninSuccess)
.do( .do(
() => { () => {
this.rpcClient.connect(); let queryString: string;
if (this.cookieService.check('AuthToken')) {
queryString = `AuthToken=${this.cookieService.get('AuthToken')}`;
}
this.rpcClient.connect(queryString);
} }
); );

View File

@ -27,8 +27,8 @@ export class RPCClient {
/** /**
* connect * connect
*/ */
public connect(): void { public connect(queryString?: string): void {
this._rwc.connect(); this._rwc.connect(queryString);
this._rwc.readResponse().subscribe( this._rwc.readResponse().subscribe(
(value: Object) => { (value: Object) => {
this.onMessage(value); this.onMessage(value);

View File

@ -3,7 +3,7 @@ import { InjectionToken } from '@angular/core';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
export abstract class RPCClientRWC { export abstract class RPCClientRWC {
public abstract connect(): void; public abstract connect(queryString?: string): void;
public abstract readResponse(): Observable<Object>; public abstract readResponse(): Observable<Object>;
public abstract writeRequest(data: any): void; public abstract writeRequest(data: any): void;
public abstract disconnect(): void; public abstract disconnect(): void;

View File

@ -20,7 +20,10 @@ export class RPCClientWebsocketRWC extends RPCClientRWC {
this._wsSocketSubject = new RxWebsocketSubject<Object>(this._config); this._wsSocketSubject = new RxWebsocketSubject<Object>(this._config);
} }
public connect(): void { public connect(queryString?: string): void {
if (undefined !== queryString) {
this._wsSocketSubject.queryString = queryString;
}
this._wsSocketSubject.connect(); this._wsSocketSubject.connect();
this._wsSocketSubject.subscribe( this._wsSocketSubject.subscribe(
(value: Object) => { (value: Object) => {

View File

@ -24,6 +24,7 @@ export class RxWebsocketSubject<T> extends Subject<T> {
private _socket: WebSocketSubject<any>; private _socket: WebSocketSubject<any>;
private _connectionObserver: Observer<boolean>; private _connectionObserver: Observer<boolean>;
private _connectionStatus: Observable<boolean>; private _connectionStatus: Observable<boolean>;
private _queryString: string;
public constructor(private _config: RxWebsocketSubjectConfig) { public constructor(private _config: RxWebsocketSubjectConfig) {
super(); super();
@ -55,12 +56,25 @@ export class RxWebsocketSubject<T> extends Subject<T> {
}); });
} }
public set queryString(query: string) {
this._queryString = query;
}
public get queryString(): string | undefined {
return this._queryString;
}
public get connectionStatus(): Observable<boolean> { public get connectionStatus(): Observable<boolean> {
return this._connectionStatus; return this._connectionStatus;
} }
public connect(): void { 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( this._socket.subscribe(
(m) => { (m) => {
this.next(m); this.next(m);

View File

@ -4688,6 +4688,10 @@ ng2-odometer@^1.1.3:
dependencies: dependencies:
odometer "^0.4.8" 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: ngx-perfect-scrollbar@^5.3.1:
version "5.3.1" version "5.3.1"
resolved "https://registry.yarnpkg.com/ngx-perfect-scrollbar/-/ngx-perfect-scrollbar-5.3.1.tgz#7fcfb26a93554ac60d0444bfaa4b9487f23c5cbc" resolved "https://registry.yarnpkg.com/ngx-perfect-scrollbar/-/ngx-perfect-scrollbar-5.3.1.tgz#7fcfb26a93554ac60d0444bfaa4b9487f23c5cbc"