mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-20 02:58:05 +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) {
|
EmbarkJS.Messages.setProvider = function(provider, options) {
|
||||||
var self = this;
|
let providerObj = this.Providers[provider];
|
||||||
var ipfs;
|
|
||||||
if (provider === 'whisper') {
|
|
||||||
let providerObj = this.Providers[provider];
|
|
||||||
|
|
||||||
if (!providerObj) {
|
if (!providerObj) {
|
||||||
throw new Error('Unknown storage provider');
|
throw new Error('Unknown messages provider');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentMessages = providerObj;
|
this.currentMessages = providerObj;
|
||||||
|
|
||||||
return providerObj.setProvider(options);
|
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');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.sendMessage = function(options) {
|
EmbarkJS.Messages.sendMessage = function(options) {
|
||||||
|
@ -1,5 +1,21 @@
|
|||||||
EmbarkJS.Messages.Orbit = {};
|
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) {
|
EmbarkJS.Messages.Orbit.sendMessage = function(options) {
|
||||||
var topics = options.topic || options.topics;
|
var topics = options.topic || options.topics;
|
||||||
var data = options.data || options.payload;
|
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/ipfs.js')).toString();
|
||||||
code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/whisper.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.generateCommunicationInitialization(true);
|
||||||
code += this.generateStorageInitialization(true);
|
code += this.generateStorageInitialization(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user