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">
|
Jeff Burke | 92dd8e4 | 2012-12-08 11:40:31 -0800 | [diff] [blame] | 4 | <!--
|
| 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>
|
| 13 |
|
Wentao Shang | 0e291c8 | 2012-12-02 23:36:29 -0800 | [diff] [blame] | 14 | <script type="text/javascript" src="../tools/build/ndn-js.js"></script>
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 15 |
|
| 16 | <script type="text/javascript">
|
| 17 | var ndn = new NDN();
|
Jeff Thompson | 5b265a7 | 2012-11-12 01:13:08 -0800 | [diff] [blame] | 18 | ndn.transport.connectWebSocket(ndn);
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 19 |
|
| 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 Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 29 | console.log('AsyncPutClosure.upcall() called.');
|
| 30 | var content = document.getElementById('content').value;
|
| 31 | var interest = upcallInfo.interest;
|
Jeff Thompson | 5b265a7 | 2012-11-12 01:13:08 -0800 | [diff] [blame] | 32 | var nameStr = escape(interest.name.getName());
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 33 |
|
| 34 | var si = new SignedInfo();
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 35 |
|
Wentao Shang | ab9018d | 2012-12-18 11:35:45 -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();
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [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 | };
|
| 44 |
|
| 45 |
|
| 46 | function run() {
|
| 47 | var contentName = document.getElementById('contentname').value;
|
| 48 |
|
Jeff Thompson | 48ba4ff | 2012-11-12 01:23:13 -0800 | [diff] [blame] | 49 | var result = ndn.registerPrefix(new Name(contentName), new AsyncPutClosure());
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 50 |
|
| 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> |