ing
This commit is contained in:
parent
61597d4581
commit
5f63a0b4de
|
@ -152,6 +152,7 @@ const serviceConfig: Map<string, APIService> = new Map();
|
||||||
serviceConfig.set('DiscoveryService', DiscoveryService.prototype);
|
serviceConfig.set('DiscoveryService', DiscoveryService.prototype);
|
||||||
serviceConfig.set('NoAuthProbeService', NoAuthProbeService.prototype);
|
serviceConfig.set('NoAuthProbeService', NoAuthProbeService.prototype);
|
||||||
|
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
export interface Config {
|
export interface Config {
|
||||||
container: ContainerConfig;
|
container: ContainerConfig;
|
||||||
|
|
|
@ -77,7 +77,6 @@ class OFApplication {
|
||||||
private sagaMiddleware: SagaMiddleware<any>;
|
private sagaMiddleware: SagaMiddleware<any>;
|
||||||
private history: History;
|
private history: History;
|
||||||
|
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
this.config = appConfig;
|
this.config = appConfig;
|
||||||
this.history = createHashHistory();
|
this.history = createHashHistory();
|
||||||
|
@ -98,6 +97,9 @@ class OFApplication {
|
||||||
|
|
||||||
await this.initRedux();
|
await this.initRedux();
|
||||||
|
|
||||||
|
let serviceInvoker = new ServiceInvoker(this.config.service, this.store);
|
||||||
|
this.rpcClient.setServiceInvoker(serviceInvoker);
|
||||||
|
|
||||||
this.displayApp();
|
this.displayApp();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -107,8 +109,7 @@ class OFApplication {
|
||||||
|
|
||||||
private initRpcClient(): Promise<WebSocketRPC> {
|
private initRpcClient(): Promise<WebSocketRPC> {
|
||||||
const rpcClient = new Promise<WebSocketRPC>((resolve, reject) => {
|
const rpcClient = new Promise<WebSocketRPC>((resolve, reject) => {
|
||||||
let serviceInvoker = new ServiceInvoker(this.config.service);
|
let client = new WebSocketRPC(this.config.rpc.url);
|
||||||
let client = new WebSocketRPC(this.config.rpc.url, serviceInvoker);
|
|
||||||
client.initialize()
|
client.initialize()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve(client);
|
resolve(client);
|
||||||
|
|
|
@ -1,5 +1,19 @@
|
||||||
export abstract class Service {
|
import {
|
||||||
|
Store,
|
||||||
|
} from 'redux';
|
||||||
|
|
||||||
|
import Action from '@overflow/commons/redux/Action';
|
||||||
|
|
||||||
|
export abstract class Service {
|
||||||
|
private store: Store<any>;
|
||||||
|
|
||||||
|
protected dispatch(action: Action<any>): void {
|
||||||
|
this.store.dispatch(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setStore(store: Store<any>): void {
|
||||||
|
this.store = store;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Service;
|
export default Service;
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
import {Service} from '@overflow/commons/api/service';
|
import {Service} from '@overflow/commons/api/service';
|
||||||
|
import {
|
||||||
|
Store,
|
||||||
|
} from 'redux';
|
||||||
|
|
||||||
export class ServiceInvoker {
|
export class ServiceInvoker {
|
||||||
private config: Map<string, Service>;
|
private config: Map<string, Service>;
|
||||||
private instanceMap: Map<string, Object>;
|
private instanceMap: Map<string, Object>;
|
||||||
|
private store: Store<any>;
|
||||||
|
|
||||||
public constructor(config: Map<string, Service>) {
|
public constructor(config: Map<string, Service>, store: Store<any>) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.store = store;
|
||||||
this.instanceMap = new Map();
|
this.instanceMap = new Map();
|
||||||
|
|
||||||
this.initialize();
|
this.initialize();
|
||||||
|
@ -13,7 +18,9 @@ export class ServiceInvoker {
|
||||||
|
|
||||||
private initialize(): void {
|
private initialize(): void {
|
||||||
this.config.forEach((value, key) => {
|
this.config.forEach((value, key) => {
|
||||||
this.instanceMap.set(key, Object.create(value));
|
const instance: Service = Object.create(value);
|
||||||
|
instance.setStore(this.store);
|
||||||
|
this.instanceMap.set(key, instance);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,15 +49,18 @@ export default class WebSocketRPC {
|
||||||
/**
|
/**
|
||||||
* name
|
* name
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, serviceInvoker: ServiceInvoker) {
|
public constructor(url: string) {
|
||||||
this.isReady = false;
|
this.isReady = false;
|
||||||
this.connStatus = WebSocketStatus.NOT_CONNECT;
|
this.connStatus = WebSocketStatus.NOT_CONNECT;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.serviceInvoker = serviceInvoker;
|
|
||||||
this.onResponseListeners = new Map();
|
this.onResponseListeners = new Map();
|
||||||
this.requestQueue = new Map();
|
this.requestQueue = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setServiceInvoker(serviceInvoker: ServiceInvoker): void {
|
||||||
|
this.serviceInvoker = serviceInvoker;
|
||||||
|
}
|
||||||
|
|
||||||
public Call(method: string, args: any): Promise<any> {
|
public Call(method: string, args: any): Promise<any> {
|
||||||
return new Promise<any>((resolve, reject) => {
|
return new Promise<any>((resolve, reject) => {
|
||||||
const requestID = this.getRequestID();
|
const requestID = this.getRequestID();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Service } from '@overflow/commons/api/service';
|
import { Service } from '@overflow/commons/api/service';
|
||||||
|
import NoAuthProbe from '../model/NoAuthProbe';
|
||||||
|
import Action from '@overflow/commons/redux/Action';
|
||||||
|
|
||||||
export class NoAuthProbeService extends Service {
|
export class NoAuthProbeService extends Service {
|
||||||
// tslint:disable-next-line:no-empty
|
// tslint:disable-next-line:no-empty
|
||||||
|
@ -8,8 +9,11 @@ export class NoAuthProbeService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public regist(params: any): void {
|
public regist(params: any): void {
|
||||||
console.log('Discovery has finished.' + params);
|
const json: NoAuthProbe = JSON.parse(params);
|
||||||
// state change test
|
const action: Action = {
|
||||||
|
type: 'TEST',
|
||||||
|
};
|
||||||
|
this.dispatch(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user