UNPKG

@loopeco/socketio

Version:

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

28 lines (24 loc) 1.08 kB
import {Application, ApplicationConfig, Binding, Constructor, Context, Server} from '@loopback/core'; import {format} from 'util'; import {SocketIoMixin} from './mixins'; export const ERR_NO_MULTI_SERVER = format( 'SocketApplication does not support multiple servers!', 'To create your own server bindings, please extend the Application class.', ); export class SocketIoApplication extends SocketIoMixin(Application) { constructor(parent: Context); constructor(config?: ApplicationConfig, parent?: Context); constructor(configOrParent?: ApplicationConfig | Context, parent?: Context) { super(configOrParent, parent); } // Unfortunately, TypeScript does not allow overriding methods inherited // from mapped types. https://github.com/microsoft/TypeScript/issues/38496 // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore public server(server: Constructor<Server>, name?: string): Binding { if (this.findByTag('server').length > 0) { throw new Error(ERR_NO_MULTI_SERVER); } return super.server(server, name); } }