Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing proxy parameters to ws without having WebSocket objects #2273

Open
1 task done
QuantumTaskForce opened this issue Jan 10, 2025 · 3 comments
Open
1 task done

Comments

@QuantumTaskForce
Copy link

Is there an existing issue for this?

  • I've searched for any related issues and avoided creating a duplicate issue.

Description

I'm building an app that relies on dydxprotocol link which itself relies on ws for websocket. But my app doesn't use ws explicitly so I cannot apply what's proposed on issue #1601

For example with Axios I could find a work around and feed it my proxy parameters because Axios proposes a field axios.defaults.httpsAgent.

Is there a similar parameter with ws? Or are there any trick to solve my situation?
Thanks!

ws version

8.14.2

Node.js Version

23.6.0

System

No response

Expected result

No response

Actual result

No response

Attachments

No response

@lpinca
Copy link
Member

lpinca commented Jan 12, 2025

I can't think of any way to do this without having access to the WebSocket object.

@QuantumTaskForce
Copy link
Author

What I tried so far is to add a WebSocket object in my code:

import { WebSocket } from "ws";
import { HttpsProxyAgent } from "https-proxy-agent";
const httpsAgent = new HttpsProxyAgent('http://my-proxy.com:1234');
const socket = new WebSocket('url', {agent: httpsAgent});

And in my package.json add an overridesection so my dydx module will use the same ws module I use in my code.

"overrides": {
  "@dydxprotocol/v4-client-js": {
    "ws": "$ws"
    }
}

My hope was that by inserting the httpAgent in the beginning it would apply to all further WebSocket objects, but it doesn't work. Do you know if it's possible to make it work this way?

@lpinca
Copy link
Member

lpinca commented Jan 13, 2025

No, because the WebSocket instance you create is not the same created by your dependency. The dependency should allow you to pass the options to the instance that it creates. There is no other way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants