blob: cb8a7c136444a8ffec974f8b23f3a80ce194156b [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();
Jeff Thompson5b265a72012-11-12 01:13:08 -080018 ndn.transport.connectWebSocket(ndn);
Jeff Thompson287a3182012-11-11 18:12:20 -080019
20 var AsyncPutClosure = function AsyncPutClosure() {
21 // Inherit from Closure.
22 Closure.call(this);
23 };
24
25 AsyncPutClosure.prototype.upcall = function(kind, upcallInfo) {
26 if (kind == Closure.UPCALL_FINAL) {
27 // Do nothing.
28 } else if (kind == Closure.UPCALL_INTEREST) {
Jeff Thompson287a3182012-11-11 18:12:20 -080029 console.log('AsyncPutClosure.upcall() called.');
30 var content = document.getElementById('content').value;
31 var interest = upcallInfo.interest;
Jeff Thompson5b265a72012-11-12 01:13:08 -080032 var nameStr = escape(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 Shangab9018d2012-12-18 11:35:45 -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 Thompson48ba4ff2012-11-12 01:23:13 -080049 var result = ndn.registerPrefix(new Name(contentName), new AsyncPutClosure());
Jeff Thompson287a3182012-11-11 18:12:20 -080050
51 document.getElementById('result').innerHTML = 'Content name \'' + contentName
52 +'\' published. Result: ' + result;
53 }
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>
73 <button onclick="run()">Publish Content</button>
74 </div>
75
76 <p id="result"></p>
77
78</body>
79</html>