| <?xml version = "1.0" encoding="utf-8" ?> | |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
| "DTD/xhtml1-strict.dtd"> | |
| <!-- | |
| See COPYING for copyright and distribution information. | |
| --> | |
| <html xmlns = "http://www.w3.org/1999/xhtml"> | |
| <meta charset="UTF-8"> | |
| <head> | |
| <title>NDN Get via WebSocket</title> | |
| <script type="text/javascript" src="../tools/build/ndn-js.js"></script> | |
| <script type="text/javascript"> | |
| var ndn = new NDN(); | |
| var AsyncGetClosure = function AsyncGetClosure() { | |
| // Inherit from Closure. | |
| Closure.call(this); | |
| }; | |
| AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) { | |
| //console.log("Closure.upcall() executed."); | |
| if (kind == Closure.UPCALL_FINAL) { | |
| // Do nothing. | |
| } else if (kind == Closure.UPCALL_CONTENT) { | |
| console.log("Closure.upcall: content signature verification pass."); | |
| console.log("Host: " + ndn.host + ":" + ndn.port); | |
| var content = upcallInfo.contentObject; | |
| //console.log(content.name); | |
| nameStr = escape(content.name.getName()); | |
| document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>"; | |
| document.getElementById('content').innerHTML += "<p>Content buffer length: " + content.content.length + "</p>"; | |
| //console.log("In callback, nameStr: " + nameStr); | |
| //console.log("In callback, content: "); | |
| //console.log(content); | |
| document.getElementById('content').innerHTML += contentObjectToHtml(content); | |
| } else if (kind == Closure.UPCALL_CONTENT_BAD) { | |
| var content = upcallInfo.contentObject; | |
| console.log("Closure.upcall: content signature verification fail."); | |
| console.log("Host: " + ndn.host + ":" + ndn.port); | |
| if (content.signature.signature) | |
| console.log("Signature: " + DataUtils.toHex(content.signature.signature).toLowerCase()); | |
| if (content.signature.Witness) | |
| console.log("Witness: " + DataUtils.toHex(content.signature.Witness).toLowerCase()); | |
| } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) { | |
| console.log("Closure.upcall called with interest time out. Re-expressing the interest."); | |
| console.log("Host: " + ndn.host + ":" + ndn.port); | |
| return Closure.RESULT_REEXPRESS; | |
| } | |
| return Closure.RESULT_OK; | |
| }; | |
| function run() { | |
| ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure()); | |
| } | |
| </script> | |
| </head> | |
| <body > | |
| <form> | |
| Please Enter an Interest:<br /> | |
| <input id="interest" type="text" name="INTEREST" size="50" value="/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY" /> | |
| </form> | |
| <button id="testBtn" onclick="run()">Fetch Content</button> | |
| <p id="content">Content: <br/></p> | |
| </body> | |
| </html> |