hyperswarm-proxy-ws
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -6,3 +6,3 @@ const HyperswarmProxyClient = require('hyperswarm-proxy/client') | ||
const LOCAL_PROXY = `ws://localhost:${DEFAULT_PORT}` | ||
const DEFAULT_PROXY = LOCAL_PROXY | ||
const DEFAULT_PROXY = [LOCAL_PROXY] | ||
const DEFAULT_RECONNECT_DELAY = 1000 | ||
@@ -16,5 +16,8 @@ | ||
this.proxy = proxy | ||
this.reconnectDelay = reconnectDelay | ||
this.proxy = null | ||
this._urls = typeof proxy === 'string' ? [proxy] : proxy | ||
this._urlIndex = 0 | ||
this.reconnect() | ||
@@ -24,2 +27,4 @@ } | ||
reconnect () { | ||
this._nextUrl(); | ||
const localSocket = websocket(LOCAL_PROXY) | ||
@@ -49,4 +54,9 @@ | ||
} | ||
_nextUrl() { | ||
this.proxy = this._urls[this._urlIndex++ % this._urls.length] | ||
return this.proxy | ||
} | ||
} | ||
module.exports = HyperswarmProxyWSClient |
{ | ||
"name": "hyperswarm-proxy-ws", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Proxy hyperswarm connections over websockets with auto-reconnect logic", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,4 +29,4 @@ # hyperswarm-proxy-ws | ||
const swarm = new HyperswarmClient({ | ||
// Specify the proxy server to connect to | ||
proxy: 'ws://127.0.0.1:3472' | ||
// Specify a list of proxy servers available to connect to | ||
proxy: ['ws://127.0.0.1:3472'] | ||
}) | ||
@@ -33,0 +33,0 @@ |
@@ -14,3 +14,3 @@ const hyperswarm = require('@hyperswarm/network') | ||
t.plan(4) | ||
t.plan(5) | ||
@@ -31,3 +31,6 @@ try { | ||
const swarm = new Client({ | ||
proxy | ||
proxy: [ | ||
'ws://localhost:4000', // wrong url | ||
proxy, | ||
] | ||
}) | ||
@@ -72,2 +75,4 @@ | ||
t.equal(swarm.proxy, proxy, 'should use the working proxy') | ||
t.deepEqual(info.peer.topic, TEST_TOPIC, 'got connection in client') | ||
@@ -74,0 +79,0 @@ connection.on('data', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7624
155