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,8 +444,8 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
var self = this; var self = this;
var ipfs; var ipfs;
if (provider === 'whisper') { if (provider === 'whisper') {
this.providerName = 'whisper'
this.currentMessages = EmbarkJS.Messages.Whisper; this.currentMessages = EmbarkJS.Messages.Whisper;
if (typeof variable === 'undefined' && typeof(web3) === 'undefined') {
let provider; let provider;
if (options === undefined) { if (options === undefined) {
provider = "localhost:8546"; provider = "localhost:8546";
@ -453,13 +453,10 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
provider = options.server + ':' + options.port; provider = options.server + ':' + options.port;
} }
if (this.isNewWeb3()) { if (this.isNewWeb3()) {
// TODO: add current Provider
self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider)); self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider));
} else { } else {
self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider)); self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider));
} }
}
console.log("getting whisper version");
self.getWhisperVersion(function(err, version) { self.getWhisperVersion(function(err, version) {
if (err) { if (err) {
console.log("whisper not available"); 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.newSymKey().then((id) => {self.currentMessages.symKeyID = id;});
self.currentMessages.web3.shh.newKeyPair().then((id) => {self.currentMessages.sig = id;}); self.currentMessages.web3.shh.newKeyPair().then((id) => {self.currentMessages.sig = id;});
} else { } 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 { } else {
self.currentMessages.identity = self.currentMessages.web3.shh.newIdentity(); 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; self.currentMessages.whisperVersion = self.currentMessages.web3.version.whisper;
}); });
} else if (provider === 'orbit') { } else if (provider === 'orbit') {
this.providerName = 'orbit'
this.currentMessages = EmbarkJS.Messages.Orbit; this.currentMessages = EmbarkJS.Messages.Orbit;
if (options === undefined) { if (options === undefined) {
ipfs = HaadIpfsApi('localhost', '5001'); ipfs = HaadIpfsApi('localhost', '5001');
@ -504,12 +502,41 @@ EmbarkJS.Messages.listenTo = function(options) {
EmbarkJS.Messages.Whisper = {}; EmbarkJS.Messages.Whisper = {};
EmbarkJS.Messages.Whisper.sendMessage = function(options) { EmbarkJS.Messages.Whisper.sendMessage = function(options) {
if (EmbarkJS.Messages.isNewWeb3()) {
var topics = options.topic || options.topics; var topics = options.topic || options.topics;
var data = options.data || options.payload; var data = options.data || options.payload;
var identity; var ttl = options.ttl || 100;
if (!EmbarkJS.Messages.isNewWeb3()) { var priority = options.priority || 1000;
identity = options.identity || this.identity || web3.shh.newIdentity(); 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 ttl = options.ttl || 100;
var priority = options.priority || 1000; var priority = options.priority || 1000;
var _topics; var _topics;
@ -522,34 +549,16 @@ EmbarkJS.Messages.Whisper.sendMessage = function(options) {
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);
} else {
if (typeof topics === 'string') { if (typeof topics === 'string') {
_topics = [EmbarkJS.Utils.fromAscii(topics)]; _topics = [EmbarkJS.Utils.fromAscii(topics)];
} else { } else {
// TODO: replace with es6 + babel; _topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t));
for (var i = 0; i < topics.length; i++) {
_topics.push(EmbarkJS.Utils.fromAscii(topics[i]));
}
} }
topics = _topics; topics = _topics;
}
var payload = JSON.stringify(data); var payload = JSON.stringify(data);
var message; 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 = { message = {
from: identity, from: identity,
topics: topics, topics: topics,
@ -557,12 +566,61 @@ EmbarkJS.Messages.Whisper.sendMessage = function(options) {
ttl: ttl, ttl: ttl,
priority: priority 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) { EmbarkJS.Messages.Whisper.listenTo = function(options) {
if (EmbarkJS.Messages.isNewWeb3()) {
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 = [];
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
}).on('data', function(result) {
var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload));
var data;
data = {
topic: result.topic,
data: payload,
//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 = options.topic || options.topics;
var _topics = []; var _topics = [];
@ -582,43 +640,13 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
this.filter.stopWatching(); this.filter.stopWatching();
}; };
if (EmbarkJS.Messages.isNewWeb3()) {
topics = [this.web3.utils.toHex(topics).slice(0, 10)];
} else {
if (typeof topics === 'string') { if (typeof topics === 'string') {
_topics = [topics]; _topics = [topics];
} else { } else {
// TODO: replace with es6 + babel; _topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t));
for (var i = 0; i < topics.length; i++) {
_topics.push(topics[i]);
}
} }
topics = _topics; topics = _topics;
}
if (EmbarkJS.Messages.isNewWeb3()) {
let promise = new messageEvents();
let filter = this.web3.shh.subscribe("messages", {
symKeyID: this.symKeyID,
topics: topics
}).on('data', function(result) {
var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload));
var data;
data = {
topic: result.topic,
data: payload,
//from: result.from,
time: result.timestamp
};
promise.cb(payload, data, result);
});
promise.filter = filter;
return promise;
} else {
var filterOptions = { var filterOptions = {
topics: topics topics: topics
}; };
@ -645,7 +673,7 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
return promise; return promise;
} }
}; }
EmbarkJS.Messages.Orbit = {}; EmbarkJS.Messages.Orbit = {};
@ -722,6 +750,10 @@ EmbarkJS.Utils = {
fromAscii: function(str) { fromAscii: function(str) {
var _web3 = new Web3(); var _web3 = new Web3();
return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str); 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,8 +362,8 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
var self = this; var self = this;
var ipfs; var ipfs;
if (provider === 'whisper') { if (provider === 'whisper') {
this.providerName = 'whisper'
this.currentMessages = EmbarkJS.Messages.Whisper; this.currentMessages = EmbarkJS.Messages.Whisper;
if (typeof variable === 'undefined' && typeof(web3) === 'undefined') {
let provider; let provider;
if (options === undefined) { if (options === undefined) {
provider = "localhost:8546"; provider = "localhost:8546";
@ -371,13 +371,10 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
provider = options.server + ':' + options.port; provider = options.server + ':' + options.port;
} }
if (this.isNewWeb3()) { if (this.isNewWeb3()) {
// TODO: add current Provider
self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider)); self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider));
} else { } else {
self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider)); self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider));
} }
}
console.log("getting whisper version");
self.getWhisperVersion(function(err, version) { self.getWhisperVersion(function(err, version) {
if (err) { if (err) {
console.log("whisper not available"); 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.newSymKey().then((id) => {self.currentMessages.symKeyID = id;});
self.currentMessages.web3.shh.newKeyPair().then((id) => {self.currentMessages.sig = id;}); self.currentMessages.web3.shh.newKeyPair().then((id) => {self.currentMessages.sig = id;});
} else { } 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 { } else {
self.currentMessages.identity = self.currentMessages.web3.shh.newIdentity(); 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; self.currentMessages.whisperVersion = self.currentMessages.web3.version.whisper;
}); });
} else if (provider === 'orbit') { } else if (provider === 'orbit') {
this.providerName = 'orbit'
this.currentMessages = EmbarkJS.Messages.Orbit; this.currentMessages = EmbarkJS.Messages.Orbit;
if (options === undefined) { if (options === undefined) {
ipfs = HaadIpfsApi('localhost', '5001'); ipfs = HaadIpfsApi('localhost', '5001');
@ -422,12 +420,41 @@ EmbarkJS.Messages.listenTo = function(options) {
EmbarkJS.Messages.Whisper = {}; EmbarkJS.Messages.Whisper = {};
EmbarkJS.Messages.Whisper.sendMessage = function(options) { EmbarkJS.Messages.Whisper.sendMessage = function(options) {
if (EmbarkJS.Messages.isNewWeb3()) {
var topics = options.topic || options.topics; var topics = options.topic || options.topics;
var data = options.data || options.payload; var data = options.data || options.payload;
var identity; var ttl = options.ttl || 100;
if (!EmbarkJS.Messages.isNewWeb3()) { var priority = options.priority || 1000;
identity = options.identity || this.identity || web3.shh.newIdentity(); 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 ttl = options.ttl || 100;
var priority = options.priority || 1000; var priority = options.priority || 1000;
var _topics; var _topics;
@ -440,34 +467,16 @@ EmbarkJS.Messages.Whisper.sendMessage = function(options) {
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);
} else {
if (typeof topics === 'string') { if (typeof topics === 'string') {
_topics = [EmbarkJS.Utils.fromAscii(topics)]; _topics = [EmbarkJS.Utils.fromAscii(topics)];
} else { } else {
// TODO: replace with es6 + babel; _topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t));
for (var i = 0; i < topics.length; i++) {
_topics.push(EmbarkJS.Utils.fromAscii(topics[i]));
}
} }
topics = _topics; topics = _topics;
}
var payload = JSON.stringify(data); var payload = JSON.stringify(data);
var message; 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 = { message = {
from: identity, from: identity,
topics: topics, topics: topics,
@ -475,12 +484,61 @@ EmbarkJS.Messages.Whisper.sendMessage = function(options) {
ttl: ttl, ttl: ttl,
priority: priority 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) { EmbarkJS.Messages.Whisper.listenTo = function(options) {
if (EmbarkJS.Messages.isNewWeb3()) {
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 = [];
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
}).on('data', function(result) {
var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload));
var data;
data = {
topic: result.topic,
data: payload,
//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 = options.topic || options.topics;
var _topics = []; var _topics = [];
@ -500,43 +558,13 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
this.filter.stopWatching(); this.filter.stopWatching();
}; };
if (EmbarkJS.Messages.isNewWeb3()) {
topics = [this.web3.utils.toHex(topics).slice(0, 10)];
} else {
if (typeof topics === 'string') { if (typeof topics === 'string') {
_topics = [topics]; _topics = [topics];
} else { } else {
// TODO: replace with es6 + babel; _topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t));
for (var i = 0; i < topics.length; i++) {
_topics.push(topics[i]);
}
} }
topics = _topics; topics = _topics;
}
if (EmbarkJS.Messages.isNewWeb3()) {
let promise = new messageEvents();
let filter = this.web3.shh.subscribe("messages", {
symKeyID: this.symKeyID,
topics: topics
}).on('data', function(result) {
var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload));
var data;
data = {
topic: result.topic,
data: payload,
//from: result.from,
time: result.timestamp
};
promise.cb(payload, data, result);
});
promise.filter = filter;
return promise;
} else {
var filterOptions = { var filterOptions = {
topics: topics topics: topics
}; };
@ -563,7 +591,7 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
return promise; return promise;
} }
}; }
EmbarkJS.Messages.Orbit = {}; EmbarkJS.Messages.Orbit = {};
@ -640,6 +668,10 @@ EmbarkJS.Utils = {
fromAscii: function(str) { fromAscii: function(str) {
var _web3 = new Web3(); var _web3 = new Web3();
return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str); 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.generateProvider(options.deployment);
result += this.generateContracts(options.useEmbarkJS, options.deployment); result += this.generateContracts(options.useEmbarkJS, options.deployment);
//result += this.generateStorageInitialization(options.useEmbarkJS); result += this.generateStorageInitialization(options.useEmbarkJS);
//result += this.generateCommunicationInitialization(options.useEmbarkJS); result += this.generateCommunicationInitialization(options.useEmbarkJS);
return result; return result;
} }

View File

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