UNPKG

@loopeco/socketio

Version:

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

51 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SocketIoMixin = void 0; const keys_1 = require("../keys"); const socketio_component_1 = require("../socketio.component"); function SocketIoMixin(superClass) { return class extends superClass { // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(...args) { super(...args); this.component(socketio_component_1.SocketIoComponent); } /** * The main Socket server instance providing Socket connections for this application. */ get socketServer() { return this.getSync(keys_1.SocketIoBindings.SERVER); } expressMiddleware(factoryOrKey, configOrHandlers, options = {}) { return this.socketServer.expressMiddleware(factoryOrKey, configOrHandlers, { chain: keys_1.SocketIoTags.SOCKETIO_MIDDLEWARE_CHAIN, ...options, }); } /** * Register a middleware function or provider class * * @example * ```ts * const log: Middleware = async (requestCtx, next) { * // ... * } * server.middleware(log); * ``` * * @param middleware - Middleware function or provider class * @param options - Middleware binding options */ middleware(middleware, options = {}) { return this.socketServer.middleware(middleware, { chain: keys_1.SocketIoTags.SOCKETIO_MIDDLEWARE_CHAIN, ...options, }); } route(controllerClass, meta) { return this.socketServer.route(controllerClass, meta); } }; } exports.SocketIoMixin = SocketIoMixin; //# sourceMappingURL=socketio.mixin.js.map