Skip to content

Commit 9cfc626

Browse files
magicdawndarrachequesne
authored andcommitted
[feature] add localAddress option (#487)
1 parent 8be5864 commit 9cfc626

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ Exposed as `eio` in the browser standalone build.
226226
- `onlyBinaryUpgrades` (`Boolean`): whether transport upgrades should be restricted to transports supporting binary data (`false`)
227227
- `requestTimeout` (`Number`): Timeout for xhr-polling requests in milliseconds (`0`)
228228
- `forceNode` (`Boolean`): Uses NodeJS implementation for websockets - even if there is a native Browser-Websocket available, which is preferred by default over the NodeJS implementation. (This is useful when using hybrid platforms like nw.js or electron) (`false`, NodeJS only)
229+
- `localAddress` (`String`): the local IP address to connect to
229230
- `send`
230231
- Sends a message to the server
231232
- **Parameters**

lib/socket.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ function Socket (uri, opts) {
100100
if (opts.extraHeaders && Object.keys(opts.extraHeaders).length > 0) {
101101
this.extraHeaders = opts.extraHeaders;
102102
}
103+
104+
if (opts.localAddress) {
105+
this.localAddress = opts.localAddress;
106+
}
103107
}
104108

105109
// set on handshake
@@ -186,7 +190,8 @@ Socket.prototype.createTransport = function (name) {
186190
rejectUnauthorized: this.rejectUnauthorized,
187191
perMessageDeflate: this.perMessageDeflate,
188192
extraHeaders: this.extraHeaders,
189-
forceNode: this.forceNode
193+
forceNode: this.forceNode,
194+
localAddress: this.localAddress
190195
});
191196

192197
return transport;

lib/transport.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function Transport (opts) {
4343

4444
// other options for Node.js client
4545
this.extraHeaders = opts.extraHeaders;
46+
this.localAddress = opts.localAddress;
4647
}
4748

4849
/**

lib/transports/websocket.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ WS.prototype.doOpen = function () {
103103
if (this.extraHeaders) {
104104
opts.headers = this.extraHeaders;
105105
}
106+
if (this.localAddress) {
107+
opts.localAddress = this.localAddress;
108+
}
106109

107110
try {
108111
this.ws = this.usingBrowserWebSocket ? new WebSocket(uri) : new WebSocket(uri, protocols, opts);

0 commit comments

Comments
 (0)