Skip to content

Commit

Permalink
🤖 Merge PR #46794 ws added EventListenerOptions and removed optional …
Browse files Browse the repository at this point in the history
…flag on callback by @wilwade
  • Loading branch information
wilwade committed Sep 28, 2020
1 parent f477068 commit 744ed6c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
25 changes: 19 additions & 6 deletions types/ws/index.d.ts
Expand Up @@ -56,14 +56,23 @@ declare class WebSocket extends events.EventEmitter {
terminate(): void;

// HTML5 WebSocket events
addEventListener(method: 'message', cb?: (event: { data: any; type: string; target: WebSocket }) => void): void;
addEventListener(method: 'close', cb?: (event: {
addEventListener(method: 'message', cb: (event: {
data: any;
type: string;
target: WebSocket
}, options?: WebSocket.EventListenerOptions) => void): void;
addEventListener(method: 'close', cb: (event: {
wasClean: boolean; code: number;
reason: string; target: WebSocket
}) => void): void;
addEventListener(method: 'error', cb?: (event: {error: any, message: any, type: string, target: WebSocket }) => void): void;
addEventListener(method: 'open', cb?: (event: { target: WebSocket }) => void): void;
addEventListener(method: string, listener?: () => void): void;
}, options?: WebSocket.EventListenerOptions) => void): void;
addEventListener(method: 'error', cb: (event: {
error: any,
message: any,
type: string,
target: WebSocket
}, options?: WebSocket.EventListenerOptions) => void): void;
addEventListener(method: 'open', cb: (event: { target: WebSocket }) => void, options?: WebSocket.EventListenerOptions): void;
addEventListener(method: string, listener: () => void, options?: WebSocket.EventListenerOptions): void;

removeEventListener(method: 'message', cb?: (event: { data: any; type: string; target: WebSocket }) => void): void;
removeEventListener(method: 'close', cb?: (event: {
Expand Down Expand Up @@ -192,6 +201,10 @@ declare namespace WebSocket {
target: WebSocket;
}

interface EventListenerOptions {
once?: boolean;
}

interface ServerOptions {
host?: string;
port?: number;
Expand Down
7 changes: 7 additions & 0 deletions types/ws/ws-tests.ts
Expand Up @@ -158,3 +158,10 @@ import * as url from 'url';
duplex.pipe(process.stdout);
process.stdin.pipe(duplex);
}

{
const ws = new WebSocket('ws://www.host.com/path');
ws.addEventListener('other', () => {});
ws.addEventListener('other', () => {}, { once: true });
ws.addEventListener('other', () => {}, { once: true });
}

0 comments on commit 744ed6c

Please sign in to comment.