git ssb

2+

Dominic / ssb-client



Commit 93989fb4f2182e5c9a2df88cc6f8dc7efb421a06

update to use latest pull-ws-server api

Dominic Tarr committed on 3/6/2015, 10:52:17 AM
Parent: 4062644a7f2a55d2f9039f4151d26d2d30c06bcf

Files changed

index.jschanged
index.jsView
@@ -26,43 +26,49 @@
2626 cb = addr, addr = null
2727
2828 addr = address(config || addr)
2929 if (wsStream) {
30- wsStream.socket.close()
30 + wsStream.close()
3131 client._emit('reconnecting')
3232 }
3333
34 + var called = false
35 +
3436 client.addr = addr
35- wsStream = ws.connect(addr)
36- rpcStream = client.createStream()
37- pull(wsStream, rpcStream, wsStream)
3837
39- var onopen_ = wsStream.socket.onopen
40- wsStream.socket.onopen = function() {
41- onopen_()
42- client._emit('connect')
38 + //if auth is not the first method called,
39 + //then the other methods will get auth errors.
40 + //since rpc calls are queued, we can just do it here.
41 + client.auth(function (err, authed) {
42 + if (err)
43 + client._emit('error', err)
44 + else
45 + client._emit('authed', authed)
46 + if(called) return
47 + called = true; cb && cb(err, authed)
48 + })
4349
44- client.auth(function (err, authed) {
45- if (err)
46- client._emit('error', err)
47- else
48- client._emit('authed', authed)
49- cb && cb(err, authed)
50- })
51- }
50 + wsStream = ws.connect(addr, {
51 + onOpen: function() {
52 + client._emit('connect')
53 + //cb is called after auth, just above
54 + },
55 + onClose: function() {
56 + client._emit('close')
57 + //rpcStream will detect close on it's own.
58 + if(called) return
59 + called = true; cb && cb(err, authed)
60 + }
61 + })
5262
53- var onclose_ = wsStream.socket.onclose
54- wsStream.socket.onclose = function() {
55- onclose_ && onclose_()
56- rpcStream.close(function(){})
57- client._emit('close')
58- }
63 + rpcStream = client.createStream()
64 + pull(wsStream, rpcStream, wsStream)
5965
6066 return client
6167 }
6268
6369 client.close = function(cb) {
64- wsStream.socket.close()
70 + wsStream.close()
6571 rpcStream.close(function () {
6672 cb && cb()
6773 })
6874 return client

Built with git-ssb-web