blob: d3fbdd6e76bc0bf2845ad0640375c7447897dfbb [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 Get via WebSocket</title>
<script type="text/javascript" src="../tools/build/ndn-js.js"></script>
<script type="text/javascript">
var ndn = new NDN({port:9696,host:"localhost"});
ndn.transport.connectWebSocket(ndn);
ndn.onopen = function() {
document.getElementById("testBtn").disabled = false;
};
var AsyncGetClosure = function AsyncGetClosure() {
// Inherit from Closure.
Closure.call(this);
};
AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
//console.log("Closure.upcall() executed.");
if (kind == Closure.UPCALL_FINAL) {
// Do nothing.
} else if (kind == Closure.UPCALL_CONTENT) {
console.log("Closure.upcall: content signature verification pass.");
var content = upcallInfo.contentObject;
//console.log(content.name);
nameStr = escape(content.name.getName());
document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>";
document.getElementById('content').innerHTML += "<p>Content buffer length: " + content.content.length + "</p>";
//console.log("In callback, nameStr: " + nameStr);
//console.log("In callback, content: ");
//console.log(content);
document.getElementById('content').innerHTML += contentObjectToHtml(content);
} else if (kind == Closure.UPCALL_CONTENT_BAD) {
var content = upcallInfo.contentObject;
console.log("Closure.upcall: content signature verification fail.");
if (content.signature.signature)
console.log("Signature: " + DataUtils.toHex(content.signature.signature).toLowerCase());
if (content.signature.Witness)
console.log("Witness: " + DataUtils.toHex(content.signature.Witness).toLowerCase());
} else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
console.log("Closure.upcall called with interest time out.");
}
return Closure.RESULT_OK;
};
function run() {
ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure());
}
</script>
</head>
<body >
<form>
Please Enter an Interest:<br />
<input id="interest" type="text" name="INTEREST" size="50" value="/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY" />
</form>
<button id="testBtn" onclick="run()" disabled="disabled">Fetch Content</button>
<p id="content">Content: <br/></p>
</body>
</html>