diff --git a/src/app/app-store.module.ts b/src/app/app-store.module.ts index cb05799..3eb054e 100644 --- a/src/app/app-store.module.ts +++ b/src/app/app-store.module.ts @@ -9,10 +9,10 @@ import { import { EffectsModule } from '@ngrx/effects'; import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; +import { SimpleRouterStateSerializer } from 'packages/commons/util/router/state/serializer/simple-router-state-serializer'; import { environment } from '../environments/environment'; - -import { SimpleRouterStateSerializer } from 'packages/commons/util/router/state/serializer/simple-router-state-serializer'; +import { EFFECTS } from './commons/store'; export interface AppState { } @@ -51,7 +51,7 @@ export const reducers: ActionReducerMap = { maxAge: 50, logOnly: environment.production, }), - EffectsModule.forRoot([]), + EffectsModule.forRoot(EFFECTS), ], providers: [ /** diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 596b576..df912ab 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,6 +5,16 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { HttpClientModule } from '@angular/common/http'; +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'; + +import { RPCClientRWC } from 'packages/core/rpc/client/rwc/RPCClientRWC'; +import { RPCClientWebsocketRWC } from 'packages/core/rpc/client/rwc/websocket/RPCClientWebsocketRWC'; +import { RxWebsocketSubjectConfig } from 'packages/core/websocket/RxWebsocketSubject'; + +import { RESTClient } from 'packages/core/rest/client/RESTClient'; + import { AppRoutingModule } from './app-routing.module'; import { AppStoreModule } from './app-store.module'; import { AppL10NModule } from './app-l10n.module'; @@ -15,8 +25,9 @@ import { CovalentModule } from './commons/ui/covalent/covalent.module'; import { AppComponent } from './app.component'; import { environment } from '../environments/environment'; -import { RESTService } from 'packages/commons/service/rest.service'; -import { RPCService } from 'packages/commons/service/rpc.service'; +import { RPCService } from './commons/service/rpc.service'; +import { RESTService } from './commons/service/rest.service'; + @NgModule({ imports: [ @@ -31,8 +42,20 @@ import { RPCService } from 'packages/commons/service/rpc.service'; ], providers: [ {provide: 'REST_BASE_URL', useValue: environment.restBaseURL}, - {provide: 'RPC_BASE_URL', useValue: environment.rpcBaseURL}, - RESTService, RPCService, + {provide: 'WEBAPP_RPC_CONFIG', useValue: environment.webappRPCConfig}, + + {provide: RPCClientCodec, useFactory: () => new RPCClientJSONCodec()}, + { + provide: RPCClientRWC, + useFactory: (config: RxWebsocketSubjectConfig) => new RPCClientWebsocketRWC(config), + deps: ['WEBAPP_RPC_CONFIG'] + }, + { + provide: RESTClient, useClass: RESTService + }, + { + provide: RPCClient, useClass: RPCService + }, ], declarations: [ AppComponent, diff --git a/src/packages/commons/service/rest.service.spec.ts b/src/app/commons/service/rest.service.spec.ts similarity index 100% rename from src/packages/commons/service/rest.service.spec.ts rename to src/app/commons/service/rest.service.spec.ts diff --git a/src/app/commons/service/rest.service.ts b/src/app/commons/service/rest.service.ts new file mode 100644 index 0000000..3ac27e4 --- /dev/null +++ b/src/app/commons/service/rest.service.ts @@ -0,0 +1,26 @@ +import { Injectable, Inject } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; + +import { Observable } from 'rxjs/Observable'; + +import { Location } from '@angular/common'; + +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/timeout'; +import 'rxjs/add/observable/throw'; + +import { RESTClient } from 'packages/core/rest/client/RESTClient'; + +@Injectable() +export class RESTService extends RESTClient { + + constructor( + @Inject('REST_BASE_URL') _baseURL: string, + @Inject(HttpClient) _httpClient: HttpClient, + ) { + super(_baseURL, _httpClient); + } + +} diff --git a/src/packages/commons/service/rpc.service.spec.ts b/src/app/commons/service/rpc.service.spec.ts similarity index 100% rename from src/packages/commons/service/rpc.service.spec.ts rename to src/app/commons/service/rpc.service.spec.ts diff --git a/src/app/commons/service/rpc.service.ts b/src/app/commons/service/rpc.service.ts new file mode 100644 index 0000000..340e23b --- /dev/null +++ b/src/app/commons/service/rpc.service.ts @@ -0,0 +1,19 @@ +import { Injectable, Inject } from '@angular/core'; + +import { Observable } from 'rxjs/Observable'; +import { Subject } from 'rxjs/Subject'; + +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; +import { RPCClientCodec } from 'packages/core/rpc/protocol/RPCClientCodec'; +import { RPCClientRWC } from 'packages/core/rpc/client/rwc/RPCClientRWC'; + + +@Injectable() +export class RPCService extends RPCClient { + constructor( + private _rpcClientCodec: RPCClientCodec, + private _rpcClientRWC: RPCClientRWC, + ) { + super(_rpcClientCodec, _rpcClientRWC); + } +} diff --git a/src/app/commons/store/index.ts b/src/app/commons/store/index.ts new file mode 100644 index 0000000..b5f3921 --- /dev/null +++ b/src/app/commons/store/index.ts @@ -0,0 +1,5 @@ +import * as SigninInitStore from './signin-init'; + +export const EFFECTS = [ + SigninInitStore.Effects, +]; diff --git a/src/app/commons/store/signin-init/index.ts b/src/app/commons/store/signin-init/index.ts new file mode 100644 index 0000000..3ac331f --- /dev/null +++ b/src/app/commons/store/signin-init/index.ts @@ -0,0 +1 @@ +export * from './signin-init.effect'; diff --git a/src/app/commons/store/signin-init/signin-init.effect.spec.ts b/src/app/commons/store/signin-init/signin-init.effect.spec.ts new file mode 100644 index 0000000..6214021 --- /dev/null +++ b/src/app/commons/store/signin-init/signin-init.effect.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { Effects } from './signin-init.effect'; + +describe('SigninInit.Effects', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [Effects] + }); + }); + + it('should be created', inject([Effects], (effects: Effects) => { + expect(effects).toBeTruthy(); + })); +}); diff --git a/src/app/commons/store/signin-init/signin-init.effect.ts b/src/app/commons/store/signin-init/signin-init.effect.ts new file mode 100644 index 0000000..bdc1ab1 --- /dev/null +++ b/src/app/commons/store/signin-init/signin-init.effect.ts @@ -0,0 +1,43 @@ +import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Effect, Actions, ofType } from '@ngrx/effects'; +import { Action } from '@ngrx/store'; + +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; + +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/exhaustMap'; +import 'rxjs/add/operator/switchMap'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/take'; + +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; + +import { + Signin, + SigninSuccess, + SigninFailure, + ActionType, +} from 'packages/member/store/auth'; + +@Injectable() +export class Effects { + + constructor( + private actions$: Actions, + private rpcClient: RPCClient, + ) { } + + @Effect({ dispatch: false }) + signinSuccess$ = this.actions$ + .ofType(ActionType.SigninSuccess) + .do( + () => { + this.rpcClient.connect(); + } + ); + +} diff --git a/src/app/core/rx/websocket/rx-websocket-subject.ts b/src/app/core/rx/websocket/rx-websocket-subject.ts index 0ee3bfb..3f3cd23 100644 --- a/src/app/core/rx/websocket/rx-websocket-subject.ts +++ b/src/app/core/rx/websocket/rx-websocket-subject.ts @@ -17,10 +17,10 @@ export interface Codec { } export const defaultCodec: Codec = { - encode: (e: MessageEvent) => { + decode: (e: MessageEvent) => { return JSON.parse(e.data); }, - decode: (data: any): string => { + encode: (data: any): string => { return JSON.stringify(data); } }; @@ -59,7 +59,7 @@ export class RxWebsocketSubject extends Subject { this.connectionObserver.next(true); } }, - resultSelector: this.codec.decode, + // resultSelector: this.codec.decode, }; this._connectionStatus.subscribe((isConnected: boolean) => { @@ -116,6 +116,7 @@ export class RxWebsocketSubject extends Subject { } public send(data: any): void { + const s = this.codec.encode(data); this.socket.next(this.codec.encode(data)); } } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index cab1394..b7b44d5 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -6,8 +6,13 @@ export const environment = { production: false, restBaseURL: 'http://192.168.1.101:19080', - rpcBaseURL: 'ws://192.168.1.101/webapp', + webappRPCConfig: { + url: 'ws://192.168.1.101:19090/webapp', + reconnectInterval: 5000, + reconnectRetry: 10, + }, }; + export const palete = { primary: '#D32F2F', accent: '#E65100', diff --git a/src/packages/commons/service/error-response.ts b/src/packages/commons/service/error-response.ts deleted file mode 100644 index 0692c76..0000000 --- a/src/packages/commons/service/error-response.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { HttpErrorResponse } from '@angular/common/http'; - -export class ErrorResponse { - - private constructor( - private _code: number, - private _exception: string, - private _message: string, - ) { - } - - public get code(): number { - return this._code; - } - public get exception(): string { - return this._exception; - } - public get message(): string { - return this._message; - } - - public static restError(errorResponse: HttpErrorResponse): ErrorResponse { - const aryMsg = errorResponse.error.message.split('|'); - const resError: ErrorResponse = new ErrorResponse( - errorResponse.error.code, - aryMsg[0], - aryMsg[1] === 'null' ? '' : aryMsg[1], - ); - return resError; - } -} - diff --git a/src/packages/commons/service/rest.service.ts b/src/packages/commons/service/rest.service.ts deleted file mode 100644 index 251d54b..0000000 --- a/src/packages/commons/service/rest.service.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { Injectable, Inject } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; - -import { Observable } from 'rxjs/Observable'; - -import { Location } from '@angular/common'; - -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/map'; -import 'rxjs/add/operator/catch'; -import 'rxjs/add/operator/timeout'; -import 'rxjs/add/observable/throw'; - -import { ErrorResponse } from './error-response'; - -@Injectable() -export class RESTService { - private readonly httpHeaders: HttpHeaders; - - constructor( - @Inject('REST_BASE_URL') private _baseURL: string, - @Inject(HttpClient) private _httpClient: HttpClient, - ) { - this.httpHeaders = new HttpHeaders() - .set('Content-Type', 'application/json'); - } - - public get httpClient(): HttpClient { - return this._httpClient; - } - - public get(entry: string, params?: {[param: string]: string | string[]}): Observable { - const headers: HttpHeaders = this.httpHeaders; - - return this._httpClient - .get(Location.joinWithSlash(this._baseURL, entry), { - headers: headers, - params: params, - responseType: 'json', - }) - .map((response: string) => JSON.parse(response)) - .catch((error: HttpErrorResponse) => Observable.throw(ErrorResponse.restError(error))); - } - - public post(entry: string, body: any | null, params?: {[param: string]: string | string[]}): Observable { - const headers: HttpHeaders = this.httpHeaders; - - return this._httpClient - .post(Location.joinWithSlash(this._baseURL, entry), body, { - headers: headers, - params: params, - responseType: 'json', - }) - .map((response: string) => JSON.parse(response)) - .catch((error: HttpErrorResponse) => Observable.throw(ErrorResponse.restError(error))); - } - -} diff --git a/src/packages/commons/service/rpc.service.ts b/src/packages/commons/service/rpc.service.ts deleted file mode 100644 index a72c435..0000000 --- a/src/packages/commons/service/rpc.service.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { Injectable, Inject } from '@angular/core'; -import { Observable } from 'rxjs/Observable'; - -import { RxWebsocketSubject } from 'app/core/rx/websocket/rx-websocket-subject'; -import { RPCRegistry } from 'app/core/rpc/registry/rpc-registry'; - - -@Injectable() -export class RPCService { - private wsSocketSubject: RxWebsocketSubject; - private rpcRegistry: RPCRegistry; - - constructor( - @Inject('RPC_BASE_URL') private _baseURL: string, - ) { - this.wsSocketSubject = new RxWebsocketSubject(this._baseURL); - } - - public connect(): void { - this.wsSocketSubject.connect(); - this.wsSocketSubject.subscribe( - (value: Object) => { - this.onMessage(value); - }, - (error: any) => { - this.onError(error); - }, - () => { - this.onDisconnected(); - } - ); - } - - public call(method: string, ...args: any[]): Observable { - return undefined; - } - - public callTimeout(method: string, ...args: any[]): Observable { - return undefined; - } - - public send(method: string, ...args: any[]): void { - - } - - private sendInternal(data: Object): void { - this.wsSocketSubject.next(data); - } - - public getConnectionStatus(): Observable { - return this.wsSocketSubject.connectionStatus; - } - - private onMessage(message: Object): void { - // - console.log(message); - } - - private onError(error: any): void { - // - console.log(error); - } - - private onDisconnected(): void { - // - console.log('disconnected'); - } -} diff --git a/src/packages/core/rest/client/RESTClient.ts b/src/packages/core/rest/client/RESTClient.ts new file mode 100644 index 0000000..ee84246 --- /dev/null +++ b/src/packages/core/rest/client/RESTClient.ts @@ -0,0 +1,57 @@ +import { Injectable, Inject } from '@angular/core'; +import { Location } from '@angular/common'; +import { HttpClient, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http'; + +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/timeout'; +import 'rxjs/add/observable/throw'; + +import { RESTError } from '../error'; + +export class RESTClient { + private readonly httpHeaders: HttpHeaders; + + constructor( + private _baseURL: string, + private _httpClient: HttpClient, + ) { + this.httpHeaders = new HttpHeaders() + .set('Content-Type', 'application/json'); + } + + public get httpClient(): HttpClient { + return this._httpClient; + } + + public request(method: string, entry: string, options?: { + body?: any; + headers?: HttpHeaders | { + [header: string]: string | string[]; + }; + observe?: 'body'; + params?: HttpParams | { + [param: string]: string | string[]; + }; + responseType?: 'json'; + reportProgress?: boolean; + withCredentials?: boolean; + }): Observable { + const headers: HttpHeaders = this.httpHeaders; + + return this._httpClient + .request(method, Location.joinWithSlash(this._baseURL, entry), options) + .map((response: string) => JSON.parse(response)) + .catch((error: HttpErrorResponse) => { + const aryMsg = error.error.message.split('|'); + const resError: RESTError = { + code: error.error.code, + message: aryMsg[0], + data: aryMsg[1] === 'null' ? '' : aryMsg[1], + }; + return Observable.throw(resError); + }); + } +} diff --git a/src/packages/core/rest/error.ts b/src/packages/core/rest/error.ts new file mode 100644 index 0000000..e5942ff --- /dev/null +++ b/src/packages/core/rest/error.ts @@ -0,0 +1,5 @@ +export interface RESTError { + code: number; + message: string; + data?: any; +} diff --git a/src/packages/core/rpc/client/RPCClient.ts b/src/packages/core/rpc/client/RPCClient.ts new file mode 100644 index 0000000..1003971 --- /dev/null +++ b/src/packages/core/rpc/client/RPCClient.ts @@ -0,0 +1,113 @@ +import { Observable } from 'rxjs/Observable'; +import { Subject } from 'rxjs/Subject'; + +import { RPCClientRWC } from './rwc/RPCClientRWC'; +import { RPCRegistry } from './../registry/RPCRegistry'; +import { RPCClientCodec, RPCClientResponseCodec } from '../protocol/RPCClientCodec'; + +export class RPCClient { + private _requestID: number; + + private _pendingRequestsCount: number; + private _pendingRequests: Map>; + + public constructor( + private _codec: RPCClientCodec, + private _rwc: RPCClientRWC, + ) { + this._requestID = 0; + this._pendingRequestsCount = 0; + this._pendingRequests = new Map(); + } + + private getRequestID(): number { + return ++this._requestID; + } + + /** + * connect + */ + public connect(): void { + this._rwc.connect(); + this._rwc.readResponse().subscribe( + (value: Object) => { + this.onMessage(value); + }, + (error: any) => { + }, + () => { + + } + ); + } + + /** + * close + */ + public disconnect() { + this._rwc.disconnect(); + } + + /** + * notify + */ + public notify(method: string, ...args: any[]): void { + this.send(false, method, args); + } + + /** + * call + */ + public call(method: string, ...args: any[]): Observable { + return this.send(true, method, args); + } + + /** + * callTimeout + */ + public callTimeout(ms: number, method: string, ...args: any[]): Observable { + + return undefined; + } + + private send(hasResponse: boolean, method: string, args?: any[]): Observable | undefined { + let id: number; + let resSubject: Subject; + if (hasResponse) { + id = this.getRequestID(); + resSubject = new Subject(); + this._pendingRequests.set(id, resSubject); + this._pendingRequestsCount++; + } + + const req = this._codec.request(method, args, id); + this._rwc.writeRequest(req); + + if (undefined !== resSubject) { + return resSubject.asObservable(); + } + } + + private onMessage(message: Object): void { + const resCodec = this._codec.response(message); + if (undefined !== resCodec.id()) { + this.onResponse(resCodec); + } + } + + protected onResponse(resCodec: RPCClientResponseCodec): void { + const id = resCodec.id(); + const result = resCodec.result(); + const error = resCodec.error(); + + const resSubject: Subject = this._pendingRequests.get(id); + this._pendingRequests.delete(id); + this._pendingRequestsCount--; + + if (undefined !== result) { + resSubject.next(result); + } else if (undefined !== error) { + resSubject.error(error); + } + } +} diff --git a/src/packages/core/rpc/client/rwc/RPCClientRWC.ts b/src/packages/core/rpc/client/rwc/RPCClientRWC.ts new file mode 100644 index 0000000..9b1f2ea --- /dev/null +++ b/src/packages/core/rpc/client/rwc/RPCClientRWC.ts @@ -0,0 +1,11 @@ +import { InjectionToken } from '@angular/core'; + +import { Observable } from 'rxjs/Observable'; + +export abstract class RPCClientRWC { + public abstract connect(): void; + public abstract readResponse(): Observable; + public abstract writeRequest(data: any): void; + public abstract disconnect(): void; + public abstract connectionStatus(): Observable; +} diff --git a/src/packages/core/rpc/client/rwc/websocket/RPCClientWebsocketRWC.ts b/src/packages/core/rpc/client/rwc/websocket/RPCClientWebsocketRWC.ts new file mode 100644 index 0000000..64b4079 --- /dev/null +++ b/src/packages/core/rpc/client/rwc/websocket/RPCClientWebsocketRWC.ts @@ -0,0 +1,59 @@ +import { Observable } from 'rxjs/Observable'; +import { Subject } from 'rxjs/Subject'; +import { map } from 'rxjs/operator/map'; + +import { + RxWebsocketSubject, + RxWebsocketSubjectConfig, +} from 'packages/core/websocket/RxWebsocketSubject'; + +import { RPCClientRWC } from '../RPCClientRWC'; + +export class RPCClientWebsocketRWC extends RPCClientRWC { + private _wsSocketSubject: RxWebsocketSubject; + private _responseSubject: Subject; + + public constructor( + private _config: RxWebsocketSubjectConfig, + ) { + super(); + this._wsSocketSubject = new RxWebsocketSubject(this._config); + } + + public connect(): void { + this._wsSocketSubject.connect(); + this._wsSocketSubject.subscribe( + (value: Object) => { + if (undefined !== this._responseSubject) { + this._responseSubject.next(value); + } + }, + (error: any) => { + if (undefined !== this._responseSubject) { + this._responseSubject.error(error); + } + }, + () => { + } + ); + } + + public disconnect(): void { + this._wsSocketSubject.disconnect(); + } + + public connectionStatus(): Observable { + return this._wsSocketSubject.connectionStatus; + } + + public readResponse(): Observable { + if (undefined === this._responseSubject) { + this._responseSubject = new Subject(); + } + return this._responseSubject.asObservable(); + } + + public writeRequest(data: any): void { + this._wsSocketSubject.write(data); + } +} diff --git a/src/packages/core/rpc/error.ts b/src/packages/core/rpc/error.ts new file mode 100644 index 0000000..7d657bb --- /dev/null +++ b/src/packages/core/rpc/error.ts @@ -0,0 +1,33 @@ +/** + * Error object representation when a method invocation fails. + */ +export interface RPCError { + /** Indicates the error type that occurred. */ + code: ErrorCode; + + /** A short description of the error. */ + message: string; + + /** Additional information about the error */ + data?: any; +}/* + +/** Error codes are same as xml-rpc codes. See http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php */ +export const enum ErrorCode { + /** Parse error Invalid JSON was received by the Server. */ + ParseError = -32700, + + /** Invalid Request The JSON sent is not a valid Request object. */ + InvalidRequest = -32600, + + /** The method does not exist / is not available. */ + MethodNotFound = -32601, + + /** Invalid method parameter(s). */ + InvalidParams = - -32602, + + /** Internal JSON-RPC error. */ + InternalError = -32603 + + /** -32000 to -32099: Reserved for implementation-defined Server errors. */ +} diff --git a/src/packages/core/rpc/protocol/RPCClientCodec.ts b/src/packages/core/rpc/protocol/RPCClientCodec.ts new file mode 100644 index 0000000..61ace58 --- /dev/null +++ b/src/packages/core/rpc/protocol/RPCClientCodec.ts @@ -0,0 +1,12 @@ +import { RPCError } from '../error'; + +export abstract class RPCClientCodec { + abstract request(method: string, args: any[], id: number): any; + abstract response(res: any): RPCClientResponseCodec; +} + +export abstract class RPCClientResponseCodec { + abstract id(): number | undefined; + abstract error(): RPCError | undefined; + abstract result(): any | undefined; +} diff --git a/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts b/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts new file mode 100644 index 0000000..5d8f4a7 --- /dev/null +++ b/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts @@ -0,0 +1,59 @@ +import { + RPCClientCodec, + RPCClientResponseCodec, +} from '../RPCClientCodec'; + +import { + RPCError, +} from '../../error'; + +export interface ClientRequest { + jsonrpc: string; + method: string; + params?: any[]; + id?: number; +} + +export interface ClientResponse { + jsonrpc: string; + result?: any; + error?: RPCError; + id?: number; +} + +export class RPCClientJSONCodec extends RPCClientCodec { + public request(method: string, args: any[], id?: number): any { + const req: ClientRequest = { + jsonrpc: '2.0', + method: method, + params: args, + id: id, + }; + return JSON.stringify(req); + } + public response(res: any): RPCClientResponseCodec { + const _res: ClientResponse = { + id: res.id, + jsonrpc: res.jsonrpc, + result: undefined !== res.result ? JSON.parse(res.result) : undefined, + error: undefined !== res.error ? JSON.parse(res.error) : undefined, + }; + return new RPCClientJSONResponseCodec(_res); + } +} + +export class RPCClientJSONResponseCodec extends RPCClientResponseCodec { + public constructor(private _res: ClientResponse) { + super(); + } + + public id(): number | undefined { + return this._res.id; + } + public error(): RPCError | undefined { + return this._res.error; + } + public result(): any | undefined { + return this._res.result; + } +} diff --git a/src/packages/core/rpc/registry/RPCInvoker.ts b/src/packages/core/rpc/registry/RPCInvoker.ts new file mode 100644 index 0000000..aadf8e2 --- /dev/null +++ b/src/packages/core/rpc/registry/RPCInvoker.ts @@ -0,0 +1,17 @@ + +export class RPCInvoker { + + /** + * hasMethod + */ + public hasMethod(method: string): boolean { + return false; + } + + /** + * invoke + */ + public invoke() { + + } +} diff --git a/src/packages/core/rpc/registry/RPCRegistry.ts b/src/packages/core/rpc/registry/RPCRegistry.ts new file mode 100644 index 0000000..074572b --- /dev/null +++ b/src/packages/core/rpc/registry/RPCRegistry.ts @@ -0,0 +1,18 @@ +import { RPCInvoker } from './RPCInvoker'; + +export class RPCRegistry extends RPCInvoker { + + /** + * registerService + */ + public registerService(receiver: T, name: string) { + + } + + /** + * getService + */ + public getService(name: string): T { + return undefined; + } +} diff --git a/src/packages/core/websocket/RxWebsocketSubject.ts b/src/packages/core/websocket/RxWebsocketSubject.ts new file mode 100644 index 0000000..be02808 --- /dev/null +++ b/src/packages/core/websocket/RxWebsocketSubject.ts @@ -0,0 +1,103 @@ +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; +import { Subject } from 'rxjs/Subject'; +import { + WebSocketSubject, + WebSocketSubjectConfig +} from 'rxjs/observable/dom/WebSocketSubject'; + +import 'rxjs/add/operator/distinctUntilChanged'; +import 'rxjs/add/operator/share'; +import 'rxjs/add/operator/takeWhile'; +import 'rxjs/add/observable/interval'; + +export interface RxWebsocketSubjectConfig { + url: string; + protocol?: string | Array; + reconnectInterval?: 5000; + reconnectRetry?: 10; +} + +export class RxWebsocketSubject extends Subject { + private _reconnectionObservable: Observable; + private _wsSubjectConfig: WebSocketSubjectConfig; + private _socket: WebSocketSubject; + private _connectionObserver: Observer; + private _connectionStatus: Observable; + + public constructor(private _config: RxWebsocketSubjectConfig) { + super(); + + this._connectionStatus = new Observable((observer) => { + this._connectionObserver = observer; + }).share().distinctUntilChanged(); + + this._wsSubjectConfig = { + url: _config.url, + protocol: _config.protocol, + closeObserver: { + next: (e: CloseEvent) => { + this._socket = null; + this._connectionObserver.next(false); + } + }, + openObserver: { + next: (e: Event) => { + this._connectionObserver.next(true); + } + }, + }; + + this._connectionStatus.subscribe((isConnected: boolean) => { + if (!this._reconnectionObservable && typeof(isConnected) === 'boolean' && !isConnected) { + this.reconnect(); + } + }); + } + + public get connectionStatus(): Observable { + return this._connectionStatus; + } + + public connect(): void { + this._socket = new WebSocketSubject(this._wsSubjectConfig); + this._socket.subscribe( + (m) => { + this.next(m); + }, + (error: Event) => { + if (!this._socket) { + this.reconnect(); + } + } + ); + } + + public disconnect(): void { + this._socket.complete(); + } + + private reconnect(): void { + this._reconnectionObservable = Observable.interval(this._config.reconnectInterval) + .takeWhile((v, index) => { + return index < this._config.reconnectRetry && !this._socket; + }); + this._reconnectionObservable.subscribe( + () => { + this.connect(); + }, + null, + () => { + this._reconnectionObservable = null; + if (!this._socket) { + this.complete(); + this._connectionObserver.complete(); + } + } + ); + } + + public write(data: any): void { + this._socket.next(data); + } +} diff --git a/src/packages/discovery/service/discovery.service.ts b/src/packages/discovery/service/discovery.service.ts index 5efb335..a38f384 100644 --- a/src/packages/discovery/service/discovery.service.ts +++ b/src/packages/discovery/service/discovery.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; -import { RESTService } from 'packages/commons/service/rest.service'; +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { DiscoveryStartInfo } from '../model'; @@ -11,7 +11,7 @@ import { DiscoveryStartInfo } from '../model'; export class DiscoveryService { public constructor( - private restService: RESTService, + private rpcClient: RPCClient, ) { } @@ -22,7 +22,7 @@ export class DiscoveryService { // signinPw: password, // }; - return this.restService.post('/discovery/start', dsInfo); + return this.rpcClient.call('DiscoveryService.start', dsInfo); } // public signup(member: DiscoveryStartInfo): Observable { diff --git a/src/packages/discovery/store/setting/setting.action.ts b/src/packages/discovery/store/setting/setting.action.ts index 83c4d19..6ad8772 100644 --- a/src/packages/discovery/store/setting/setting.action.ts +++ b/src/packages/discovery/store/setting/setting.action.ts @@ -1,6 +1,6 @@ import { Action } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { DiscoveryStartInfo } from '../../model'; @@ -26,7 +26,7 @@ export class SettingSuccess implements Action { export class SettingFailure implements Action { readonly type = ActionType.SettingFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RPCError) {} } export class SettingRedirect implements Action { diff --git a/src/packages/discovery/store/setting/setting.effect.ts b/src/packages/discovery/store/setting/setting.effect.ts index 508b5d7..cf69b27 100644 --- a/src/packages/discovery/store/setting/setting.effect.ts +++ b/src/packages/discovery/store/setting/setting.effect.ts @@ -14,7 +14,7 @@ import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { DiscoveryStartInfo } from '../../model'; import { DiscoveryService } from '../../service/discovery.service'; @@ -43,7 +43,7 @@ export class Effects { .map(discoveryStartInfo => { return new SettingSuccess(discoveryStartInfo); }) - .catch((error: ErrorResponse) => { + .catch((error: RPCError) => { return of(new SettingFailure(error)); }); diff --git a/src/packages/discovery/store/setting/setting.reducer.ts b/src/packages/discovery/store/setting/setting.reducer.ts index bc9b9ad..3ff133b 100644 --- a/src/packages/discovery/store/setting/setting.reducer.ts +++ b/src/packages/discovery/store/setting/setting.reducer.ts @@ -1,4 +1,4 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Actions, diff --git a/src/packages/discovery/store/setting/setting.state.ts b/src/packages/discovery/store/setting/setting.state.ts index 6f2af78..3749f5f 100644 --- a/src/packages/discovery/store/setting/setting.state.ts +++ b/src/packages/discovery/store/setting/setting.state.ts @@ -1,10 +1,10 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { DiscoveryStartInfo } from '../../model'; export interface State { isStart: boolean; - error: ErrorResponse | null; + error: RPCError | null; isPending: boolean; discoveryStartInfo: DiscoveryStartInfo | null; } diff --git a/src/packages/infra/service/infra.service.ts b/src/packages/infra/service/infra.service.ts index a5e2e41..eaa30cb 100644 --- a/src/packages/infra/service/infra.service.ts +++ b/src/packages/infra/service/infra.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; -import { RESTService } from 'packages/commons/service/rest.service'; +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { Infra } from '../model'; import { Page } from '../../../app/commons/model'; @@ -14,16 +14,16 @@ import { Probe } from '../../probe/model'; export class InfraService { public constructor( - private restService: RESTService, + private rpcClient: RPCClient, ) { } public readByDomain(domain: Domain): Observable { - return this.restService.post('/account/signin', domain); + return this.rpcClient.call('InfraService.', domain); } public readByProbe(probe: Probe): Observable { - return this.restService.post('/account/signup', probe); + return this.rpcClient.call('InfraService.', probe); } } diff --git a/src/packages/infra/store/readbydomain/readbydomain.action.ts b/src/packages/infra/store/readbydomain/readbydomain.action.ts index cedaf0a..dd39c71 100644 --- a/src/packages/infra/store/readbydomain/readbydomain.action.ts +++ b/src/packages/infra/store/readbydomain/readbydomain.action.ts @@ -1,6 +1,6 @@ import { Action } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Infra } from '../../model'; import { Page } from '../../../../app/commons/model'; @@ -26,7 +26,7 @@ export class ReadbydomainSuccess implements Action { export class ReadbydomainFailure implements Action { readonly type = ActionType.ReadbydomainFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RPCError) {} } export type Actions = diff --git a/src/packages/infra/store/readbydomain/readbydomain.effect.ts b/src/packages/infra/store/readbydomain/readbydomain.effect.ts index fcb3481..fd53cf4 100644 --- a/src/packages/infra/store/readbydomain/readbydomain.effect.ts +++ b/src/packages/infra/store/readbydomain/readbydomain.effect.ts @@ -13,7 +13,7 @@ import 'rxjs/add/operator/exhaustMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Infra } from '../../model'; import { InfraService } from '../../service/infra.service'; diff --git a/src/packages/infra/store/readbydomain/readbydomain.state.ts b/src/packages/infra/store/readbydomain/readbydomain.state.ts index 0ad4056..4d0c084 100644 --- a/src/packages/infra/store/readbydomain/readbydomain.state.ts +++ b/src/packages/infra/store/readbydomain/readbydomain.state.ts @@ -3,13 +3,14 @@ import { MemoizedSelector, } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; + import { Infra } from '../../model'; import { Page } from '../../../../app/commons/model'; export interface State { isSignin: boolean; - error: ErrorResponse | null; + error: RPCError | null; isPending: boolean; infraList: Page | null; } diff --git a/src/packages/member/component/signin/signin.component.ts b/src/packages/member/component/signin/signin.component.ts index 4ac23a2..02816fe 100644 --- a/src/packages/member/component/signin/signin.component.ts +++ b/src/packages/member/component/signin/signin.component.ts @@ -3,8 +3,6 @@ import { Router } from '@angular/router'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; import { Store, select } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; - import * as AuthStore from '../../store/auth'; import { AuthSelector } from '../../store'; @@ -55,14 +53,14 @@ export class SigninComponent implements OnInit { initForm() { this.signinForm = this.formBuilder.group({ 'email': [ - '', + 'overflow@loafle.com', [ Validators.required, Validators.email ] ], 'password': [ - '', + '!@#$qwer1234', [ Validators.pattern('^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$'), Validators.minLength(6), diff --git a/src/packages/member/service/member.service.ts b/src/packages/member/service/member.service.ts index c2f38af..f44552d 100644 --- a/src/packages/member/service/member.service.ts +++ b/src/packages/member/service/member.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; -import { RESTService } from 'packages/commons/service/rest.service'; +import { RESTClient } from 'packages/core/rest/client/RESTClient'; import { DomainMember } from 'packages/domain/model'; import { Member } from '../model'; @@ -12,7 +12,7 @@ import { Member } from '../model'; export class MemberService { public constructor( - private restService: RESTService, + private restClient: RESTClient, ) { } @@ -23,10 +23,14 @@ export class MemberService { signinPw: password, }; - return this.restService.post('/account/signin', body); + return this.restClient.request('post', '/account/signin', { + body: body, + }); } public signup(member: Member): Observable { - return this.restService.post('/account/signup', member); + return this.restClient.request('post', '/account/signup', { + body: member, + }); } } diff --git a/src/packages/member/store/auth/auth.action.ts b/src/packages/member/store/auth/auth.action.ts index 8e5d61e..63f0508 100644 --- a/src/packages/member/store/auth/auth.action.ts +++ b/src/packages/member/store/auth/auth.action.ts @@ -1,6 +1,6 @@ import { Action } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RESTError } from 'packages/core/rest/error'; import { DomainMember } from 'packages/domain/model'; import { Member } from '../../model'; @@ -30,7 +30,7 @@ export class SigninSuccess implements Action { export class SigninFailure implements Action { readonly type = ActionType.SigninFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RESTError) {} } export class SigninRedirect implements Action { @@ -48,7 +48,7 @@ export class SignoutSuccess implements Action { export class SignoutFailure implements Action { readonly type = ActionType.SignoutFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RESTError) {} } export type Actions = diff --git a/src/packages/member/store/auth/auth.effect.ts b/src/packages/member/store/auth/auth.effect.ts index e7063ac..2575bfe 100644 --- a/src/packages/member/store/auth/auth.effect.ts +++ b/src/packages/member/store/auth/auth.effect.ts @@ -14,7 +14,7 @@ import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RESTError } from 'packages/core/rest/error'; import { DomainMember } from 'packages/domain/model'; @@ -45,7 +45,7 @@ export class Effects { .map((domainMember: DomainMember) => { return new SigninSuccess(domainMember); }) - .catch((error: ErrorResponse) => { + .catch((error: RESTError) => { return of(new SigninFailure(error)); }); diff --git a/src/packages/member/store/auth/auth.reducer.ts b/src/packages/member/store/auth/auth.reducer.ts index a590ba4..618522c 100644 --- a/src/packages/member/store/auth/auth.reducer.ts +++ b/src/packages/member/store/auth/auth.reducer.ts @@ -1,5 +1,3 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; - import { Actions, ActionType, diff --git a/src/packages/member/store/auth/auth.state.ts b/src/packages/member/store/auth/auth.state.ts index 2c13e17..29c19c4 100644 --- a/src/packages/member/store/auth/auth.state.ts +++ b/src/packages/member/store/auth/auth.state.ts @@ -1,10 +1,10 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RESTError } from 'packages/core/rest/error'; import { Domain } from 'packages/domain/model'; import { Member } from '../../model'; export interface State { signined: boolean; - error: ErrorResponse | null; + error: RESTError | null; pending: boolean; member: Member | null; domain: Domain | null; diff --git a/src/packages/member/store/signup/signup.action.ts b/src/packages/member/store/signup/signup.action.ts index b599c78..be749bb 100644 --- a/src/packages/member/store/signup/signup.action.ts +++ b/src/packages/member/store/signup/signup.action.ts @@ -1,6 +1,6 @@ import { Action } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RESTError } from 'packages/core/rest/error'; import { Member } from '../../model'; @@ -25,7 +25,7 @@ export class SignupSuccess implements Action { export class SignupFailure implements Action { readonly type = ActionType.SignupFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RESTError) {} } export type Actions = diff --git a/src/packages/member/store/signup/signup.effect.ts b/src/packages/member/store/signup/signup.effect.ts index 0a5e918..38bb465 100644 --- a/src/packages/member/store/signup/signup.effect.ts +++ b/src/packages/member/store/signup/signup.effect.ts @@ -13,7 +13,7 @@ import 'rxjs/add/operator/exhaustMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RESTError } from 'packages/core/rest/error'; import { Member } from '../../model'; import { MemberService } from '../../service/member.service'; diff --git a/src/packages/member/store/signup/signup.state.ts b/src/packages/member/store/signup/signup.state.ts index f0ef9f0..f071de4 100644 --- a/src/packages/member/store/signup/signup.state.ts +++ b/src/packages/member/store/signup/signup.state.ts @@ -1,9 +1,9 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RESTError } from 'packages/core/rest/error'; import { Member } from '../../model'; export interface State { - error: ErrorResponse | null; + error: RESTError | null; pending: boolean; member: Member | null; } diff --git a/src/packages/meta/service/crawler.service.ts b/src/packages/meta/service/crawler.service.ts index 560fbc4..877b199 100644 --- a/src/packages/meta/service/crawler.service.ts +++ b/src/packages/meta/service/crawler.service.ts @@ -3,8 +3,7 @@ import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; -import { RESTService } from 'packages/commons/service/rest.service'; - +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { MetaCrawler } from '../model'; @@ -12,7 +11,7 @@ import { MetaCrawler } from '../model'; export class CrawlerService { public constructor( - private restService: RESTService, + private rpcClient: RPCClient, ) { } @@ -23,10 +22,10 @@ export class CrawlerService { signinPw: password, }; - return this.restService.post('/account/signin', body); + return this.rpcClient.call('CrawlerService.', body); } public readAll(): Observable { - return this.restService.post('/account/signup', null); + return this.rpcClient.call('CrawlerService.'); } } diff --git a/src/packages/meta/store/crawler-readall/readall.action.ts b/src/packages/meta/store/crawler-readall/readall.action.ts index c647f86..e90a6a6 100644 --- a/src/packages/meta/store/crawler-readall/readall.action.ts +++ b/src/packages/meta/store/crawler-readall/readall.action.ts @@ -1,6 +1,6 @@ import { Action } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { MetaCrawler } from '../../model'; @@ -26,7 +26,7 @@ export class ReadAllSuccess implements Action { export class ReadAllFailure implements Action { readonly type = ActionType.ReadAllFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RPCError) {} } export type Actions = diff --git a/src/packages/meta/store/crawler-readall/readall.effect.ts b/src/packages/meta/store/crawler-readall/readall.effect.ts index 223df1f..e63d00c 100644 --- a/src/packages/meta/store/crawler-readall/readall.effect.ts +++ b/src/packages/meta/store/crawler-readall/readall.effect.ts @@ -14,7 +14,7 @@ import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { DomainMember } from 'packages/domain/model'; @@ -45,7 +45,7 @@ export class Effects { .map((metaCrawlerList: MetaCrawler[]) => { return new ReadAllSuccess(metaCrawlerList); }) - .catch((error: ErrorResponse) => { + .catch((error: RPCError) => { return of(new ReadAllFailure(error)); }); diff --git a/src/packages/meta/store/crawler-readall/readall.reducer.ts b/src/packages/meta/store/crawler-readall/readall.reducer.ts index 0fac605..5daf4e2 100644 --- a/src/packages/meta/store/crawler-readall/readall.reducer.ts +++ b/src/packages/meta/store/crawler-readall/readall.reducer.ts @@ -1,5 +1,3 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; - import { Actions, ActionType, diff --git a/src/packages/meta/store/crawler-readall/readall.state.ts b/src/packages/meta/store/crawler-readall/readall.state.ts index 7de7dc6..040196f 100644 --- a/src/packages/meta/store/crawler-readall/readall.state.ts +++ b/src/packages/meta/store/crawler-readall/readall.state.ts @@ -1,9 +1,9 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { MetaCrawler } from '../../model'; export interface State { - error: ErrorResponse | null; + error: RPCError | null; pending: boolean; metaCrawlerList: MetaCrawler[] | null; } diff --git a/src/packages/noauth/component/list/list.component.ts b/src/packages/noauth/component/list/list.component.ts index 6fb50cc..7170c2c 100644 --- a/src/packages/noauth/component/list/list.component.ts +++ b/src/packages/noauth/component/list/list.component.ts @@ -2,9 +2,14 @@ import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core'; import { MatTableDataSource, MatSort } from '@angular/material'; import { AfterContentInit } from '@angular/core/src/metadata/lifecycle_hooks'; import { Router } from '@angular/router'; -import { Store } from '@ngrx/store'; +import { Store, select } from '@ngrx/store'; + +import { AuthSelector } from 'packages/member/store'; +import { RPCError } from 'packages/core/rpc/error'; +import { Domain } from 'packages/domain/model'; + import * as ListStore from '../../store/noauth-probe'; -import { Domain } from '../../../domain/model'; +import { NoAuthProbeSelector } from '../../store'; import { NoAuthProbe } from '../../model'; @Component({ @@ -13,6 +18,7 @@ import { NoAuthProbe } from '../../model'; styleUrls: ['./list.component.scss'] }) export class ListComponent implements OnInit, AfterContentInit { + noAuthProbes$ = this.store.pipe(select(NoAuthProbeSelector.select('noAuthProbes'))); selected: NoAuthProbe = null; @@ -23,27 +29,39 @@ export class ListComponent implements OnInit, AfterContentInit { constructor( private router: Router, private store: Store - ) { } + ) { + } ngAfterContentInit() { - // const domain: Domain = { - // id: 1, - // }; - // this.store.dispatch(new ListStore.ReadAllByDomain(domain)); + this.store.select(AuthSelector.select('domain')).subscribe( + (domain: Domain) => { + this.store.dispatch(new ListStore.ReadAllByDomain(domain)); + } + ); + // temporary data - const data: NoAuthProbe[] = new Array(); - for (let i = 0; i < 5; i++) { - const p: NoAuthProbe = { - id: i, - description: String('desc' + i), - createDate: new Date() - }; - data.push(p); - } + // const data: NoAuthProbe[] = new Array(); + // for (let i = 0; i < 5; i++) { + // const p: NoAuthProbe = { + // id: i, + // description: String('desc' + i), + // createDate: new Date() + // }; + // data.push(p); + // } - this.dataSource = new MatTableDataSource(data); - this.dataSource.sort = this.sort; + this.noAuthProbes$.subscribe( + (noAuthProbes: NoAuthProbe[]) => { + this.dataSource = new MatTableDataSource(noAuthProbes); + this.dataSource.sort = this.sort; + }, + (error: RPCError) => { + console.log(error.message); + } + ); + // this.dataSource = new MatTableDataSource(data); + // this.dataSource.sort = this.sort; } ngOnInit() { diff --git a/src/packages/noauth/service/noauth-probe.service.ts b/src/packages/noauth/service/noauth-probe.service.ts index a45a2de..6d0f2ac 100644 --- a/src/packages/noauth/service/noauth-probe.service.ts +++ b/src/packages/noauth/service/noauth-probe.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; -import { RPCService } from 'packages/commons/service/rpc.service'; +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { Domain } from 'packages/domain/model'; @@ -14,20 +14,20 @@ import { NoAuthProbe } from '../model'; export class NoAuthProbeService { public constructor( - private rpcService: RPCService, + private rpcClient: RPCClient, ) { } public readAllByDomain(domain: Domain): Observable { - return this.rpcService.call('NoAuthProbeService.readAllByDomain', domain); + return this.rpcClient.call('NoAuthProbeService.readAllByDomain', domain); } public acceptNoAuthProbe(noAuthProbe: NoAuthProbe): Observable { - return this.rpcService.call('NoAuthProbeService.acceptNoAuthProbe', noAuthProbe); + return this.rpcClient.call('NoAuthProbeService.acceptNoAuthProbe', noAuthProbe); } public denyNoauthProbe(noAuthProbe: NoAuthProbe): Observable { - return this.rpcService.call('NoAuthProbeService.denyNoauthProbe', noAuthProbe); + return this.rpcClient.call('NoAuthProbeService.denyNoauthProbe', noAuthProbe); } } diff --git a/src/packages/noauth/store/index.ts b/src/packages/noauth/store/index.ts index 84813f3..56e7112 100644 --- a/src/packages/noauth/store/index.ts +++ b/src/packages/noauth/store/index.ts @@ -1,3 +1,12 @@ +import { + createSelector, + createFeatureSelector, +} from '@ngrx/store'; + +import { StateSelector } from 'packages/commons/util/ngrx/store'; + +import { MODULE } from '../noauth-probe.constant'; + import * as NoAuthProbeStore from './noauth-probe'; export interface State { @@ -11,3 +20,10 @@ export const REDUCERS = { export const EFFECTS = [ NoAuthProbeStore.Effects, ]; + +export const selectNoAuthProbeState = createFeatureSelector(MODULE.name); + +export const NoAuthProbeSelector = new StateSelector(createSelector( + selectNoAuthProbeState, + (state: State) => state.noAuthProbe +)); diff --git a/src/packages/noauth/store/noauth-probe/noauth-probe.action.ts b/src/packages/noauth/store/noauth-probe/noauth-probe.action.ts index a9523ae..bde38dd 100644 --- a/src/packages/noauth/store/noauth-probe/noauth-probe.action.ts +++ b/src/packages/noauth/store/noauth-probe/noauth-probe.action.ts @@ -1,6 +1,6 @@ import { Action } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Domain } from 'packages/domain/model'; @@ -35,7 +35,7 @@ export class ReadAllByDomainSuccess implements Action { export class ReadAllByDomainFailure implements Action { readonly type = ActionType.ReadAllByDomainFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RPCError) {} } export class Accept implements Action { @@ -53,7 +53,7 @@ export class AcceptSuccess implements Action { export class AcceptFailure implements Action { readonly type = ActionType.AcceptFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RPCError) {} } export class Deny implements Action { @@ -71,7 +71,7 @@ export class DenySuccess implements Action { export class DenyFailure implements Action { readonly type = ActionType.DenyFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RPCError) {} } diff --git a/src/packages/noauth/store/noauth-probe/noauth-probe.effect.ts b/src/packages/noauth/store/noauth-probe/noauth-probe.effect.ts index bca9c14..3c40158 100644 --- a/src/packages/noauth/store/noauth-probe/noauth-probe.effect.ts +++ b/src/packages/noauth/store/noauth-probe/noauth-probe.effect.ts @@ -14,7 +14,7 @@ import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Domain } from 'packages/domain/model'; @@ -51,7 +51,7 @@ export class Effects { .map(noAuthProbes => { return new ReadAllByDomainSuccess(noAuthProbes); }) - .catch((error: ErrorResponse) => { + .catch((error: RPCError) => { return of(new ReadAllByDomainFailure(error)); }); @@ -63,7 +63,7 @@ export class Effects { .map(noAuthProbes => { return new AcceptSuccess(noAuthProbes); }) - .catch((error: ErrorResponse) => { + .catch((error: RPCError) => { return of(new AcceptFailure(error)); }); @@ -75,7 +75,7 @@ export class Effects { .map(noAuthProbes => { return new DenySuccess(noAuthProbes); }) - .catch((error: ErrorResponse) => { + .catch((error: RPCError) => { return of(new DenyFailure(error)); }); diff --git a/src/packages/noauth/store/noauth-probe/noauth-probe.reducer.ts b/src/packages/noauth/store/noauth-probe/noauth-probe.reducer.ts index 4d16f64..d4afeb9 100644 --- a/src/packages/noauth/store/noauth-probe/noauth-probe.reducer.ts +++ b/src/packages/noauth/store/noauth-probe/noauth-probe.reducer.ts @@ -1,5 +1,3 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; - import { ReadAllByDomain, ReadAllByDomainFailure, @@ -27,7 +25,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: null, - isPending: true, + pending: true, }; } @@ -35,7 +33,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: null, - isPending: false, + pending: false, noAuthProbes: action.payload, }; } @@ -44,7 +42,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: action.payload, - isPending: false, + pending: false, noAuthProbes: null, }; } @@ -53,7 +51,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: null, - isPending: true, + pending: true, }; } @@ -61,7 +59,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: null, - isPending: false, + pending: false, noAuthProbes: action.payload, }; } @@ -70,7 +68,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: action.payload, - isPending: false, + pending: false, }; } @@ -78,7 +76,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: null, - isPending: true, + pending: true, }; } @@ -86,7 +84,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: null, - isPending: false, + pending: false, noAuthProbes: action.payload, }; } @@ -95,7 +93,7 @@ export function reducer(state = initialState, action: Actions): State { return { ...state, error: action.payload, - isPending: false, + pending: false, }; } diff --git a/src/packages/noauth/store/noauth-probe/noauth-probe.state.ts b/src/packages/noauth/store/noauth-probe/noauth-probe.state.ts index 6e974d5..712963b 100644 --- a/src/packages/noauth/store/noauth-probe/noauth-probe.state.ts +++ b/src/packages/noauth/store/noauth-probe/noauth-probe.state.ts @@ -1,19 +1,15 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { NoAuthProbe } from '../../model'; export interface State { - error: ErrorResponse | null; - isPending: boolean; + error: RPCError | null; + pending: boolean; noAuthProbes: NoAuthProbe[] | null; } export const initialState: State = { error: null, - isPending: false, + pending: false, noAuthProbes: null, }; - -export const getNoAuthProbes = (state: State) => state.noAuthProbes; -export const getError = (state: State) => state.error; -export const isPending = (state: State) => state.isPending; diff --git a/src/packages/probe/component/list/list.component.ts b/src/packages/probe/component/list/list.component.ts index d88164b..6e17d60 100644 --- a/src/packages/probe/component/list/list.component.ts +++ b/src/packages/probe/component/list/list.component.ts @@ -1,13 +1,15 @@ -import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core'; +import { Component, OnInit, AfterViewInit, AfterContentInit, ViewChild } from '@angular/core'; import { MatTableDataSource, MatSort } from '@angular/material'; -import { AfterContentInit } from '@angular/core/src/metadata/lifecycle_hooks'; import { Router } from '@angular/router'; -import { Probe } from '../../model'; + import { Store, select } from '@ngrx/store'; + +import { RPCError } from 'packages/core/rpc/error'; +import { Domain } from 'packages/domain/model'; +import { AuthSelector } from 'packages/member/store'; + +import { Probe } from '../../model'; import * as ListStore from '../../store/list'; -import { Domain } from '../../../domain/model'; -import { AuthSelector } from '../../../member/store'; -import { ErrorResponse } from '../../../commons/service/error-response'; import { ListSelector } from '../../store'; @Component({ @@ -36,7 +38,7 @@ export class ListComponent implements OnInit, AfterContentInit { this.dataSource = new MatTableDataSource(probes); this.dataSource.sort = this.sort; }, - (error: ErrorResponse) => { + (error: RPCError) => { console.log(error); } ); diff --git a/src/packages/probe/service/probe.service.ts b/src/packages/probe/service/probe.service.ts index 6e79e6a..0e008eb 100644 --- a/src/packages/probe/service/probe.service.ts +++ b/src/packages/probe/service/probe.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; -import { RPCService } from 'packages/commons/service/rpc.service'; +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; import { Domain } from 'packages/domain/model'; @@ -14,19 +14,19 @@ import { Probe } from '../model'; export class ProbeService { public constructor( - private rpcService: RPCService, + private rpcClient: RPCClient, ) { } public readAllByDomain(domain: Domain): Observable { - return this.rpcService.call('ProbeService.readAllByDomain', domain); + return this.rpcClient.call('ProbeService.readAllByDomain', domain); } public read(id: string): Observable { const param = { id: id, }; - return this.rpcService.call('ProbeService.read', param); + return this.rpcClient.call('ProbeService.read', param); } } diff --git a/src/packages/probe/store/detail/detail.action.ts b/src/packages/probe/store/detail/detail.action.ts index 22911a1..76f6360 100644 --- a/src/packages/probe/store/detail/detail.action.ts +++ b/src/packages/probe/store/detail/detail.action.ts @@ -1,6 +1,6 @@ import { Action } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Probe } from '../../model'; @@ -26,7 +26,7 @@ export class ReadSuccess implements Action { export class ReadFailure implements Action { readonly type = ActionType.ReadFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RPCError) {} } diff --git a/src/packages/probe/store/detail/detail.effect.ts b/src/packages/probe/store/detail/detail.effect.ts index 6e75465..c013050 100644 --- a/src/packages/probe/store/detail/detail.effect.ts +++ b/src/packages/probe/store/detail/detail.effect.ts @@ -14,7 +14,7 @@ import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Probe } from '../../model'; import { ProbeService } from '../../service/probe.service'; @@ -43,7 +43,7 @@ export class Effects { .map(probe => { return new ReadSuccess(probe); }) - .catch((error: ErrorResponse) => { + .catch((error: RPCError) => { return of(new ReadFailure(error)); }); } diff --git a/src/packages/probe/store/detail/detail.reducer.ts b/src/packages/probe/store/detail/detail.reducer.ts index 2f211b1..21dccad 100644 --- a/src/packages/probe/store/detail/detail.reducer.ts +++ b/src/packages/probe/store/detail/detail.reducer.ts @@ -1,5 +1,3 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; - import { Read, ReadFailure, diff --git a/src/packages/probe/store/detail/detail.state.ts b/src/packages/probe/store/detail/detail.state.ts index 5ea411f..4218697 100644 --- a/src/packages/probe/store/detail/detail.state.ts +++ b/src/packages/probe/store/detail/detail.state.ts @@ -1,9 +1,9 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Probe } from '../../model'; export interface State { - error: ErrorResponse | null; + error: RPCError | null; isPending: boolean; probe: Probe | null; } diff --git a/src/packages/probe/store/list/list.action.ts b/src/packages/probe/store/list/list.action.ts index fae1ee2..c305b06 100644 --- a/src/packages/probe/store/list/list.action.ts +++ b/src/packages/probe/store/list/list.action.ts @@ -1,6 +1,6 @@ import { Action } from '@ngrx/store'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Domain } from 'packages/domain/model'; import { Probe } from '../../model'; @@ -27,7 +27,7 @@ export class ReadAllByDomainSuccess implements Action { export class ReadAllByDomainFailure implements Action { readonly type = ActionType.ReadAllByDomainFailure; - constructor(public payload: ErrorResponse) {} + constructor(public payload: RPCError) {} } diff --git a/src/packages/probe/store/list/list.effect.ts b/src/packages/probe/store/list/list.effect.ts index adf3e49..6b90aa0 100644 --- a/src/packages/probe/store/list/list.effect.ts +++ b/src/packages/probe/store/list/list.effect.ts @@ -14,7 +14,7 @@ import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/take'; -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Domain } from 'packages/domain/model'; @@ -45,7 +45,7 @@ export class Effects { .map(probes => { return new ReadAllByDomainSuccess(probes); }) - .catch((error: ErrorResponse) => { + .catch((error: RPCError) => { return of(new ReadAllByDomainFailure(error)); }); } diff --git a/src/packages/probe/store/list/list.reducer.ts b/src/packages/probe/store/list/list.reducer.ts index fd925b9..44c5a26 100644 --- a/src/packages/probe/store/list/list.reducer.ts +++ b/src/packages/probe/store/list/list.reducer.ts @@ -1,5 +1,3 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; - import { ReadAllByDomain, ReadAllByDomainFailure, diff --git a/src/packages/probe/store/list/list.state.ts b/src/packages/probe/store/list/list.state.ts index f5e8f20..fddbf05 100644 --- a/src/packages/probe/store/list/list.state.ts +++ b/src/packages/probe/store/list/list.state.ts @@ -1,9 +1,9 @@ -import { ErrorResponse } from 'packages/commons/service/error-response'; +import { RPCError } from 'packages/core/rpc/error'; import { Probe } from '../../model'; export interface State { - error: ErrorResponse | null; + error: RPCError | null; isPending: boolean; probes: Probe[] | null; } diff --git a/yarn.lock b/yarn.lock index d6eb506..f805c32 100644 --- a/yarn.lock +++ b/yarn.lock @@ -409,6 +409,12 @@ angular-l10n@^4.1.5: dependencies: tslib "^1.7.1" +angularx-qrcode@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/angularx-qrcode/-/angularx-qrcode-1.0.1.tgz#9b10423995cd7448ef38843e241407ce7337daad" + dependencies: + qrcodejs2 "0.0.2" + ansi-html@0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.7.tgz#813584021962a9e9e6fd039f940d12f56ca7859e" @@ -5723,6 +5729,10 @@ qjobs@^1.1.4: version "1.1.5" resolved "https://registry.yarnpkg.com/qjobs/-/qjobs-1.1.5.tgz#659de9f2cf8dcc27a1481276f205377272382e73" +qrcodejs2@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/qrcodejs2/-/qrcodejs2-0.0.2.tgz#465afe5e39f19facecb932c11f7a186109146ae1" + qs@6.5.1: version "6.5.1" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"