re-add support for whisper 5

This commit is contained in:
Iuri Matias 2017-10-09 08:59:02 -04:00
parent 69fa1b24c3
commit 09db4eaa53
4 changed files with 338 additions and 276 deletions

View File

@ -444,22 +444,19 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
var self = this;
var ipfs;
if (provider === 'whisper') {
this.providerName = 'whisper'
this.currentMessages = EmbarkJS.Messages.Whisper;
if (typeof variable === 'undefined' && typeof(web3) === 'undefined') {
let provider;
if (options === undefined) {
provider = "localhost:8546";
} else {
provider = options.server + ':' + options.port;
}
if (this.isNewWeb3()) {
// TODO: add current Provider
self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider));
} else {
self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider));
}
let provider;
if (options === undefined) {
provider = "localhost:8546";
} else {
provider = options.server + ':' + options.port;
}
if (this.isNewWeb3()) {
self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider));
} else {
self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider));
}
console.log("getting whisper version");
self.getWhisperVersion(function(err, version) {
if (err) {
console.log("whisper not available");
@ -468,7 +465,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
self.currentMessages.web3.shh.newSymKey().then((id) => {self.currentMessages.symKeyID = id;});
self.currentMessages.web3.shh.newKeyPair().then((id) => {self.currentMessages.sig = id;});
} else {
console.log("this version of whisper is not supported yet; try a version of geth bellow 1.6.1");
console.log("this version of whisper in this node");
}
} else {
self.currentMessages.identity = self.currentMessages.web3.shh.newIdentity();
@ -476,6 +473,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
self.currentMessages.whisperVersion = self.currentMessages.web3.version.whisper;
});
} else if (provider === 'orbit') {
this.providerName = 'orbit'
this.currentMessages = EmbarkJS.Messages.Orbit;
if (options === undefined) {
ipfs = HaadIpfsApi('localhost', '5001');
@ -504,104 +502,108 @@ EmbarkJS.Messages.listenTo = function(options) {
EmbarkJS.Messages.Whisper = {};
EmbarkJS.Messages.Whisper.sendMessage = function(options) {
if (EmbarkJS.Messages.isNewWeb3()) {
var topics = options.topic || options.topics;
var data = options.data || options.payload;
var identity;
if (!EmbarkJS.Messages.isNewWeb3()) {
identity = options.identity || this.identity || web3.shh.newIdentity();
var ttl = options.ttl || 100;
var priority = options.priority || 1000;
var powTime = options.powTime || 3;
var powTarget = options.powTarget || 0.5;
if (topics === undefined) {
throw new Error("missing option: topic");
}
if (data === undefined) {
throw new Error("missing option: data");
}
topics = this.web3.utils.toHex(topics).slice(0, 10);
var payload = JSON.stringify(data);
let message = {
symKeyID: this.symKeyID, // encrypts using the sym key ID
sig: this.sig, // signs the message using the keyPair ID
ttl: ttl,
topic: topics,
payload: EmbarkJS.Utils.fromAscii(payload),
powTime: powTime,
powTarget: powTarget
};
this.web3.shh.post(message, function() { });
} else {
var topics = options.topic || options.topics;
var data = options.data || options.payload;
var identity = options.identity || this.identity || web3.shh.newIdentity();
var ttl = options.ttl || 100;
var priority = options.priority || 1000;
var _topics;
if (topics === undefined) {
throw new Error("missing option: topic");
throw new Error("missing option: topic");
}
if (data === undefined) {
throw new Error("missing option: data");
throw new Error("missing option: data");
}
if (EmbarkJS.Messages.isNewWeb3()) {
topics = this.web3.utils.toHex(topics).slice(0, 10);
if (typeof topics === 'string') {
_topics = [EmbarkJS.Utils.fromAscii(topics)];
} else {
if (typeof topics === 'string') {
_topics = [EmbarkJS.Utils.fromAscii(topics)];
} else {
// TODO: replace with es6 + babel;
for (var i = 0; i < topics.length; i++) {
_topics.push(EmbarkJS.Utils.fromAscii(topics[i]));
}
}
topics = _topics;
_topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t));
}
topics = _topics;
var payload = JSON.stringify(data);
var message;
if (EmbarkJS.Messages.isNewWeb3()) {
message = {
symKeyID: this.symKeyID, // encrypts using the sym key ID
sig: this.sig, // signs the message using the keyPair ID
ttl: 10,
topic: topics,
payload: EmbarkJS.Utils.fromAscii('hello'),
powTime: 3,
powTarget: 0.5
};
} else {
message = {
from: identity,
topics: topics,
payload: EmbarkJS.Utils.fromAscii(payload),
ttl: ttl,
priority: priority
};
}
message = {
from: identity,
topics: topics,
payload: EmbarkJS.Utils.fromAscii(payload),
ttl: ttl,
priority: priority
};
return this.web3.shh.post(message, function() {});
return EmbarkJS.Messages.currentMessages.web3.shh.post(message, function() { console.log("message sent") });
}
};
EmbarkJS.Messages.Whisper.listenTo = function(options) {
var topics = options.topic || options.topics;
var _topics = [];
var messageEvents = function() {
this.cb = function() {};
};
messageEvents.prototype.then = function(cb) {
this.cb = cb;
};
messageEvents.prototype.error = function(err) {
return err;
};
messageEvents.prototype.stop = function() {
this.filter.stopWatching();
};
if (EmbarkJS.Messages.isNewWeb3()) {
topics = [this.web3.utils.toHex(topics).slice(0, 10)];
} else {
if (typeof topics === 'string') {
_topics = [topics];
} else {
// TODO: replace with es6 + babel;
for (var i = 0; i < topics.length; i++) {
_topics.push(topics[i]);
}
}
topics = _topics;
}
var messageEvents = function() {
this.cb = function() {};
};
messageEvents.prototype.then = function(cb) {
this.cb = cb;
};
messageEvents.prototype.error = function(err) {
return err;
};
messageEvents.prototype.stop = function() {
this.filter.stopWatching();
};
var topics = options.topic || options.topics;
var _topics = [];
if (EmbarkJS.Messages.isNewWeb3()) {
let promise = new messageEvents();
// listenTo
if (typeof topics === 'string') {
topics = [this.web3.utils.toHex(topics).slice(0, 10)];
} else {
topics = topics.map((t) => this.web3.utils.toHex(t).slice(0, 10));
}
let filter = this.web3.shh.subscribe("messages", {
symKeyID: this.symKeyID,
topics: topics
symKeyID: this.symKeyID,
topics: topics
}).on('data', function(result) {
var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload));
var data;
@ -611,14 +613,40 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
//from: result.from,
time: result.timestamp
};
promise.cb(payload, data, result);
});
promise.filter = filter;
return promise;
} else {
var topics = options.topic || options.topics;
var _topics = [];
var messageEvents = function() {
this.cb = function() {};
};
messageEvents.prototype.then = function(cb) {
this.cb = cb;
};
messageEvents.prototype.error = function(err) {
return err;
};
messageEvents.prototype.stop = function() {
this.filter.stopWatching();
};
if (typeof topics === 'string') {
_topics = [topics];
} else {
_topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t));
}
topics = _topics;
var filterOptions = {
topics: topics
};
@ -645,7 +673,7 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
return promise;
}
};
}
EmbarkJS.Messages.Orbit = {};
@ -722,6 +750,10 @@ EmbarkJS.Utils = {
fromAscii: function(str) {
var _web3 = new Web3();
return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str);
},
toAscii: function(str) {
var _web3 = new Web3();
return _web3.utils.toAscii(str);
}
};

