blob: e3844e665eb6adc7b22e787249507be5b2e3acc5 [file] [log] [blame]
<?xml version = "1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<!--
See COPYING for copyright and distribution information.
-->
<html xmlns = "http://www.w3.org/1999/xhtml">
<meta charset="UTF-8">
<head>
<title>NDN Put via WebSocket</title>
<script type="text/javascript" src="../build/ndn-js.js"></script>
<script type="text/javascript">
var ndn = new NDN();
var AsyncPutClosure = function AsyncPutClosure() {
// Inherit from Closure.
Closure.call(this);
};
AsyncPutClosure.prototype.upcall = function(kind, upcallInfo) {
if (kind == Closure.UPCALL_FINAL) {
// Do nothing.
} else if (kind == Closure.UPCALL_INTEREST) {
console.log('AsyncPutClosure.upcall() called.');
console.log("Host: " + ndn.host + ":" + ndn.port);
var content = document.getElementById('content').value;
var interest = upcallInfo.interest;
var nameStr = interest.name.getName();
var si = new SignedInfo();
var co = new ContentObject(new Name(nameStr), si, content, new Signature());
co.sign();
upcallInfo.contentObject = co;
return Closure.RESULT_INTEREST_CONSUMED;
}
return Closure.RESULT_OK;
};
function run() {
var contentName = document.getElementById('contentname').value;
ndn.registerPrefix(new Name(contentName), new AsyncPutClosure());
document.getElementById('result').innerHTML = 'Content name \'' + contentName
+'\' published.';
}
</script>
</head>
<body >
<form>
<div>
<p>Please Enter a Content Name:</p>
<input id="contentname" type="text" name="CONTENTNAME" value="/wentao.shang/regtest001" />
<p>Please Enter the Content:</p>
<textarea id="content" cols="40" rows="5" name="CONTENT" >This works!</textarea>
<br />
</div>
</form>
<div>
<button id="testBtn" onclick="run()">Publish Content</button>
</div>
<p id="result"></p>
</body>
</html>