Merge pull request #16 from rodneywitcher/master

WOLKJS handle in browser and out of browser
This commit is contained in:
Mitra Ardron 2019-03-27 15:27:39 -07:00 committed by GitHub
commit c044dba496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,13 @@
/* /*
This Transport layers uses Wolk NoSQL + Cloudstore. This Transport layers uses Wolk NoSQL + Cloudstore.
*/ */
var WOLK
const Url = require('url'); const Url = require('url');
const WOLK = require('wolkjs').WOLK; //TODO: change to just WOLK once we understand everything if( typeof window === 'undefined' ) {
WOLK = require("wolkjs").FS;
} else {
WOLK = require("wolkjs").WOLK;
}
const stringify = require('canonical-json'); const stringify = require('canonical-json');
const debug = require('debug')('dweb-transports:wolk'); const debug = require('debug')('dweb-transports:wolk');
@ -31,9 +36,8 @@ class TransportWOLK extends Transport {
connection(url) { connection(url) {
debug("connection call") debug("connection call")
var wolknode = new WOLK(); var wolknode = new WOLK();
//TODO: cloudstore connection needed return wolknode
return wolknode
} }
//stuff that happens b/f using ntwk bandwidth (config/connect/stuff) //stuff that happens b/f using ntwk bandwidth (config/connect/stuff)
@ -60,16 +64,19 @@ class TransportWOLK extends Transport {
debug("Account Created: [" + wolkName + "] hash: " + hash + " KEY: " + this.wolk.ecdsaKey) debug("Account Created: [" + wolkName + "] hash: " + hash + " KEY: " + this.wolk.ecdsaKey)
}) })
.catch( err => { .catch( err => {
throw new Error("Error Creating Account: " + err); throw new Error("Error Creating Account: " + err);
}) })
} }
})
.catch( (err) => {
throw new Error("Error Initializing Wolk: " + err);
}); });
try { try {
this.status = Transport.STATUS_STARTING; // Should display, but probably not refreshed in most case this.status = Transport.STATUS_STARTING; // Should display, but probably not refreshed in most case
if (cb) cb(this); if (cb) cb(this);
await this.p_status(); await this.p_status();
} catch(err) { } catch(err) {
console.error(this.name, "failed to start" ,err);
this.status = Transport.STATUS_FAILED; this.status = Transport.STATUS_FAILED;
} }
if (cb) cb(this); if (cb) cb(this);
@ -130,6 +137,7 @@ class TransportWOLK extends Transport {
} }
async p_rawfetch(url) { async p_rawfetch(url) {
//TODO: use this.wolk.parseWolkUrl eventually
var wolkurl = this.parseWolkUrl(url) var wolkurl = this.parseWolkUrl(url)
/* /*
console.log("WOLK p_rawfetch url: " + JSON.stringify(wolkurl)); console.log("WOLK p_rawfetch url: " + JSON.stringify(wolkurl));