Allow "offline mode" without Pubsub (for testing)

This commit is contained in:
haad
2016-03-03 14:58:03 +01:00
parent 7bec05fd81
commit c6c21023d3
2 changed files with 11 additions and 6 deletions

View File

@@ -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;
}
}

View File

@@ -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();