@ndn/ws-transport
This package is part of NDNts, Named Data Networking libraries for the modern web.
This package implements a WebSocket transport.
It works in both Node and browser.
You can create a forwarder face that uses WebSocket transport with WsTransport.createFace()
function.
To create a WebSocket transport without wrapping into L3Face, use WsTransport.connect()
function.
import { WsTransport } from "@ndn/ws-transport";
import { Endpoint } from "@ndn/endpoint";
import { Data, Interest, Name } from "@ndn/packet";
(async () => {
if (process.env.CI) { return; }
const uplink = await WsTransport.createFace({}, "wss://hobo.cs.arizona.edu/ws/");
uplink.addRoute(new Name("/ndn"));
const endpoint = new Endpoint();
let seq = Math.floor(Math.random() * 1e9);
for (let i = 0; i < 5; ++i) {
try {
const interest = new Interest(`/ndn/edu/arizona/ping/NDNts/${seq++}`);
console.log(`<I ${interest.name}`);
const data = await endpoint.consume(interest);
console.log(`>D ${data.name}`);
} catch (err: unknown) {
console.warn(err);
}
}
uplink.close();
})();