reconnecting-websocket icon indicating copy to clipboard operation
reconnecting-websocket copied to clipboard

How to set proxy?

Open Liang-YY opened this issue 2 years ago • 1 comments

How to set proxy?

Liang-YY avatar Jan 04 '23 09:01 Liang-YY

Maybe someone will find it useful

const HttpsProxyAgent = require("https-proxy-agent");
const WebSocket = require("ws");
const ReconnectingWebSocket = require("reconnecting-websocket");

const wsUrl = "wss://some.url";

const agent = new HttpsProxyAgent("http://ip:port");

class WebSocketWithAgent extends WebSocket {
    constructor(url, protocols) {
        super(url, protocols, {
            agent,
        });
    }
}

const ws = new ReconnectingWebSocket(wsUrl, [], { WebSocket: WebSocketWithAgent });

reme3d2y avatar Nov 03 '23 13:11 reme3d2y