UNPKG

@loopeco/socketio

Version:

A enhanced LoopBack's WebSocket server based on socket.io

27 lines (24 loc) 987 B
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( @inject.context() protected context: Context, @inject(CoreBindings.CONTROLLER_CURRENT) protected controller: ControllerClass, @inject(SocketIoBindings.INVOKE_METHOD) protected invoke: SocketIoInvokeMethod, @inject(SocketIoBindings.SEND_METHOD) protected send: SocketIoSendMethod, @inject(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); } } }