mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 14:24:24 +00:00
refactor setProvider
This commit is contained in:
parent
6786b47e77
commit
24c34fcbe3
34
js/embark.js
34
js/embark.js
@ -228,37 +228,15 @@ EmbarkJS.Messages.registerProvider = function(providerName, obj) {
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.setProvider = function(provider, options) {
|
||||
var self = this;
|
||||
var ipfs;
|
||||
if (provider === 'whisper') {
|
||||
let providerObj = this.Providers[provider];
|
||||
let providerObj = this.Providers[provider];
|
||||
|
||||
if (!providerObj) {
|
||||
throw new Error('Unknown storage provider');
|
||||
}
|
||||
if (!providerObj) {
|
||||
throw new Error('Unknown messages provider');
|
||||
}
|
||||
|
||||
this.currentMessages = providerObj;
|
||||
this.currentMessages = providerObj;
|
||||
|
||||
return providerObj.setProvider(options);
|
||||
|
||||
} else if (provider === 'orbit') {
|
||||
|
||||
this.providerName = 'orbit';
|
||||
this.currentMessages = EmbarkJS.Messages.Orbit;
|
||||
if (options === undefined) {
|
||||
ipfs = HaadIpfsApi('localhost', '5001');
|
||||
} else {
|
||||
ipfs = HaadIpfsApi(options.host, options.port);
|
||||
}
|
||||
this.currentMessages.orbit = new Orbit(ipfs);
|
||||
if (typeof(web3) === "undefined") {
|
||||
this.currentMessages.orbit.connect(Math.random().toString(36).substring(2));
|
||||
} else {
|
||||
this.currentMessages.orbit.connect(web3.eth.accounts[0]);
|
||||
}
|
||||
} else {
|
||||
throw Error('Unknown message provider');
|
||||
}
|
||||
return providerObj.setProvider(options);
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.sendMessage = function(options) {
|
||||
|
@ -1,5 +1,21 @@
|
||||
EmbarkJS.Messages.Orbit = {};
|
||||
|
||||
EmbarkJS.Messages.Orbit.setProvider = function(options) {
|
||||
this.providerName = 'orbit';
|
||||
this.currentMessages = EmbarkJS.Messages.Orbit;
|
||||
if (options === undefined) {
|
||||
ipfs = HaadIpfsApi('localhost', '5001');
|
||||
} else {
|
||||
ipfs = HaadIpfsApi(options.host, options.port);
|
||||
}
|
||||
this.currentMessages.orbit = new Orbit(ipfs);
|
||||
if (typeof(web3) === "undefined") {
|
||||
this.currentMessages.orbit.connect(Math.random().toString(36).substring(2));
|
||||
} else {
|
||||
this.currentMessages.orbit.connect(web3.eth.accounts[0]);
|
||||
}
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.Orbit.sendMessage = function(options) {
|
||||
var topics = options.topic || options.topics;
|
||||
var data = options.data || options.payload;
|
||||
|
@ -293,7 +293,7 @@ class CodeGenerator {
|
||||
|
||||
code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/ipfs.js')).toString();
|
||||
code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/whisper.js')).toString();
|
||||
code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/orbit.js')).toString();
|
||||
//code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/orbit.js')).toString();
|
||||
|
||||
code += this.generateCommunicationInitialization(true);
|
||||
code += this.generateStorageInitialization(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user