var date, interval, tada = new Audio('http://soundbible.com/grab.php?id=2084&type=mp3'); function setDate(timestamp) { date = new Date(Date.UTC(2013, 10, 24, 12, 0, 0, 0) + timestamp * 1000); clearInterval(interval); setInterval(update, 5000); update(); } function update() { $('#d').text($.timeago(date)); } var socket = new FIMKSocket("wss://cloud.mofowallet.org:7986/ws/"); socket.ready(function () { /* Get the initial blockchain height and time */ socket.getBlockchainState(null, function (data) { $('#h').text(data.height); setDate(data.timestamp); tada.play(); }); /* Listen for new blocks */ socket.subscribe("blockPushed", function (data) { $('#h').text(data.height); setDate(data.timestamp); tada.play(); }); });
<div class="row"> <div class="col-xs-12"> <h3>FIMK WebSocket Widget</h3> <span class="text-muted">Current block is at height</span> <span id="h"></span><br> <span class="text-muted">This block arrived</span> <span id="d"></span><br> </div> </div>