Added new websocket files.
diff --git a/js/testing/test-encode-decode-ContentObject-bis.html b/js/testing/test-encode-decode-ContentObject-bis.html
index 4a8ee43..4bbebe4 100644
--- a/js/testing/test-encode-decode-ContentObject-bis.html
+++ b/js/testing/test-encode-decode-ContentObject-bis.html
@@ -36,6 +36,9 @@
<script type="text/javascript" src="../encoding/DataUtils.js"></script>
+ <script type="text/javascript" src="../encoding/EncodingUtils.js"></script>
+
+
<script language="JavaScript" type="text/javascript" src="../security/KeyManager.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/jsbn.js"></script>
@@ -58,7 +61,7 @@
<script type="text/javascript">
function encode(){
- var contentname = new Name( createNameArray(document.getElementById('contentname').value) );
+ var contentname = new Name( Name.createNameArray(document.getElementById('contentname').value) );
var content = document.getElementById('content').value;
@@ -119,21 +122,21 @@
output+= "<br />";
}
if(co.content !=null){
- output += "CONTENT(hex): "+ toHex(co.content);
+ output += "CONTENT(hex): "+ DataUtils.toHex(co.content);
output+= "<br />";
output+= "<br />";
}
if(co.signature !=null && co.signature.signature!=null){
- output += "SIGNATURE(hex): "+ toHex(co.signature.signature);
+ output += "SIGNATURE(hex): "+ DataUtils.toHex(co.signature.signature);
output+= "<br />";
output+= "<br />";
}
if(co.signedInfo !=null && co.signedInfo.publisher!=null && co.signedInfo.publisher.publisherPublicKeyDigest!=null){
- output += "Publisher Public Key Digest(hex): "+ toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
+ output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
output+= "<br />";
output+= "<br />";
@@ -148,10 +151,10 @@
if(co.signedInfo!=null && co.signedInfo.locator!=null && co.signedInfo.locator.publicKey!=null){
var publickey = rstr2b64(toString(co.signedInfo.locator.publicKey));
- var publickeyHex = toHex(co.signedInfo.locator.publicKey).toLowerCase();
+ var publickeyHex = DataUtils.toHex(co.signedInfo.locator.publicKey).toLowerCase();
var publickeyString = toString(co.signedInfo.locator.publicKey);
- var signature = toHex(co.signature.signature).toLowerCase();
+ var signature = DataUtils.toHex(co.signature.signature).toLowerCase();
var input = toString(co.rawSignatureData);
diff --git a/js/testing/test-get-async.html b/js/testing/test-get-async.html
new file mode 100644
index 0000000..fc7d84a
--- /dev/null
+++ b/js/testing/test-get-async.html
@@ -0,0 +1,56 @@
+<?xml version = "1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"DTD/xhtml1-strict.dtd">
+<html xmlns = "http://www.w3.org/1999/xhtml">
+<meta charset="UTF-8">
+
+<head>
+ <title>NDN Get via WebSocket</title>
+
+ <script type="text/javascript" src="../Helper.js"></script>
+
+ <script type="text/javascript">
+ var ndn = new NDN();
+ ndn.connectWebSocket();
+
+ var AsyncGetClosure = function AsyncGetClosure() {
+ // Inherit from Closure.
+ Closure.call(this);
+ };
+
+ AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
+ if (kind == Closure.UPCALL_FINAL) {
+ // Do nothing.
+ } else if (kind == Closure.UPCALL_CONTENT) {
+ console.log("Closure.upcall() executed.");
+ var content = upcallInfo.contentObject;
+ nameStr = escape(content.name.getName());
+ console.log("In callback, nameStr: " + nameStr);
+ console.log("In callback, content: ");
+ console.log(content);
+ document.getElementById('content').innerHTML = contentObjectToHtml(content);
+ }
+ return Closure.RESULT_OK;
+ };
+
+
+ function run() {
+ ndn.expressInterestWS(document.getElementById('interest').value, new AsyncGetClosure(), null);
+ }
+
+ </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 onclick="run()">Fetch Content</button>
+
+ <p id="content">Content: <br/></p>
+
+</body>
+</html>
diff --git a/js/testing/test-put-async.html b/js/testing/test-put-async.html
new file mode 100644
index 0000000..f94d2b6
--- /dev/null
+++ b/js/testing/test-put-async.html
@@ -0,0 +1,92 @@
+<?xml version = "1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"DTD/xhtml1-strict.dtd">
+<html xmlns = "http://www.w3.org/1999/xhtml">
+<meta charset="UTF-8">
+
+
+<head>
+ <title>NDN Put via WebSocket</title>
+
+ <script type="text/javascript" src="../Helper.js"></script>
+
+ <script type="text/javascript">
+ var ndn = new NDN();
+ ndn.connectWebSocket();
+
+ 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) {
+ // Extract the Name from the Interest. var name = upcallInfo.Interest.name;Íž
+ // Check that we want to respond to upcallInfo.interest. If yes, construct a ContentObject
+ // response, put it to the NDN and return Closure.RESULT_INTEREST_CONSUMED. Else fall
+ // through to return Content.RESULT_OK.
+ // See linemaker.py for more details.
+ console.log('AsyncPutClosure.upcall() called.');
+ var content = document.getElementById('content').value;
+ var interest = upcallInfo.interest;
+ nameStr = escape(interest.name.getName());
+
+ var si = new SignedInfo();
+ si.setFields();
+
+ var answer = DataUtils.toNumbersFromString(content);
+
+ var co = new ContentObject(new Name(nameStr), si, answer, new Signature());
+ co.sign();
+ var hex = encodeToHexContentObject(co);
+
+ var bytearray = new Uint8Array(hex.length / 2);
+ for (var i = 0; i < hex.length; i = i + 2) {
+ bytearray[i / 2] = '0x' + hex.substr(i, 2);
+ }
+
+ upcallInfo.ndn.ws.send(bytearray.buffer);
+ console.log('ws.send() finised.');
+
+ return Closure.RESULT_INTEREST_CONSUMED;
+ }
+ return Closure.RESULT_OK;
+ };
+
+
+ function run() {
+ var contentName = document.getElementById('contentname').value;
+
+ result = ndn.registerPrefixWS(contentName, new AsyncPutClosure(), null);
+
+ document.getElementById('result').innerHTML = 'Content name \'' + contentName
+ +'\' published. Result: ' + result;
+ }
+
+ </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 onclick="run()">Publish Content</button>
+ </div>
+
+ <p id="result"></p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/js/testing/test-websocket.html b/js/testing/test-websocket.html
new file mode 100644
index 0000000..d6530cb
--- /dev/null
+++ b/js/testing/test-websocket.html
@@ -0,0 +1,51 @@
+<?xml version = "1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"DTD/xhtml1-strict.dtd">
+<html xmlns = "http://www.w3.org/1999/xhtml">
+
+<head>
+ <title>Test WebSocket Support</title>
+
+ <script type="text/javascript">
+
+ function test(){
+ var output = "";
+
+ if ('WebSocket' in window) {
+ output += "This browser support WebSocket.";
+ } else {
+ output += "No WebSocket support.";
+ }
+
+ document.getElementById('result').innerHTML += output;
+
+ console.log("starting websocket...");
+ if ("WebSocket" in window) {
+ var ws = new WebSocket("ws://localhost:9696");
+
+ ws.onopen = function() {
+ console.log("WebSockets connection opened");
+ ws.send("Hello Server (from client).");
+ }
+ ws.onmessage = function(e) {
+ console.log("Got from server: " + e.data);
+ }
+ ws.onclose = function() {
+ console.log("WebSockets connection closed");
+ }
+ } else {
+ alert("No WebSockets support");
+ }
+
+ }
+
+ </script>
+
+</head>
+<body >
+ <button onclick="test()">Test Now!</button>
+
+ <p id="result">Result here: </p>
+
+</body>
+</html>