From c6c21023d30ff83ddda42d0be17c0e3c0e1edb53 Mon Sep 17 00:00:00 2001 From: haad Date: Thu, 3 Mar 2016 14:58:03 +0100 Subject: [PATCH] Allow "offline mode" without Pubsub (for testing) --- src/OrbitClient.js | 15 ++++++++++----- test/orbit-client-tests.js | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/OrbitClient.js b/src/OrbitClient.js index 27092f5..077bd5c 100644 --- a/src/OrbitClient.js +++ b/src/OrbitClient.js @@ -150,23 +150,28 @@ class OrbitDB { return true; } - _connect(host, port, username, password) { - this._pubsub = new PubSub(this._ipfs); - await(this._pubsub.connect(host, port, username, password)); + _connect(host, port, username, password, allowOffline) { + if(allowOffline === undefined) allowOffline = false; + try { + this._pubsub = new PubSub(this._ipfs); + await(this._pubsub.connect(host, port, username, password)); + } catch(e) { + if(!allowOffline) throw e; + } this.user = { username: username, id: 'TODO: user id' } this.network = { host: host, port: port, name: 'TODO: network name' } } } class OrbitClientFactory { - static connect(host, port, username, password, ipfs) { + static connect(host, port, username, password, allowOffline, ipfs) { if(!ipfs) { let ipfsd = await(ipfsDaemon()); ipfs = ipfsd.ipfs; } const client = new OrbitDB(ipfs); - await(client._connect(host, port, username, password)) + await(client._connect(host, port, username, password, allowOffline)) return client; } } diff --git a/test/orbit-client-tests.js b/test/orbit-client-tests.js index 80d58b0..8892def 100644 --- a/test/orbit-client-tests.js +++ b/test/orbit-client-tests.js @@ -21,7 +21,7 @@ describe('Orbit Client', function() { let channel = 'abcdefgh'; before(async((done) => { - client = OrbitClient.connect(host, port, username, password); + client = await(OrbitClient.connect(host, port, username, password, true)); db = client.channel(channel, '', false); db.delete(); done();