uweb/en/searchurl/globaljs/websocket.js
2024-03-17 10:36:18 +08:00

13 lines
408 B
JavaScript

window.WebSocketOriginal = window.WebSocket;
(function () {
function CustomWebSocket(url) {
const ws = new window.WebSocketOriginal(url);
Object.getOwnPropertyNames(window.WebSocket.prototype).forEach(methodName => {
if (methodName !== 'constructor') {
CustomWebSocket.prototype[methodName] = ws[methodName].bind(ws);
}
});
}
window.WebSocket = CustomWebSocket;
})();
t