UNPKG

@4players/odin

Version:

A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects

43 lines (42 loc) 2.23 kB
import { OdinEventMethods } from './types'; import { EventHandlers, EventSchemas } from './schema-types'; export type OdinStreamHandler = (method: OdinEventMethods, params: unknown) => void; export interface RequestResolve { method: string; resolve: (result: unknown) => void; reject: (error: Error) => void; timeoutHandle: ReturnType<typeof setTimeout> | null; handler?: (method: string, params: unknown) => Promise<unknown>; } export declare class OdinStream { private _url; private _handler; private _timeout; private _websocket; private _requests; private nextId; constructor(_url: string, _handler: OdinStreamHandler, _timeout?: number); get url(): string; get websocket(): WebSocket | null; get timeout(): number; get requests(): Map<number, RequestResolve>; get handler(): OdinStreamHandler; get onopen(): ((this: WebSocket, ev: Event) => any) | null; set onopen(value: ((this: WebSocket, ev: Event) => any) | null); get onclose(): ((this: WebSocket, ev: CloseEvent) => any) | null; set onclose(value: ((this: WebSocket, ev: CloseEvent) => any) | null); set onerror(value: ((this: WebSocket, ev: Event) => any) | null); get onerror(): ((this: WebSocket, ev: Event) => any) | null; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): Promise<void>; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; request(method: string, params: any): Promise<unknown>; close(): void; } /** * Creates a handler which correctly handles the event depending on the method and validates its params. * * @param schemas The object which provides the schemas that are used to check recursively the type of the value at runtime * @param handlers All event handler for the given schema<T> * @returns Returns a handler function that takes the method (type) and the params as argument (The msgpack params) */ export declare const makeHandler: <T extends EventSchemas, I>(schemas: T, handlers: EventHandlers<T, I>, instance: I) => (method: string, params: unknown) => void;