index.d.ts 1.4 KB

123456789101112131415161718192021222324252627
  1. // Type definitions for websocket-stream 5.3
  2. // Project: https://github.com/maxogden/websocket-stream#readme
  3. // Original definitions by: Ben Burns <https://github.com/benjamincburns>
  4. import * as WebSocket from 'ws';
  5. import { Duplex } from 'stream';
  6. import * as http from 'http';
  7. declare namespace WebSocketStream {
  8. type WebSocketDuplex = Duplex & { socket: WebSocket };
  9. class Server extends WebSocket.Server {
  10. on(event: 'connection', cb: (this: WebSocket, socket: WebSocket, request: http.IncomingMessage) => void): this;
  11. on(event: 'error', cb: (this: WebSocket, error: Error) => void): this;
  12. on(event: 'headers', cb: (this: WebSocket, headers: string[], request: http.IncomingMessage) => void): this;
  13. on(event: 'listening', cb: (this: WebSocket) => void): this;
  14. on(event: 'stream', cb: (this: WebSocket, stream: WebSocketDuplex, request: http.IncomingMessage) => void): this;
  15. on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
  16. }
  17. function createServer(opts?: WebSocket.ServerOptions, callback?: () => void): Server;
  18. }
  19. declare function WebSocketStream(target: string | WebSocket, options?: WebSocket.ClientOptions): WebSocketStream.WebSocketDuplex;
  20. declare function WebSocketStream(target: string | WebSocket, protocols?: string | string[], options?: WebSocket.ClientOptions): WebSocketStream.WebSocketDuplex;
  21. export = WebSocketStream;