blob: a8c0b66c60d67bcd03b6598afe63b1d7ebc96f3e [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">
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -07004<!--
Jeff Burke92dd8e42012-12-08 11:40:31 -08005 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>
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070013
14 <script type="text/javascript" src="../build/ndn-js.js"></script>
15
Jeff Thompson287a3182012-11-11 18:12:20 -080016 <script type="text/javascript">
17 var ndn = new NDN();
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070018
Jeff Thompson287a3182012-11-11 18:12:20 -080019 var AsyncPutClosure = function AsyncPutClosure() {
20 // Inherit from Closure.
21 Closure.call(this);
22 };
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070023
Jeff Thompson287a3182012-11-11 18:12:20 -080024 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();
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070033
Jeff Thompson287a3182012-11-11 18:12:20 -080034 var si = new SignedInfo();
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070035
Jeff Thompson2c580442013-07-31 11:51:18 -070036 var co = new ContentObject(new Name(nameStr), si, content);
Jeff Thompson287a3182012-11-11 18:12:20 -080037 co.sign();
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070038
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 };
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070044
45
Jeff Thompson287a3182012-11-11 18:12:20 -080046 function run() {
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070047 var contentName = document.getElementById('contentname').value;
48
Jeff Thompson589664b2013-01-26 19:07:08 -080049 ndn.registerPrefix(new Name(contentName), new AsyncPutClosure());
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070050
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 }
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070054
Jeff Thompson287a3182012-11-11 18:12:20 -080055 </script>
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070056
Jeff Thompson287a3182012-11-11 18:12:20 -080057</head>
58<body >
59 <form>
60 <div>
61 <p>Please Enter a Content Name:</p>
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070062
63 <input id="contentname" type="text" name="CONTENTNAME" value="/wentao.shang/regtest001" />
64
Jeff Thompson287a3182012-11-11 18:12:20 -080065 <p>Please Enter the Content:</p>
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070066
67 <textarea id="content" cols="40" rows="5" name="CONTENT" >This works!</textarea>
68
Jeff Thompson287a3182012-11-11 18:12:20 -080069 <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>
Alexander Afanasyev2a2c9d22013-03-13 16:21:32 -070075
Jeff Thompson287a3182012-11-11 18:12:20 -080076 <p id="result"></p>
77
78</body>
79</html>