-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project import generated by Copybara.
GitOrigin-RevId: f093288ace705c1924be026783dcbeca315598b1
- Loading branch information
1 parent
c6a4520
commit 5e9873f
Showing
21 changed files
with
303 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { PolyfillWebSocketFactory, PolyfillWebSocket } from "."; | ||
export { PolyfillWebSocket } from "."; | ||
|
||
const PolyfillWebSocket = | ||
WebSocket ?? global?.WebSocket ?? window?.WebSocket ?? self?.WebSocket; | ||
|
||
export const factory: PolyfillWebSocketFactory = ( | ||
url: string, | ||
params?: unknown, | ||
) => { | ||
if (params) { | ||
return new PolyfillWebSocket( | ||
url, | ||
params as string | string[], | ||
) as unknown as PolyfillWebSocket; | ||
} | ||
return new PolyfillWebSocket(url) as unknown as PolyfillWebSocket; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ws from "ws"; | ||
import { PolyfillWebSocket, PolyfillWebSocketFactory } from "."; | ||
export { PolyfillWebSocket } from "."; | ||
|
||
export const factory: PolyfillWebSocketFactory = ( | ||
url: string, | ||
params?: unknown, | ||
) => new ws(url, params as ws.ClientOptions) as unknown as PolyfillWebSocket; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import ws, { Event, ErrorEvent, CloseEvent, MessageEvent } from "ws"; | ||
|
||
export type PolyfillWebSocket = { | ||
OPEN: typeof ws.OPEN; | ||
binaryType: string; | ||
onopen: ((event: Event) => void) | null; | ||
onerror: ((event: ErrorEvent) => void) | null; | ||
onclose: ((event: CloseEvent) => void) | null; | ||
onmessage: ((event: MessageEvent) => void) | null; | ||
readonly readyState: | ||
| typeof ws.CONNECTING | ||
| typeof ws.OPEN | ||
| typeof ws.CLOSING | ||
| typeof ws.CLOSED; | ||
removeAllListeners?: () => void; | ||
send( | ||
data: | ||
| string | ||
| number | ||
| Buffer | ||
| DataView | ||
| ArrayBufferView | ||
| Uint8Array | ||
| ArrayBuffer | ||
| SharedArrayBuffer | ||
| readonly unknown[] | ||
| readonly number[] | ||
| { valueOf(): ArrayBuffer } | ||
| { valueOf(): SharedArrayBuffer } | ||
| { valueOf(): Uint8Array } | ||
| { valueOf(): readonly number[] } | ||
| { valueOf(): string } | ||
| { [Symbol.toPrimitive](hint: string): string }, | ||
): unknown; | ||
close(): unknown; | ||
}; | ||
|
||
export type PolyfillWebSocketFactory = ( | ||
url: string, | ||
params?: unknown, | ||
) => PolyfillWebSocket; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.