View File

@ -362,22 +362,19 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
var self = this;
var ipfs;
if (provider === 'whisper') {
this.providerName = 'whisper'
this.currentMessages = EmbarkJS.Messages.Whisper;
if (typeof variable === 'undefined' && typeof(web3) === 'undefined') {
let provider;
if (options === undefined) {
provider = "localhost:8546";
} else {
provider = options.server + ':' + options.port;
}
if (this.isNewWeb3()) {
// TODO: add current Provider
self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider));
} else {
self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider));
}
let provider;
if (options === undefined) {
provider = "localhost:8546";
} else {
provider = options.server + ':' + options.port;
}
if (this.isNewWeb3()) {
self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider));
} else {
self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider));
}
console.log("getting whisper version");
self.getWhisperVersion(function(err, version) {
if (err) {
console.log("whisper not available");
@ -386,7 +383,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
self.currentMessages.web3.shh.newSymKey().then((id) => {self.currentMessages.symKeyID = id;});
self.currentMessages.web3.shh.newKeyPair().then((id) => {self.currentMessages.sig = id;});
} else {
console.log("this version of whisper is not supported yet; try a version of geth bellow 1.6.1");
console.log("this version of whisper in this node");
}
} else {
self.currentMessages.identity = self.currentMessages.web3.shh.newIdentity();
@ -394,6 +391,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
self.currentMessages.whisperVersion = self.currentMessages.web3.version.whisper;
});
} else if (provider === 'orbit') {
this.providerName = 'orbit'
this.currentMessages = EmbarkJS.Messages.Orbit;
if (options === undefined) {
ipfs = HaadIpfsApi('localhost', '5001');
@ -422,104 +420,108 @@ EmbarkJS.Messages.listenTo = function(options) {
EmbarkJS.Messages.Whisper = {};
EmbarkJS.Messages.Whisper.sendMessage = function(options) {
if (EmbarkJS.Messages.isNewWeb3()) {
var topics = options.topic || options.topics;
var data = options.data || options.payload;
var identity;
if (!EmbarkJS.Messages.isNewWeb3()) {
identity = options.identity || this.identity || web3.shh.newIdentity();
var ttl = options.ttl || 100;
var priority = options.priority || 1000;
var powTime = options.powTime || 3;
var powTarget = options.powTarget || 0.5;
if (topics === undefined) {
throw new Error("missing option: topic");
}
if (data === undefined) {
throw new Error("missing option: data");
}
topics = this.web3.utils.toHex(topics).slice(0, 10);
var payload = JSON.stringify(data);
let message = {
symKeyID: this.symKeyID, // encrypts using the sym key ID
sig: this.sig, // signs the message using the keyPair ID
ttl: ttl,
topic: topics,
payload: EmbarkJS.Utils.fromAscii(payload),
powTime: powTime,
powTarget: powTarget
};
this.web3.shh.post(message, function() { });
} else {
var topics = options.topic || options.topics;
var data = options.data || options.payload;
var identity = options.identity || this.identity || web3.shh.newIdentity();
var ttl = options.ttl || 100;
var priority = options.priority || 1000;
var _topics;
if (topics === undefined) {
throw new Error("missing option: topic");
throw new Error("missing option: topic");
}
if (data === undefined) {
throw new Error("missing option: data");
throw new Error("missing option: data");
}
if (EmbarkJS.Messages.isNewWeb3()) {
topics = this.web3.utils.toHex(topics).slice(0, 10);
if (typeof topics === 'string') {
_topics = [EmbarkJS.Utils.fromAscii(topics)];
} else {
if (typeof topics === 'string') {
_topics = [EmbarkJS.Utils.fromAscii(topics)];
} else {
// TODO: replace with es6 + babel;
for (var i = 0; i < topics.length; i++) {
_topics.push(EmbarkJS.Utils.fromAscii(topics[i]));
}
}
topics = _topics;
_topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t));
}
topics = _topics;
var payload = JSON.stringify(data);
var message;
if (EmbarkJS.Messages.isNewWeb3()) {
message = {
symKeyID: this.symKeyID, // encrypts using the sym key ID
sig: this.sig, // signs the message using the keyPair ID
ttl: 10,
topic: topics,
payload: EmbarkJS.Utils.fromAscii('hello'),
powTime: 3,
powTarget: 0.5
};
} else {
message = {
from: identity,
topics: topics,
payload: EmbarkJS.Utils.fromAscii(payload),
ttl: ttl,
priority: priority
};
}
message = {
from: identity,
topics: topics,
payload: EmbarkJS.Utils.fromAscii(payload),
ttl: ttl,
priority: priority
};
return this.web3.shh.post(message, function() {});
return EmbarkJS.Messages.currentMessages.web3.shh.post(message, function() { console.log("message sent") });
}
};
EmbarkJS.Messages.Whisper.listenTo = function(options) {
var topics = options.topic || options.topics;
var _topics = [];
var messageEvents = function() {
this.cb = function() {};
};
messageEvents.prototype.then = function(cb) {
this.cb = cb;
};
messageEvents.prototype.error = function(err) {
return err;
};
messageEvents.prototype.stop = function() {
this.filter.stopWatching();
};
if (EmbarkJS.Messages.isNewWeb3()) {
topics = [this.web3.utils.toHex(topics).slice(0, 10)];
} else {
if (typeof topics === 'string') {
_topics = [topics];
} else {
// TODO: replace with es6 + babel;
for (var i = 0; i < topics.length; i++) {
_topics.push(topics[i]);
}
}
topics = _topics;
}
var messageEvents = function() {
this.cb = function() {};
};
messageEvents.prototype.then = function(cb) {
this.cb = cb;
};
messageEvents.prototype.error = function(err) {
return err;
};
messageEvents.prototype.stop = function() {
this.filter.stopWatching();
};
var topics = options.topic || options.topics;
var _topics = [];
if (EmbarkJS.Messages.isNewWeb3()) {
let promise = new messageEvents();
// listenTo
if (typeof topics === 'string') {
topics = [this.web3.utils.toHex(topics).slice(0, 10)];
} else {
topics = topics.map((t) => this.web3.utils.toHex(t).slice(0, 10));
}
let filter = this.web3.shh.subscribe("messages", {
symKeyID: this.symKeyID,
topics: topics
symKeyID: this.symKeyID,
topics: topics
}).on('data', function(result) {
var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload));
var data;
@ -529,14 +531,40 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
//from: result.from,
time: result.timestamp
};
promise.cb(payload, data, result);
});
promise.filter = filter;
return promise;
} else {
var topics = options.topic || options.topics;
var _topics = [];
var messageEvents = function() {
this.cb = function() {};
};
messageEvents.prototype.then = function(cb) {
this.cb = cb;
};
messageEvents.prototype.error = function(err) {
return err;
};
messageEvents.prototype.stop = function() {
this.filter.stopWatching();
};
if (typeof topics === 'string') {
_topics = [topics];
} else {
_topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t));
}
topics = _topics;
var filterOptions = {
topics: topics
};
@ -563,7 +591,7 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
return promise;
}
};
}
EmbarkJS.Messages.Orbit = {};
@ -640,6 +668,10 @@ EmbarkJS.Utils = {
fromAscii: function(str) {
var _web3 = new Web3();
return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str);
},
toAscii: function(str) {
var _web3 = new Web3();
return _web3.utils.toAscii(str);
}
};

