UNPKG

node-jet

Version:

Jet Realtime Message Bus for the Web. Daemon and Peer implementation.

39 lines (38 loc) 1.54 kB
import { WebSocket as ws } from 'ws'; import MessageSocket from './message-socket.js'; /** Socket instance. * @class * @classdesc Class used as Interface to communicate between the native socket connection and the json rpc layer. */ export declare class Socket { id: string; sock?: WebSocket | MessageSocket | ws; type: string; constructor(socket?: WebSocket | MessageSocket | ws); /** * Method to connect to Server * @param url url to connect to * @param ip Ip address to connect to only valid in combination with port * @param port Port used to connect */ connect: (url?: string | undefined, ip?: string | undefined, port?: number | undefined) => void; /** * Closes the native socket connection */ close: () => void; /** * Listening to socket events to socket events * @param event "close": CloseEvent;"error": Event;"message": MessageEvent;"open": Event; * @param cb callback that is invoked when event is triggered * @emits CloseEvent in case of closing of the native socket * @emits Event in case of established socket connection * @emits MessageEvent in case of received message * @emits Event in case of error */ addEventListener: <K extends keyof WebSocketEventMap>(event: K, cb: (this: WebSocket, ev: WebSocketEventMap[K]) => void) => void; /** * sending a message via the native socket * @param message //string that represents the message to send */ send: (message: string) => void; }