|
|
@ -19,7 +19,7 @@ export abstract class WebSocketServerService<M extends Microservice> extends Int |
|
|
|
/** |
|
|
|
* The list of registered methods |
|
|
|
*/ |
|
|
|
#methods: { [method: string]: (payload?: any) => Promise<any>|any } = {}; |
|
|
|
private __methods: { [method: string]: (payload?: any) => Promise<any>|any } = {}; |
|
|
|
|
|
|
|
// Overridable ---------------------------------------------------------------------------------
|
|
|
|
|
|
|
@ -111,10 +111,10 @@ export abstract class WebSocketServerService<M extends Microservice> extends Int |
|
|
|
* Install a method into the server service |
|
|
|
*/ |
|
|
|
protected installMethod(name: string, method: (payload?: any) => Promise<any>|any) { |
|
|
|
if (this.#methods[name] !== undefined) { |
|
|
|
if (this.__methods[name] !== undefined) { |
|
|
|
throw new Error("Attempted to install method with duplicate name in websocket service"); |
|
|
|
} |
|
|
|
this.#methods[name] = method; |
|
|
|
this.__methods[name] = method; |
|
|
|
} |
|
|
|
|
|
|
|
// Event Handling ------------------------------------------------------------------------------
|
|
|
@ -123,11 +123,11 @@ export abstract class WebSocketServerService<M extends Microservice> extends Int |
|
|
|
* Handle an incoming request |
|
|
|
*/ |
|
|
|
protected async handleRequest(socket: WebSocket, request: IWebSocketRequest) { |
|
|
|
if (this.#methods[request.method] === undefined) { |
|
|
|
if (this.__methods[request.method] === undefined) { |
|
|
|
console.warn(`Requested unknown method: '${request.method}' with payload:`, request.payload); |
|
|
|
return; |
|
|
|
} |
|
|
|
let result = await this.#methods[request.method](request.payload); |
|
|
|
let result = await this.__methods[request.method](request.payload); |
|
|
|
socket.send(JSON.stringify(<IWebSocketResponse>{ |
|
|
|
type: "response", |
|
|
|
requestId: request.requestId, |
|
|
|