View File

@ -288,8 +288,8 @@ result += "\n";
result += this.generateProvider(options.deployment);
result += this.generateContracts(options.useEmbarkJS, options.deployment);
//result += this.generateStorageInitialization(options.useEmbarkJS);
//result += this.generateCommunicationInitialization(options.useEmbarkJS);
result += this.generateStorageInitialization(options.useEmbarkJS);
result += this.generateCommunicationInitialization(options.useEmbarkJS);
return result;
}

View File

@ -47,80 +47,80 @@ $(document).ready(function() {
// automatic set if config/storage.json has "enabled": true and "provider": "ipfs"
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
//$("#storage .error").hide();
//EmbarkJS.Storage.setProvider('ipfs')
// .then(function(){
// console.log('Provider set to IPFS');
// EmbarkJS.Storage.ipfsConnection.ping()
// .then(function(){
// $("#status-storage").addClass('status-online');
// $("#storage-controls").show();
// })
// .catch(function(err) {
// if(err){
// console.log("IPFS Connection Error => " + err.message);
// $("#storage .error").show();
// $("#status-storage").addClass('status-offline');
// $("#storage-controls").hide();
// }
// });
// })
// .catch(function(err){
// console.log('Failed to set IPFS as Provider:', err.message);
// $("#storage .error").show();
// $("#status-storage").addClass('status-offline');
// $("#storage-controls").hide();
// });
$("#storage .error").hide();
EmbarkJS.Storage.setProvider('ipfs')
.then(function(){
console.log('Provider set to IPFS');
EmbarkJS.Storage.ipfsConnection.ping()
.then(function(){
$("#status-storage").addClass('status-online');
$("#storage-controls").show();
})
.catch(function(err) {
if(err){
console.log("IPFS Connection Error => " + err.message);
$("#storage .error").show();
$("#status-storage").addClass('status-offline');
$("#storage-controls").hide();
}
});
})
.catch(function(err){
console.log('Failed to set IPFS as Provider:', err.message);
$("#storage .error").show();
$("#status-storage").addClass('status-offline');
$("#storage-controls").hide();
});
//$("#storage button.setIpfsText").click(function() {
// var value = $("#storage input.ipfsText").val();
// EmbarkJS.Storage.saveText(value).then(function(hash) {
// $("span.textHash").html(hash);
// $("input.textHash").val(hash);
// addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
// })
// .catch(function(err) {
// if(err){
// console.log("IPFS saveText Error => " + err.message);
// }
// });
//});
$("#storage button.setIpfsText").click(function() {
var value = $("#storage input.ipfsText").val();
EmbarkJS.Storage.saveText(value).then(function(hash) {
$("span.textHash").html(hash);
$("input.textHash").val(hash);
addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
})
.catch(function(err) {
if(err){
console.log("IPFS saveText Error => " + err.message);
}
});
});
//$("#storage button.loadIpfsHash").click(function() {
// var value = $("#storage input.textHash").val();
// EmbarkJS.Storage.get(value).then(function(content) {
// $("span.ipfsText").html(content);
// addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
// })
// .catch(function(err) {
// if(err){
// console.log("IPFS get Error => " + err.message);
// }
// });
//});
$("#storage button.loadIpfsHash").click(function() {
var value = $("#storage input.textHash").val();
EmbarkJS.Storage.get(value).then(function(content) {
$("span.ipfsText").html(content);
addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
})
.catch(function(err) {
if(err){
console.log("IPFS get Error => " + err.message);
}
});
});
//$("#storage button.uploadFile").click(function() {
// var input = $("#storage input[type=file]");
// EmbarkJS.Storage.uploadFile(input).then(function(hash) {
// $("span.fileIpfsHash").html(hash);
// $("input.fileIpfsHash").val(hash);
// addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
// })
// .catch(function(err) {
// if(err){
// console.log("IPFS uploadFile Error => " + err.message);
// }
// });
//});
$("#storage button.uploadFile").click(function() {
var input = $("#storage input[type=file]");
EmbarkJS.Storage.uploadFile(input).then(function(hash) {
$("span.fileIpfsHash").html(hash);
$("input.fileIpfsHash").val(hash);
addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
})
.catch(function(err) {
if(err){
console.log("IPFS uploadFile Error => " + err.message);
}
});
});
//$("#storage button.loadIpfsFile").click(function() {
// var hash = $("#storage input.fileIpfsHash").val();
// var url = EmbarkJS.Storage.getUrl(hash);
// var link = '<a href="' + url + '" target="_blank">' + url + '</a>';
// $("span.ipfsFileUrl").html(link);
// $(".ipfsImage").attr('src', url);
// addToLog("#storage", "EmbarkJS.Storage.getUrl('" + hash + "')");
//});
$("#storage button.loadIpfsFile").click(function() {
var hash = $("#storage input.fileIpfsHash").val();
var url = EmbarkJS.Storage.getUrl(hash);
var link = '<a href="' + url + '" target="_blank">' + url + '</a>';
$("span.ipfsFileUrl").html(link);
$(".ipfsImage").attr('src', url);
addToLog("#storage", "EmbarkJS.Storage.getUrl('" + hash + "')");
});
});
@ -129,37 +129,35 @@ $(document).ready(function() {
// ===========================
$(document).ready(function() {
//$("#communication .error").hide();
//$("#communication .errorVersion").hide();
//web3.version.getWhisper(function(err, version) {
// if (err) {
// $("#communication .error").show();
// $("#communication-controls").hide();
// $("#status-communication").addClass('status-offline');
// } else if (version >= 5) {
// $("#communication .errorVersion").show();
// $("#communication-controls").hide();
// $("#status-communication").addClass('status-offline');
// } else {
// EmbarkJS.Messages.setProvider('whisper');
// $("#status-communication").addClass('status-online');
// }
//});
$("#communication .error").hide();
$("#communication .errorVersion").hide();
if (EmbarkJS.Messages.providerName === 'whisper') {
EmbarkJS.Messages.getWhisperVersion(function(err, version) {
if (err) {
$("#communication .error").show();
$("#communication-controls").hide();
$("#status-communication").addClass('status-offline');
} else {
EmbarkJS.Messages.setProvider('whisper');
$("#status-communication").addClass('status-online');
}
});
}
//$("#communication button.listenToChannel").click(function() {
// var channel = $("#communication .listen input.channel").val();
// $("#communication #subscribeList").append("<br> subscribed to " + channel + " now try sending a message");
// EmbarkJS.Messages.listenTo({topic: [channel]}).then(function(message) {
// $("#communication #messagesList").append("<br> channel: " + channel + " message: " + message);
// });
// addToLog("#communication", "EmbarkJS.Messages.listenTo({topic: ['" + channel + "']}).then(function(message) {})");
//});
$("#communication button.listenToChannel").click(function() {
var channel = $("#communication .listen input.channel").val();
$("#communication #subscribeList").append("<br> subscribed to " + channel + " now try sending a message");
EmbarkJS.Messages.listenTo({topic: [channel]}).then(function(message) {
$("#communication #messagesList").append("<br> channel: " + channel + " message: " + message);
});
addToLog("#communication", "EmbarkJS.Messages.listenTo({topic: ['" + channel + "']}).then(function(message) {})");
});
//$("#communication button.sendMessage").click(function() {
// var channel = $("#communication .send input.channel").val();
// var message = $("#communication .send input.message").val();
// EmbarkJS.Messages.sendMessage({topic: channel, data: message});
// addToLog("#communication", "EmbarkJS.Messages.sendMessage({topic: '" + channel + "', data: '" + message + "'})");
//});
$("#communication button.sendMessage").click(function() {
var channel = $("#communication .send input.channel").val();
var message = $("#communication .send input.message").val();
EmbarkJS.Messages.sendMessage({topic: channel, data: message});
addToLog("#communication", "EmbarkJS.Messages.sendMessage({topic: '" + channel + "', data: '" + message + "'})");
});
});