From 1fc94ebd7d854d59edecc5e2b69812865c4893c2 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 13 Mar 2018 20:59:39 +0900 Subject: [PATCH] ing --- src/app/core/rpc/client/rpc-client.ts | 28 ---- src/app/core/rpc/protocol/client-codec.ts | 4 - .../rpc/protocol/json/client-notification.ts | 3 - .../core/rpc/protocol/json/client-request.ts | 3 - .../core/rpc/protocol/json/client-response.ts | 6 - src/app/core/rpc/registry/rpc-registry.ts | 36 ------ .../core/rx/websocket/rx-websocket-subject.ts | 122 ------------------ src/packages/core/rest/client/RESTClient.ts | 6 +- 8 files changed, 1 insertion(+), 207 deletions(-) delete mode 100644 src/app/core/rpc/client/rpc-client.ts delete mode 100644 src/app/core/rpc/protocol/client-codec.ts delete mode 100644 src/app/core/rpc/protocol/json/client-notification.ts delete mode 100644 src/app/core/rpc/protocol/json/client-request.ts delete mode 100644 src/app/core/rpc/protocol/json/client-response.ts delete mode 100644 src/app/core/rpc/registry/rpc-registry.ts delete mode 100644 src/app/core/rx/websocket/rx-websocket-subject.ts diff --git a/src/app/core/rpc/client/rpc-client.ts b/src/app/core/rpc/client/rpc-client.ts deleted file mode 100644 index d65d541..0000000 --- a/src/app/core/rpc/client/rpc-client.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Observable } from 'rxjs/Observable'; -import { Subject } from 'rxjs/Subject'; - -import { RPCRegistry } from '../registry/rpc-registry'; - - -export class RPCClient { - private socketSubject: Subject; - private rpcRegistry: RPCRegistry; - private pendingRequests: Map>; - - public constructor() { - - } - - public call(method: string, ...args: any[]): Observable { - - return undefined; - } - - public send(method: string, ...args: any[]): void { - - } - - private sendInternal(method: string, ...args: any[]): Observable { - return undefined; - } -} diff --git a/src/app/core/rpc/protocol/client-codec.ts b/src/app/core/rpc/protocol/client-codec.ts deleted file mode 100644 index b8c7ae2..0000000 --- a/src/app/core/rpc/protocol/client-codec.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface ClientCodec { - encode(method: string, args: any[], id?: number); - -} diff --git a/src/app/core/rpc/protocol/json/client-notification.ts b/src/app/core/rpc/protocol/json/client-notification.ts deleted file mode 100644 index c8be96e..0000000 --- a/src/app/core/rpc/protocol/json/client-notification.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface ClientNotification { - -} diff --git a/src/app/core/rpc/protocol/json/client-request.ts b/src/app/core/rpc/protocol/json/client-request.ts deleted file mode 100644 index ac76013..0000000 --- a/src/app/core/rpc/protocol/json/client-request.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface ClientRequest { - id: number; -} diff --git a/src/app/core/rpc/protocol/json/client-response.ts b/src/app/core/rpc/protocol/json/client-response.ts deleted file mode 100644 index c857c4f..0000000 --- a/src/app/core/rpc/protocol/json/client-response.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface ClientResponse { - jsonrpc: string; - id?: number; - result?: any; - error?: Error; -} diff --git a/src/app/core/rpc/registry/rpc-registry.ts b/src/app/core/rpc/registry/rpc-registry.ts deleted file mode 100644 index a1d4a68..0000000 --- a/src/app/core/rpc/registry/rpc-registry.ts +++ /dev/null @@ -1,36 +0,0 @@ -export class RPCRegistry { - private services: Map; - - public constructor() { - this.services = new Map(); - } - - public registerService(receiver: Object, name?: string): void { - if (undefined === name) { - name = receiver.constructor.name; - } - this.services.set(name, receiver); - } - - public getService(name: string): any | undefined { - return this.services.get(name); - } - - public hasMethod(method: string): boolean { - const names = method.split('.'); - if (undefined === names || 2 !== names.length) { - throw new Error(); - } - const serviceName = names[0]; - const methodName = names[1]; - - const service = this.services.get(serviceName); - if (undefined === service || !service.hasOwnProperty(methodName)) { - return false; - } - - return true; - } - - -} diff --git a/src/app/core/rx/websocket/rx-websocket-subject.ts b/src/app/core/rx/websocket/rx-websocket-subject.ts deleted file mode 100644 index 3f3cd23..0000000 --- a/src/app/core/rx/websocket/rx-websocket-subject.ts +++ /dev/null @@ -1,122 +0,0 @@ -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 Codec { - decode(e: MessageEvent): any; - encode(data: any): string; -} - -export const defaultCodec: Codec = { - decode: (e: MessageEvent) => { - return JSON.parse(e.data); - }, - encode: (data: any): string => { - return JSON.stringify(data); - } -}; - -export class RxWebsocketSubject extends Subject { - private reconnectionObservable: Observable; - private wsSubjectConfig: WebSocketSubjectConfig; - private socket: WebSocketSubject; - private connectionObserver: Observer; - private _connectionStatus: Observable; - - private _reconnectInterval = 5000; - private _reconnectAttempts = 10; - - public constructor(private url: string, private codec?: Codec) { - super(); - - this._connectionStatus = new Observable((observer) => { - this.connectionObserver = observer; - }).share().distinctUntilChanged(); - - if (undefined === codec) { - this.codec = defaultCodec; - } - - this.wsSubjectConfig = { - url: url, - closeObserver: { - next: (e: CloseEvent) => { - this.socket = null; - this.connectionObserver.next(false); - } - }, - openObserver: { - next: (e: Event) => { - this.connectionObserver.next(true); - } - }, - // resultSelector: this.codec.decode, - }; - - this._connectionStatus.subscribe((isConnected: boolean) => { - if (!this.reconnectionObservable && typeof(isConnected) === 'boolean' && !isConnected) { - this.reconnect(); - } - }); - } - - public set reconnectInterval(reconnectInterval: number) { - this._reconnectInterval = reconnectInterval; - } - - public set reconnectAttempts(reconnectAttempts: number) { - this._reconnectAttempts = reconnectAttempts; - } - - 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(); - } - } - ); - } - - private reconnect(): void { - this.reconnectionObservable = Observable.interval(this._reconnectInterval) - .takeWhile((v, index) => { - return index < this._reconnectAttempts && !this.socket; - }); - this.reconnectionObservable.subscribe( - () => { - this.connect(); - }, - null, - () => { - this.reconnectionObservable = null; - if (!this.socket) { - this.complete(); - this.connectionObserver.complete(); - } - } - ); - } - - public send(data: any): void { - const s = this.codec.encode(data); - this.socket.next(this.codec.encode(data)); - } -} diff --git a/src/packages/core/rest/client/RESTClient.ts b/src/packages/core/rest/client/RESTClient.ts index 9ff174b..a3e72b3 100644 --- a/src/packages/core/rest/client/RESTClient.ts +++ b/src/packages/core/rest/client/RESTClient.ts @@ -37,11 +37,7 @@ export class RESTClient { }): Observable { return this._httpClient .request(method, Location.joinWithSlash(this._baseURL, entry), options) - .map( - (response: T) => { - return response; - } - ) + .map(response => response) .catch((error: HttpErrorResponse) => { const aryMsg = error.error.message.split('|'); const resError: RESTError = {