@loopeco/socketio
Version:
A enhanced LoopBack's WebSocket server based on socket.io
27 lines (24 loc) • 987 B
text/typescript
import {Context, ControllerClass, CoreBindings, inject} from '@loopback/core';
import {SocketIoBindings} from './keys';
import {SocketIoInvokeMethod, SocketIoRejectMethod, SocketIoSendMethod, SocketIoSequence} from './types';
export class DefaultSocketIoSequence implements SocketIoSequence {
constructor(
.context() protected context: Context,
(CoreBindings.CONTROLLER_CURRENT)
protected controller: ControllerClass,
(SocketIoBindings.INVOKE_METHOD)
protected invoke: SocketIoInvokeMethod,
(SocketIoBindings.SEND_METHOD)
protected send: SocketIoSendMethod,
(SocketIoBindings.REJECT_METHOD)
protected reject: SocketIoRejectMethod,
) {}
async handle(methodName: string, args: unknown[], done: Function) {
try {
const result = await this.invoke(this.context, this.controller, methodName, args);
await this.send(done, result);
} catch (err) {
await this.reject(done, err);
}
}
}