blob: e019537b0b9b787a5df6453f8f1c8a72ffcfd806 [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">
Wentao Shang7eb8c402012-11-19 13:30:44 -080016 var ndn = new NDN({port:9696});
Jeff Thompson5b265a72012-11-12 01:13:08 -080017 ndn.transport.connectWebSocket(ndn);
Jeff Thompson287a3182012-11-11 18:12:20 -080018
Wentao Shang82854bd2012-12-27 14:14:41 -080019 ndn.onopen = function() {
20 document.getElementById("testBtn").disabled = false;
21 };
22
Jeff Thompson287a3182012-11-11 18:12:20 -080023 var AsyncGetClosure = function AsyncGetClosure() {
24 // Inherit from Closure.
25 Closure.call(this);
26 };
27
28 AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
Wentao Shangc0311e52012-12-03 10:38:23 -080029 //console.log("Closure.upcall() executed.");
Jeff Thompson287a3182012-11-11 18:12:20 -080030 if (kind == Closure.UPCALL_FINAL) {
31 // Do nothing.
32 } else if (kind == Closure.UPCALL_CONTENT) {
Wentao Shangfa245962012-12-25 20:26:26 -080033 console.log("Closure.upcall: content signature verification pass.");
Jeff Thompson287a3182012-11-11 18:12:20 -080034 var content = upcallInfo.contentObject;
Wentao Shang2b740e62012-12-07 00:02:53 -080035 //console.log(content.name);
Jeff Thompson287a3182012-11-11 18:12:20 -080036 nameStr = escape(content.name.getName());
Wentao Shang2b740e62012-12-07 00:02:53 -080037 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 Shangfa245962012-12-25 20:26:26 -080043 } else if (kind == Closure.UPCALL_CONTENT_BAD) {
44 console.log("Closure.upcall: content signature verification fail.");
Wentao Shangc0311e52012-12-03 10:38:23 -080045 } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
46 console.log("Closure.upcall called with interest time out.");
Jeff Thompson287a3182012-11-11 18:12:20 -080047 }
48 return Closure.RESULT_OK;
49 };
50
51
52 function run() {
Jeff Thompson5b265a72012-11-12 01:13:08 -080053 ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure());
Jeff Thompson287a3182012-11-11 18:12:20 -080054 }
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 Shang82854bd2012-12-27 14:14:41 -080066 <button id="testBtn" onclick="run()" disabled="disabled">Fetch Content</button>
Jeff Thompson287a3182012-11-11 18:12:20 -080067
68 <p id="content">Content: <br/></p>
69
70</body>
71</html>