From e36fca383a648488f0a4dee3f3d9eac5e23ad2af Mon Sep 17 00:00:00 2001 From: Andy Nogueira Date: Fri, 17 Feb 2017 18:11:20 -0500 Subject: [PATCH] Implemented logic to detect if IPFS node is running or not and display online/offline status and error message in the demo app boilerplate --- demo/app/index.html | 11 ++++++----- demo/app/js/index.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/demo/app/index.html b/demo/app/index.html index 6544e05d..9dcde044 100644 --- a/demo/app/index.html +++ b/demo/app/index.html @@ -9,8 +9,8 @@
@@ -37,7 +37,8 @@
- note: You need to have an IPFS node running + +

Save text to IPFS

@@ -72,10 +73,10 @@

EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
- +
- +

Listen To channel

diff --git a/demo/app/js/index.js b/demo/app/js/index.js index 60147b1b..c430bbf9 100644 --- a/demo/app/js/index.js +++ b/demo/app/js/index.js @@ -30,6 +30,21 @@ $(document).ready(function() { $(document).ready(function() { EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}); + $("#storage .error").hide(); + 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(); + } + }); + $("#storage button.setIpfsText").click(function() { var value = $("#storage input.ipfsText").val(); EmbarkJS.Storage.saveText(value).then(function(hash) {