Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 1 | <?xml version = "1.0" encoding="utf-8" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
| 3 | "DTD/xhtml1-strict.dtd">
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 4 | <!--
|
Jeff Burke | 92dd8e4 | 2012-12-08 11:40:31 -0800 | [diff] [blame] | 5 | See COPYING for copyright and distribution information.
|
| 6 | -->
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 7 | <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 Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 13 |
|
| 14 | <script type="text/javascript" src="../build/ndn-js.js"></script>
|
| 15 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 16 | <script type="text/javascript">
|
| 17 | var ndn = new NDN();
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 18 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 19 | var AsyncPutClosure = function AsyncPutClosure() {
|
| 20 | // Inherit from Closure.
|
| 21 | Closure.call(this);
|
| 22 | };
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 23 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 24 | AsyncPutClosure.prototype.upcall = function(kind, upcallInfo) {
|
| 25 | if (kind == Closure.UPCALL_FINAL) {
|
| 26 | // Do nothing.
|
| 27 | } else if (kind == Closure.UPCALL_INTEREST) {
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 28 | console.log('AsyncPutClosure.upcall() called.');
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 29 | console.log("Host: " + ndn.host + ":" + ndn.port);
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 30 | var content = document.getElementById('content').value;
|
| 31 | var interest = upcallInfo.interest;
|
Wentao Shang | f8b4a7d | 2012-12-25 12:52:07 -0800 | [diff] [blame] | 32 | var nameStr = interest.name.getName();
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 33 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 34 | var si = new SignedInfo();
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 35 |
|
Wentao Shang | f8b4a7d | 2012-12-25 12:52:07 -0800 | [diff] [blame] | 36 | var co = new ContentObject(new Name(nameStr), si, content, new Signature());
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 37 | co.sign();
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 38 |
|
Wentao Shang | ab9018d | 2012-12-18 11:35:45 -0800 | [diff] [blame] | 39 | upcallInfo.contentObject = co;
|
Wentao Shang | c05dc53 | 2012-11-19 12:00:33 -0800 | [diff] [blame] | 40 | return Closure.RESULT_INTEREST_CONSUMED;
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 41 | }
|
| 42 | return Closure.RESULT_OK;
|
| 43 | };
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 44 |
|
| 45 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 46 | function run() {
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 47 | var contentName = document.getElementById('contentname').value;
|
| 48 |
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 49 | ndn.registerPrefix(new Name(contentName), new AsyncPutClosure());
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 50 |
|
| 51 | document.getElementById('result').innerHTML = 'Content name \'' + contentName
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 52 | +'\' published.';
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 53 | }
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 54 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 55 | </script>
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 56 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 57 | </head>
|
| 58 | <body >
|
| 59 | <form>
|
| 60 | <div>
|
| 61 | <p>Please Enter a Content Name:</p>
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 62 |
|
| 63 | <input id="contentname" type="text" name="CONTENTNAME" value="/wentao.shang/regtest001" />
|
| 64 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 65 | <p>Please Enter the Content:</p>
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 66 |
|
| 67 | <textarea id="content" cols="40" rows="5" name="CONTENT" >This works!</textarea>
|
| 68 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 69 | <br />
|
| 70 | </div>
|
| 71 | </form>
|
| 72 | <div>
|
Jeff Thompson | 589664b | 2013-01-26 19:07:08 -0800 | [diff] [blame] | 73 | <button id="testBtn" onclick="run()">Publish Content</button>
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 74 | </div>
|
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 75 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 76 | <p id="result"></p>
|
| 77 |
|
| 78 | </body>
|
| 79 | </html> |