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 |
|
Wentao Shang | 0e291c8 | 2012-12-02 23:36:29 -0800 | [diff] [blame] | 13 | <script type="text/javascript" src="../tools/build/ndn-js.js"></script>
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 14 |
|
| 15 | <script type="text/javascript">
|
Wentao Shang | 7eb8c40 | 2012-11-19 13:30:44 -0800 | [diff] [blame] | 16 | var ndn = new NDN({port:9696});
|
Jeff Thompson | 5b265a7 | 2012-11-12 01:13:08 -0800 | [diff] [blame] | 17 | ndn.transport.connectWebSocket(ndn);
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 18 |
|
Wentao Shang | 82854bd | 2012-12-27 14:14:41 -0800 | [diff] [blame] | 19 | ndn.onopen = function() {
|
| 20 | document.getElementById("testBtn").disabled = false;
|
| 21 | };
|
| 22 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 23 | var AsyncGetClosure = function AsyncGetClosure() {
|
| 24 | // Inherit from Closure.
|
| 25 | Closure.call(this);
|
| 26 | };
|
| 27 |
|
| 28 | AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
|
Wentao Shang | c0311e5 | 2012-12-03 10:38:23 -0800 | [diff] [blame] | 29 | //console.log("Closure.upcall() executed.");
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 30 | if (kind == Closure.UPCALL_FINAL) {
|
| 31 | // Do nothing.
|
| 32 | } else if (kind == Closure.UPCALL_CONTENT) {
|
Wentao Shang | fa24596 | 2012-12-25 20:26:26 -0800 | [diff] [blame] | 33 | console.log("Closure.upcall: content signature verification pass.");
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 34 | var content = upcallInfo.contentObject;
|
Wentao Shang | 2b740e6 | 2012-12-07 00:02:53 -0800 | [diff] [blame] | 35 | //console.log(content.name);
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 36 | nameStr = escape(content.name.getName());
|
Wentao Shang | 2b740e6 | 2012-12-07 00:02:53 -0800 | [diff] [blame] | 37 | document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>";
|
| 38 | document.getElementById('content').innerHTML += "<p>Content buffer length: " + content.content.length + "</p>";
|
| 39 | //console.log("In callback, nameStr: " + nameStr);
|
| 40 | //console.log("In callback, content: ");
|
| 41 | //console.log(content);
|
| 42 | document.getElementById('content').innerHTML += contentObjectToHtml(content);
|
Wentao Shang | fa24596 | 2012-12-25 20:26:26 -0800 | [diff] [blame] | 43 | } else if (kind == Closure.UPCALL_CONTENT_BAD) {
|
| 44 | console.log("Closure.upcall: content signature verification fail.");
|
Wentao Shang | c0311e5 | 2012-12-03 10:38:23 -0800 | [diff] [blame] | 45 | } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
|
| 46 | console.log("Closure.upcall called with interest time out.");
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 47 | }
|
| 48 | return Closure.RESULT_OK;
|
| 49 | };
|
| 50 |
|
| 51 |
|
| 52 | function run() {
|
Jeff Thompson | 5b265a7 | 2012-11-12 01:13:08 -0800 | [diff] [blame] | 53 | ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure());
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 54 | }
|
| 55 |
|
| 56 | </script>
|
| 57 |
|
| 58 | </head>
|
| 59 | <body >
|
| 60 |
|
| 61 | <form>
|
| 62 | Please Enter an Interest:<br />
|
| 63 | <input id="interest" type="text" name="INTEREST" size="50" value="/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY" />
|
| 64 | </form>
|
| 65 |
|
Wentao Shang | 82854bd | 2012-12-27 14:14:41 -0800 | [diff] [blame] | 66 | <button id="testBtn" onclick="run()" disabled="disabled">Fetch Content</button>
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 67 |
|
| 68 | <p id="content">Content: <br/></p>
|
| 69 |
|
| 70 | </body>
|
| 71 | </html>
|