-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws.mjs
29 lines (23 loc) · 954 Bytes
/
ws.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const __WebSocket = typeof WebSocket === 'undefined' ? (await import('ws')).WebSocket : WebSocket;
// const WEBSOCKET ={
// CONNECTING : 0, // Socket has been created. The connection is not yet open.
// OPEN : 1, // The connection is open and ready to communicate.
// CLOSING : 2, // The connection is in the process of closing.
// CLOSED : 3, // The connection is closed or couldn't be opened.
// };
//
// Object.assign( __WebSocket, WEBSOCKET );
/*
* Polyfill for ws module which has no addEventHandler for some reason.
*/
if ( typeof (__WebSocket.prototype.addEventHandler) === 'undefined' ) {
// console.warn( 'WebSocket.prototype.addEventHandler === undefined' ) ;
__WebSocket.prototype.addEventHandler = function(...args) {
return this.on( ...args );
};
}
const __createWebSocket = (...args)=>new __WebSocket(...args);
export {
__WebSocket as WebSocket,
__createWebSocket as createWebSocket,
};