blob: 79407c216bb5950274305fbd97a82424b6ebb78a [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
Wentao Shang0e291c82012-12-02 23:36:29 -080013 <script type="text/javascript" src="../tools/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) {
48 console.log("Closure.upcall called with interest time out.");
Jeff Thompson589664b2013-01-26 19:07:08 -080049 console.log("Host: " + ndn.host + ":" + ndn.port);
Jeff Thompson287a3182012-11-11 18:12:20 -080050 }
51 return Closure.RESULT_OK;
52 };
53
54
55 function run() {
Jeff Thompson5b265a72012-11-12 01:13:08 -080056 ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure());
Jeff Thompson287a3182012-11-11 18:12:20 -080057 }
58
59 </script>
60
61</head>
62<body >
63
64 <form>
65 Please Enter an Interest:<br />
66 <input id="interest" type="text" name="INTEREST" size="50" value="/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY" />
67 </form>
68
Jeff Thompson589664b2013-01-26 19:07:08 -080069 <button id="testBtn" onclick="run()">Fetch Content</button>
Jeff Thompson287a3182012-11-11 18:12:20 -080070
71 <p id="content">Content: <br/></p>
72
73</body>
74</html>