@loopback/socketio
Version:
LoopBack's WebSocket server based on socket.io
48 lines (47 loc) • 1.98 kB
TypeScript
import { Constructor, MetadataAccessor } from '@loopback/core';
/**
* Metadata for SocketIo
*/
export interface SocketIoMetadata {
name?: string;
namespace?: string | RegExp;
}
export declare const SOCKET_IO_METADATA: MetadataAccessor<SocketIoMetadata, ClassDecorator>;
export declare const SOCKET_IO_SUBSCRIBE_METADATA: MetadataAccessor<(string | RegExp)[], MethodDecorator>;
export declare const SOCKET_IO_CONNECT_METADATA: MetadataAccessor<boolean, MethodDecorator>;
/**
* Decorate a socketio controller class to specify the namespace.
*
* @example
* ```ts
* @socketio({namespace: '/chats'})
* export class SocketIoController {}
* ```
* @param spec A namespace or object
*/
export declare function socketio(spec?: SocketIoMetadata | string | RegExp): ClassDecorator;
export declare function getSocketIoMetadata(controllerClass: Constructor<unknown>): SocketIoMetadata | undefined;
export declare namespace socketio {
function io(): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
function namespace(name: string): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
function socket(): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
/**
* Decorate a method to subscribe to socketio events.
* For example,
* ```ts
* @socketio.subscribe('chat message')
* async function onChat(msg: string) {
* }
* ```
* @param messageTypes
*/
function subscribe(...messageTypes: (string | RegExp)[]): MethodDecorator;
/**
* Decorate a controller method for `disconnect`
*/
function disconnect(): MethodDecorator;
/**
* Decorate a controller method for `connect`
*/
function connect(): MethodDecorator;
}