Files
smartsocket/ts/smartsocket.pluginstyped.ts

47 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-09-29 17:21:08 +00:00
// node native
2022-03-14 22:40:55 +01:00
import type * as http from 'http';
import type * as https from 'https';
2020-09-29 17:21:08 +00:00
2023-07-21 03:53:41 +02:00
export type { http, https };
2020-09-29 17:21:08 +00:00
// third party scope - ws types
import type * as wsTypes from 'ws';
2020-09-29 17:21:08 +00:00
export namespace ws {
export type WebSocket = wsTypes.WebSocket;
export type WebSocketServer = wsTypes.WebSocketServer;
export type RawData = wsTypes.RawData;
}
2020-09-29 17:21:08 +00:00
// smartserve compatibility interface (for setExternalServer)
// This mirrors the IWebSocketPeer interface from smartserve
export interface ISmartserveWebSocketPeer {
id: string;
url: string;
readyState: 0 | 1 | 2 | 3;
protocol: string;
extensions: string;
send(data: string): void;
sendBinary(data: Uint8Array | ArrayBuffer): void;
close(code?: number, reason?: string): void;
ping(data?: Uint8Array): void;
terminate(): void;
context: any;
data: Map<string, unknown>;
tags: Set<string>;
}
2020-09-29 17:21:08 +00:00
export interface ISmartserveWebSocketMessage {
type: 'text' | 'binary';
text?: string;
data?: Uint8Array;
size: number;
2022-03-24 12:52:28 +01:00
}
export interface ISmartserveWebSocketHooks {
onOpen?: (peer: ISmartserveWebSocketPeer) => void | Promise<void>;
onMessage?: (peer: ISmartserveWebSocketPeer, message: ISmartserveWebSocketMessage) => void | Promise<void>;
onClose?: (peer: ISmartserveWebSocketPeer, code: number, reason: string) => void | Promise<void>;
onError?: (peer: ISmartserveWebSocketPeer, error: Error) => void | Promise<void>;
2022-01-19 18:36:13 +01:00
}