Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 1 | <?xml version = "1.0" encoding="utf-8" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
| 3 | "DTD/xhtml1-strict.dtd">
|
Jeff Burke | 92dd8e4 | 2012-12-08 11:40:31 -0800 | [diff] [blame] | 4 | <!--
|
| 5 | See COPYING for copyright and distribution information.
|
| 6 | -->
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 7 | <html xmlns = "http://www.w3.org/1999/xhtml">
|
| 8 | <meta charset="UTF-8">
|
| 9 |
|
| 10 | <head>
|
| 11 | <title>NDN Get via WebSocket</title>
|
| 12 |
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 13 | <script type="text/javascript" src="../build/ndn-js.js"></script>
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 14 |
|
| 15 | <script type="text/javascript">
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 16 | var ndn = new NDN();
|
Wentao Shang | 82854bd | 2012-12-27 14:14:41 -0800 | [diff] [blame] | 17 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 18 | var AsyncGetClosure = function AsyncGetClosure() {
|
| 19 | // Inherit from Closure.
|
| 20 | Closure.call(this);
|
| 21 | };
|
| 22 |
|
| 23 | AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
|
Wentao Shang | c0311e5 | 2012-12-03 10:38:23 -0800 | [diff] [blame] | 24 | //console.log("Closure.upcall() executed.");
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 25 | if (kind == Closure.UPCALL_FINAL) {
|
| 26 | // Do nothing.
|
| 27 | } else if (kind == Closure.UPCALL_CONTENT) {
|
Wentao Shang | fa24596 | 2012-12-25 20:26:26 -0800 | [diff] [blame] | 28 | console.log("Closure.upcall: content signature verification pass.");
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 29 | console.log("Host: " + ndn.host + ":" + ndn.port);
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 30 | var content = upcallInfo.contentObject;
|
Wentao Shang | 2b740e6 | 2012-12-07 00:02:53 -0800 | [diff] [blame] | 31 | //console.log(content.name);
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 32 | nameStr = escape(content.name.getName());
|
Wentao Shang | 2b740e6 | 2012-12-07 00:02:53 -0800 | [diff] [blame] | 33 | document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>";
|
| 34 | document.getElementById('content').innerHTML += "<p>Content buffer length: " + content.content.length + "</p>";
|
| 35 | //console.log("In callback, nameStr: " + nameStr);
|
| 36 | //console.log("In callback, content: ");
|
| 37 | //console.log(content);
|
| 38 | document.getElementById('content').innerHTML += contentObjectToHtml(content);
|
Wentao Shang | fa24596 | 2012-12-25 20:26:26 -0800 | [diff] [blame] | 39 | } else if (kind == Closure.UPCALL_CONTENT_BAD) {
|
Wentao Shang | edd4dea | 2013-01-19 16:55:11 -0800 | [diff] [blame] | 40 | var content = upcallInfo.contentObject;
|
Wentao Shang | fa24596 | 2012-12-25 20:26:26 -0800 | [diff] [blame] | 41 | console.log("Closure.upcall: content signature verification fail.");
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 42 | console.log("Host: " + ndn.host + ":" + ndn.port);
|
Wentao Shang | edd4dea | 2013-01-19 16:55:11 -0800 | [diff] [blame] | 43 | if (content.signature.signature)
|
| 44 | console.log("Signature: " + DataUtils.toHex(content.signature.signature).toLowerCase());
|
| 45 | if (content.signature.Witness)
|
| 46 | console.log("Witness: " + DataUtils.toHex(content.signature.Witness).toLowerCase());
|
Wentao Shang | c0311e5 | 2012-12-03 10:38:23 -0800 | [diff] [blame] | 47 | } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
|
Jeff Thompson | 1a1f3d4 | 2013-02-18 15:24:25 -0800 | [diff] [blame] | 48 | console.log("Closure.upcall called with interest time out. Re-expressing the interest.");
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 49 | console.log("Host: " + ndn.host + ":" + ndn.port);
|
Jeff Thompson | 1a1f3d4 | 2013-02-18 15:24:25 -0800 | [diff] [blame] | 50 | return Closure.RESULT_REEXPRESS;
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 51 | }
|
| 52 | return Closure.RESULT_OK;
|
| 53 | };
|
| 54 |
|
| 55 |
|
| 56 | function run() {
|
Jeff Thompson | 5b265a7 | 2012-11-12 01:13:08 -0800 | [diff] [blame] | 57 | ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure());
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 58 | }
|
| 59 |
|
| 60 | </script>
|
| 61 |
|
| 62 | </head>
|
| 63 | <body >
|
| 64 |
|
| 65 | <form>
|
| 66 | Please Enter an Interest:<br />
|
| 67 | <input id="interest" type="text" name="INTEREST" size="50" value="/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY" />
|
| 68 | </form>
|
| 69 |
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 70 | <button id="testBtn" onclick="run()">Fetch Content</button>
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 71 |
|
| 72 | <p id="content">Content: <br/></p>
|
| 73 |
|
| 74 | </body>
|
| 75 | </html>
|