UNPKG

ndn-js

Version:

A JavaScript client library for Named Data Networking

97 lines (83 loc) 3.45 kB
<?xml version = "1.0" encoding="utf-8" ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- * Copyright (C) 2014-2018 Regents of the University of California. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * A copy of the GNU Lesser General Public License is in the file COPYING. * * author: Chavoosh Ghasemi <chghasemi@cs.arizona.edu> --> <!-- This page uses SegmentFetcher to fetch any NDN segmented content via Fixed/Cubic pipeline. --> <head> <title>Use SegmentFetcher to fetch data via WebSocket</title> <script type="text/javascript" src="../../build/ndn.js"></script> <script type="text/javascript"> var face = new Face({host: "localhost"}); function onComplete(content) { console.log("onComplete called."); console.log("Host: " + face.connectionInfo.toString()); document.getElementById('content').innerHTML += "<p style='font-weight:bold; color:green;'>Successfully received the content"; document.getElementById('content').innerHTML += content.buf().toString('binary'); } function onTimeout(interest) { console.log("onTimeout called. Re-expressing the interest."); console.log("Host: " + face.connectionInfo.toString()); face.expressInterest(interest, onData, onTimeout); } function run() { if (document.getElementById('pipeline').value === "cubic") { SegmentFetcher.fetch (face, new Interest(document.getElementById('interest').value), null /*validator key*/, onComplete, function(errorCode, message) { console.log("Error " + errorCode + ": " + message); }, null /*pipeline type (default: Cubic) and its options*/ ); } else { SegmentFetcher.fetch (face, new Interest(document.getElementById('interest').value), null /*validator key*/, onComplete, function(errorCode, message) { console.log("Error " + errorCode + ": " + message); }, {pipeline: "fixed" /*pipeline type and its options*/, windowSize: 20, maxRetriesOnTimeoutOrNack : 10} ); } } </script> </head> <body> <div style="font-size:15px; font-family:monospace; color:slateblue;">Please Enter the Interest name:<br /></div> <input id="interest" style="border-radius: 3px" type="text" name="INTEREST" size="50" value="/" /> <br> <select id="pipeline"> <option value="cubic">Cubic Pipline</option> <option value="fixed">Fixed Pipline</option> </select> <br><br> <button style="margin-top:7px; font-style:italic; border-radius: 7px;" id="testBtn" onclick="run()">Fetch Content</button> <div id="content"><p>Content: </p></div> </body> </html>