13 Commits

Author SHA1 Message Date
Zane Hitchcox
3e77509084 ensure replaced 'http' is at beginning of url or not replaced 2017-02-14 16:14:21 -05:00
d3x0r
a4425bda24 remove redundant option fetch
since options have to be fetched higher anyway... 
Or rather - this options is outside of knowing gun options
2016-12-23 00:43:05 -08:00
d3x0r
8dac820902 fix default assignment 2016-12-21 12:18:39 -08:00
d3x0r
8e6d827216 fix indentation 2016-12-21 12:17:56 -08:00
d3x0r
9c41182004 Fix quotes 2016-12-21 12:17:31 -08:00
d3x0r
320183fa54 Set default options more robustly 2016-12-21 12:17:01 -08:00
d3x0r
f28b62fd4c Setup default option
if wsc doesn't previosuly exist, create a empty option block.
add option 'protocols' for wsc that can specify the optional protocols before the options.
Options will also only apply to node client websockets; (package 'ws'), browser websockets only take 1 with 1 optional parameter (being the list of protocols to connect with; so I added that optional param for compatibility.
2016-12-21 12:09:10 -08:00
d3x0r
f548db293b pull opions from 'wsc' in gun options
'ws' options are used by server
'wsc' options to be used by websock client... ?
2016-12-21 11:59:28 -08:00
d3x0r
e8f840c548 pass gun's options to websocket
I recently had to set options given to the websocket client especially 

rejectUnauthorized {Boolean} Verify or not the server certificate.

for connecting to wss which are using self signed certs...
could also pass things like 'protocol' to differentiate a Gun websocket connection from some other websocket connection....

I don't know if maybe websock options should be a object in options instead ?  To avoid namespace collision?
2016-12-21 11:21:13 -08:00
Jesse Gibson
6a63b46d2b Add max reconnect backoff
Sockets will try to reconnect upon disconnection with an exponentially
rising backoff (configurable). However, if it's unbounded, at a certain
point does it need to even try? Probably not. Instead there's now a
`max` option that defaults to a minute, and the backoff will never
exceed that time.
2016-11-18 12:49:58 -07:00
Jesse Gibson
e402e3966e Optimistically open client sockets
Changes behavior from only opening sockets when absolutely necessary to
keeping them open for as long as possible. Key differences:
- Much higher success rate for messages sent from the connected server.
- Process no longer shuts down if nothing is done with gun, instead
  listens for incoming messages on client sockets.
Socket reconnect handle by Peer instances, meaning better handling for
deferred messages and predictable backoff.
The client.js logic has been significantly refactored. Among the
improvements, GET/PUT requests now respect the `peers` option for each
gun instance, only sending requests to the URLs listed.
2016-11-18 11:42:24 -07:00
Jesse Gibson
e8f8047cb6 Expose websocket events
The Peer "class" now extends EventEmitter. Listening to any websocket
events (e.g., "message", "close", "open", etc.) will not only subscribe
to the current websocket, but all future websockets. This provides a
much needed abstraction, since reconnection replaces the socket, which
would typically destroy your listeners.
2016-11-17 14:07:26 -07:00
Jesse Gibson
4cd2d434d1 Add websocket backoff/retry logic
New library handles websocket reconnection logic and queues messages
that were sent while offline.
2016-11-10 10:11:01 -07:00