blob: f69756a4272639252d7b90c82a1bbcb3a4f06a20 [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
Wentao Shang82854bd2012-12-27 14:14:41 -080020 ndn.onopen = function() {
21 document.getElementById("testBtn").disabled = false;
22 };
23
Jeff Thompson287a3182012-11-11 18:12:20 -080024 var AsyncPutClosure = function AsyncPutClosure() {
25 // Inherit from Closure.
26 Closure.call(this);
27 };
28
29 AsyncPutClosure.prototype.upcall = function(kind, upcallInfo) {
30 if (kind == Closure.UPCALL_FINAL) {
31 // Do nothing.
32 } else if (kind == Closure.UPCALL_INTEREST) {
Jeff Thompson287a3182012-11-11 18:12:20 -080033 console.log('AsyncPutClosure.upcall() called.');
34 var content = document.getElementById('content').value;
35 var interest = upcallInfo.interest;
Wentao Shangf8b4a7d2012-12-25 12:52:07 -080036 var nameStr = interest.name.getName();
Jeff Thompson287a3182012-11-11 18:12:20 -080037
38 var si = new SignedInfo();
Jeff Thompson287a3182012-11-11 18:12:20 -080039
Wentao Shangf8b4a7d2012-12-25 12:52:07 -080040 var co = new ContentObject(new Name(nameStr), si, content, new Signature());
Jeff Thompson287a3182012-11-11 18:12:20 -080041 co.sign();
Jeff Thompson287a3182012-11-11 18:12:20 -080042
Wentao Shangab9018d2012-12-18 11:35:45 -080043 upcallInfo.contentObject = co;
Wentao Shangc05dc532012-11-19 12:00:33 -080044 return Closure.RESULT_INTEREST_CONSUMED;
Jeff Thompson287a3182012-11-11 18:12:20 -080045 }
46 return Closure.RESULT_OK;
47 };
48
49
50 function run() {
51 var contentName = document.getElementById('contentname').value;
52
Jeff Thompson48ba4ff2012-11-12 01:23:13 -080053 var result = ndn.registerPrefix(new Name(contentName), new AsyncPutClosure());
Jeff Thompson287a3182012-11-11 18:12:20 -080054
55 document.getElementById('result').innerHTML = 'Content name \'' + contentName
56 +'\' published. Result: ' + result;
57 }
58
59 </script>
60
61</head>
62<body >
63 <form>
64 <div>
65 <p>Please Enter a Content Name:</p>
66
67 <input id="contentname" type="text" name="CONTENTNAME" value="/wentao.shang/regtest001" />
68
69 <p>Please Enter the Content:</p>
70
71 <textarea id="content" cols="40" rows="5" name="CONTENT" >This works!</textarea>
72
73 <br />
74 </div>
75 </form>
76 <div>
Wentao Shang82854bd2012-12-27 14:14:41 -080077 <button id="testBtn" onclick="run()" disabled="disabled">Publish Content</button>
Jeff Thompson287a3182012-11-11 18:12:20 -080078 </div>
79
80 <p id="result"></p>
81
82</body>
83</html>