joewalnes / reconnecting-websocket

A small decorator for the JavaScript WebSocket API that automatically reconnects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to set proxy?

Liang-YY opened this issue · comments

How to set proxy?

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 });