blob: ede20af546f7348881963687fcedaee33a9eb8ab [file] [log] [blame]
Jeff Thompson287a3182012-11-11 18:12:20 -08001<?xml version = "1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3"DTD/xhtml1-strict.dtd">
Jeff Burke92dd8e42012-12-08 11:40:31 -08004<!--
5 See COPYING for copyright and distribution information.
6-->
Jeff Thompson287a3182012-11-11 18:12:20 -08007<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 Afanasyev2a2c9d22013-03-13 16:21:32 -070013 <script type="text/javascript" src="../build/ndn-js.js"></script>
Jeff Thompson287a3182012-11-11 18:12:20 -080014
15 <script type="text/javascript">
Jeff Thompson589664b2013-01-26 19:07:08 -080016 var ndn = new NDN();
Wentao Shang82854bd2012-12-27 14:14:41 -080017
Jeff Thompson287a3182012-11-11 18:12:20 -080018 var AsyncGetClosure = function AsyncGetClosure() {
19 // Inherit from Closure.
20 Closure.call(this);
21 };
22
23 AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
Wentao Shangc0311e52012-12-03 10:38:23 -080024 //console.log("Closure.upcall() executed.");
Jeff Thompson287a3182012-11-11 18:12:20 -080025 if (kind == Closure.UPCALL_FINAL) {
26 // Do nothing.
27 } else if (kind == Closure.UPCALL_CONTENT) {
Wentao Shangfa245962012-12-25 20:26:26 -080028 console.log("Closure.upcall: content signature verification pass.");
Jeff Thompson589664b2013-01-26 19:07:08 -080029 console.log("Host: " + ndn.host + ":" + ndn.port);
Jeff Thompson287a3182012-11-11 18:12:20 -080030 var content = upcallInfo.contentObject;
Wentao Shang2b740e62012-12-07 00:02:53 -080031 //console.log(content.name);
Jeff Thompson287a3182012-11-11 18:12:20 -080032 nameStr = escape(content.name.getName());
Wentao Shang2b740e62012-12-07 00:02:53 -080033 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 Shangfa245962012-12-25 20:26:26 -080039 } else if (kind == Closure.UPCALL_CONTENT_BAD) {
Wentao Shangedd4dea2013-01-19 16:55:11 -080040 var content = upcallInfo.contentObject;
Wentao Shangfa245962012-12-25 20:26:26 -080041 console.log("Closure.upcall: content signature verification fail.");
Jeff Thompson589664b2013-01-26 19:07:08 -080042 console.log("Host: " + ndn.host + ":" + ndn.port);
Wentao Shangedd4dea2013-01-19 16:55:11 -080043 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 Shangc0311e52012-12-03 10:38:23 -080047 } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
Jeff Thompson1a1f3d42013-02-18 15:24:25 -080048 console.log("Closure.upcall called with interest time out. Re-expressing the interest.");
Jeff Thompson589664b2013-01-26 19:07:08 -080049 console.log("Host: " + ndn.host + ":" + ndn.port);
Jeff Thompson1a1f3d42013-02-18 15:24:25 -080050 return Closure.RESULT_REEXPRESS;
Jeff Thompson287a3182012-11-11 18:12:20 -080051 }
52 return Closure.RESULT_OK;
53 };
54
55
56 function run() {
Jeff Thompson5b265a72012-11-12 01:13:08 -080057 ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure());
Jeff Thompson287a3182012-11-11 18:12:20 -080058 }
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 Thompson589664b2013-01-26 19:07:08 -080070 <button id="testBtn" onclick="run()">Fetch Content</button>
Jeff Thompson287a3182012-11-11 18:12:20 -080071
72 <p id="content">Content: <br/></p>
73
74</body>
75</html>