Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame^] | 1 | |
| 2 | hostip = "127.0.0.1"; |
| 3 | |
| 4 | var AsyncGetClosure = function AsyncGetClosure() { |
| 5 | Closure.call(this); |
| 6 | }; |
| 7 | |
| 8 | AsyncGetClosure.prototype.upcall = function(kind, upcallInfo, tmp) { |
| 9 | if (kind == Closure.UPCALL_FINAL) { |
| 10 | // Do nothing. |
| 11 | } else if (kind == Closure.UPCALL_CONTENT) { |
| 12 | var content = upcallInfo.contentObject; |
| 13 | var nameStr = content.name.getName().split("/").slice(5,6); |
| 14 | |
| 15 | if (nameStr == "prefix") { |
| 16 | document.getElementById('prefixcontent').innerHTML = DataUtils.toString(content.content); |
| 17 | prefix(); |
| 18 | } else if (nameStr == "link") { |
| 19 | document.getElementById('linkcontent').innerHTML = DataUtils.toString(content.content); |
| 20 | link(); |
| 21 | } else { |
| 22 | var data = DataUtils.toString(content.content); |
| 23 | var obj = jQuery.parseJSON(data); |
| 24 | document.getElementById("lastupdated").innerHTML = obj.lastupdated; |
| 25 | document.getElementById("lastlog").innerHTML = obj.lastlog; |
| 26 | document.getElementById("lasttimestamp").innerHTML = obj.lasttimestamp; |
| 27 | } |
| 28 | } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) { |
| 29 | console.log("Closure.upcall called with interest time out."); |
| 30 | } |
| 31 | return Closure.RESULT_OK; |
| 32 | }; |
| 33 | |
| 34 | function getStatus(name) { |
| 35 | // Template interest to get the latest content. |
| 36 | var interest = new Interest("/tmp/"); |
| 37 | interest.childSelector = 1; |
| 38 | interest.interestLifetime = 4000; |
| 39 | |
| 40 | ndn.expressInterest(new Name("/ndn/memphis.edu/netlab/status/" + name), new AsyncGetClosure(), interest); |
| 41 | } |
| 42 | |
| 43 | // Calls to get the content data. |
| 44 | function begin() { |
| 45 | getStatus("metadata"); |
| 46 | getStatus("prefix"); |
| 47 | getStatus("link"); |
| 48 | } |
| 49 | |
| 50 | var ndn; |
| 51 | $(document).ready(function() { |
| 52 | $("#all").fadeIn(500); |
| 53 | var res = detect(); |
| 54 | |
| 55 | if (!res) { |
| 56 | $("#base").fadeOut(50); |
| 57 | $("#nosupport").fadeIn(500); |
| 58 | } |
| 59 | else { |
| 60 | openHandle = function() { console.log("NDN established"); }; |
| 61 | ndn = new NDN({host:hostip, onopen:openHandle}); |
| 62 | ndn.transport.connectWebSocket(ndn); |
| 63 | } |
| 64 | }); |
| 65 | |