blob: 70b60a9fb8b2629ba35b88be8a95bb44e34a2bb8 [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
11<head>
12 <title>NDN Put via WebSocket</title>
13
Wentao Shang0e291c82012-12-02 23:36:29 -080014 <script type="text/javascript" src="../tools/build/ndn-js.js"></script>
Jeff Thompson287a3182012-11-11 18:12:20 -080015
16 <script type="text/javascript">
17 var ndn = new NDN();
Wentao Shang82854bd2012-12-27 14:14:41 -080018
Jeff Thompson287a3182012-11-11 18:12:20 -080019 var AsyncPutClosure = function AsyncPutClosure() {
20 // Inherit from Closure.
21 Closure.call(this);
22 };
23
24 AsyncPutClosure.prototype.upcall = function(kind, upcallInfo) {
25 if (kind == Closure.UPCALL_FINAL) {
26 // Do nothing.
27 } else if (kind == Closure.UPCALL_INTEREST) {
Jeff Thompson287a3182012-11-11 18:12:20 -080028 console.log('AsyncPutClosure.upcall() called.');
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 = document.getElementById('content').value;
31 var interest = upcallInfo.interest;
Wentao Shangf8b4a7d2012-12-25 12:52:07 -080032 var nameStr = interest.name.getName();
Jeff Thompson287a3182012-11-11 18:12:20 -080033
34 var si = new SignedInfo();
Jeff Thompson287a3182012-11-11 18:12:20 -080035
Wentao Shangf8b4a7d2012-12-25 12:52:07 -080036 var co = new ContentObject(new Name(nameStr), si, content, new Signature());
Jeff Thompson287a3182012-11-11 18:12:20 -080037 co.sign();
Jeff Thompson287a3182012-11-11 18:12:20 -080038
Wentao Shangab9018d2012-12-18 11:35:45 -080039 upcallInfo.contentObject = co;
Wentao Shangc05dc532012-11-19 12:00:33 -080040 return Closure.RESULT_INTEREST_CONSUMED;
Jeff Thompson287a3182012-11-11 18:12:20 -080041 }
42 return Closure.RESULT_OK;
43 };
44
45
46 function run() {
47 var contentName = document.getElementById('contentname').value;
48
Jeff Thompson589664b2013-01-26 19:07:08 -080049 ndn.registerPrefix(new Name(contentName), new AsyncPutClosure());
Jeff Thompson287a3182012-11-11 18:12:20 -080050
51 document.getElementById('result').innerHTML = 'Content name \'' + contentName
Jeff Thompson589664b2013-01-26 19:07:08 -080052 +'\' published.';
Jeff Thompson287a3182012-11-11 18:12:20 -080053 }
54
55 </script>
56
57</head>
58<body >
59 <form>
60 <div>
61 <p>Please Enter a Content Name:</p>
62
63 <input id="contentname" type="text" name="CONTENTNAME" value="/wentao.shang/regtest001" />
64
65 <p>Please Enter the Content:</p>
66
67 <textarea id="content" cols="40" rows="5" name="CONTENT" >This works!</textarea>
68
69 <br />
70 </div>
71 </form>
72 <div>
Jeff Thompson589664b2013-01-26 19:07:08 -080073 <button id="testBtn" onclick="run()">Publish Content</button>
Jeff Thompson287a3182012-11-11 18:12:20 -080074 </div>
75
76 <p id="result"></p>
77
78</body>
79</html>