mirror of https://github.com/embarklabs/embark.git
extract communication provider
This commit is contained in:
parent
9ca337eeb1
commit
8956992950
|
@ -213,7 +213,7 @@ class CodeGenerator {
|
||||||
let pluginsWithCode = this.plugins.getPluginsFor('initCode');
|
let pluginsWithCode = this.plugins.getPluginsFor('initCode');
|
||||||
if (pluginsWithCode.length > 0) {
|
if (pluginsWithCode.length > 0) {
|
||||||
for (let plugin of pluginsWithCode) {
|
for (let plugin of pluginsWithCode) {
|
||||||
let initCodes = plugin.embarkjs_init_code.storage;
|
let initCodes = plugin.embarkjs_init_code.storage || [];
|
||||||
for (let initCode of initCodes) {
|
for (let initCode of initCodes) {
|
||||||
let [block, shouldInit] = initCode;
|
let [block, shouldInit] = initCode;
|
||||||
if (shouldInit.call(plugin, self.storageConfig)) {
|
if (shouldInit.call(plugin, self.storageConfig)) {
|
||||||
|
@ -235,20 +235,19 @@ class CodeGenerator {
|
||||||
// TODO: don't repeat this twice; should have 'requirements' generator first
|
// TODO: don't repeat this twice; should have 'requirements' generator first
|
||||||
result += Templates.define_when_env_loaded();
|
result += Templates.define_when_env_loaded();
|
||||||
|
|
||||||
let block;
|
let pluginsWithCode = this.plugins.getPluginsFor('initCode');
|
||||||
//if (self.communicationConfig.enabled === true && ['whisper', 'orbit'].indexOf(self.communicationConfig.provider) < 0) {
|
if (pluginsWithCode.length > 0) {
|
||||||
// //TODO: add logger; also make sure it would still work with a plugin provider
|
for (let plugin of pluginsWithCode) {
|
||||||
// self.logger.warn("unknown provider " + self.communicationConfig.provider);
|
let initCodes = plugin.embarkjs_init_code.communication || [];
|
||||||
//}
|
for (let initCode of initCodes) {
|
||||||
// TODO: refactor this
|
let [block, shouldInit] = initCode;
|
||||||
if (self.communicationConfig.enabled === true) {
|
if (shouldInit.call(plugin, self.communicationConfig)) {
|
||||||
if (self.communicationConfig.connection === undefined) {
|
result += Templates.exec_when_env_loaded({block: block});
|
||||||
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
}
|
||||||
} else {
|
}
|
||||||
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.connection.host + "', port: '" + self.communicationConfig.connection.port + "', type: '" + self.communicationConfig.connection.type + "'});";
|
|
||||||
}
|
}
|
||||||
result += Templates.exec_when_env_loaded({block: block});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Whisper {
|
||||||
|
|
||||||
this.setServiceCheck();
|
this.setServiceCheck();
|
||||||
this.addWhisperToEmbarkJS();
|
this.addWhisperToEmbarkJS();
|
||||||
|
this.addSetProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
setServiceCheck() {
|
setServiceCheck() {
|
||||||
|
@ -29,6 +30,7 @@ class Whisper {
|
||||||
}
|
}
|
||||||
|
|
||||||
addWhisperToEmbarkJS() {
|
addWhisperToEmbarkJS() {
|
||||||
|
// TODO: make this a shouldAdd condition
|
||||||
if (this.communicationConfig === {}) {
|
if (this.communicationConfig === {}) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +44,24 @@ class Whisper {
|
||||||
|
|
||||||
this.embark.addCodeToEmbarkJS(code);
|
this.embark.addCodeToEmbarkJS(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addSetProvider() {
|
||||||
|
let connection = this.communicationConfig.connection || {};
|
||||||
|
// todo: make the add code a function as well
|
||||||
|
let config = JSON.stringify({
|
||||||
|
server: connection.host || 'localhost',
|
||||||
|
port: connection.port || '8546',
|
||||||
|
type: connection.type || 'ws'
|
||||||
|
});
|
||||||
|
let code = "\nEmbarkJS.Messages.setProvider('whisper'," + config + ");";
|
||||||
|
|
||||||
|
let shouldInit = (communicationConfig) => {
|
||||||
|
return (communicationConfig.provider === 'whisper' && communicationConfig.enabled === true);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.embark.addProviderInit('communication', code, shouldInit);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Whisper;
|
module.exports = Whisper;
|
||||||
|
|
Loading…
Reference in New Issue