@ndn/ws-transport
Advanced tools
Comparing version 0.0.20200909 to 0.0.20210203
@@ -1,7 +0,5 @@ | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
const WsWebSocket = __importDefault(require("ws")).default; | ||
import { __importDefault, __importStar } from "tslib"; | ||
import _cjsDefaultImport0 from "ws"; const WsWebSocket = __importDefault(_cjsDefaultImport0).default; | ||
export function makeWebSocket(uri) { | ||
return new WsWebSocket(uri, [], { perMessageDeflate: false }); | ||
} |
@@ -0,5 +1,4 @@ | ||
import { __importDefault, __importStar } from "tslib"; | ||
import { L3Face, rxFromPacketIterable, Transport } from "@ndn/l3face"; | ||
import { EventIterator } from "event-iterator"; | ||
import PCancelable from "p-cancelable"; | ||
import pTimeout from "p-timeout"; | ||
import _cjsDefaultImport0 from "event-iterator"; const EventIterator = __importDefault(_cjsDefaultImport0).default; | ||
import { makeWebSocket } from "./ws_browser.js"; | ||
@@ -64,16 +63,26 @@ /** WebSocket transport. */ | ||
function connect(uri, opts = {}) { | ||
var _a; | ||
return pTimeout(new PCancelable((resolve, reject, onCancel) => { | ||
const { connectTimeout = 10000, signal, } = opts; | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
const sock = makeWebSocket(uri); | ||
const fail = (err) => { | ||
sock.close(); | ||
reject(err); | ||
}; | ||
const timeout = setTimeout(() => fail(new Error("connectTimeout")), connectTimeout); | ||
const onabort = () => fail(new Error("abort")); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", () => onabort); | ||
const onerror = (evt) => { | ||
sock.close(); | ||
reject(new Error(evt.message)); | ||
sock.close(); | ||
}; | ||
sock.addEventListener("error", onerror); | ||
sock.addEventListener("open", () => { | ||
var _a; | ||
clearTimeout(timeout); | ||
sock.removeEventListener("error", onerror); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", onabort); | ||
resolve(new WsTransport(sock, opts)); | ||
}); | ||
onCancel(() => sock.close()); | ||
}), (_a = opts.connectTimeout) !== null && _a !== void 0 ? _a : 10000); | ||
}); | ||
} | ||
@@ -80,0 +89,0 @@ WsTransport.connect = connect; |
@@ -1,8 +0,4 @@ | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
import { __importDefault, __importStar } from "tslib"; | ||
import { L3Face, rxFromPacketIterable, Transport } from "@ndn/l3face"; | ||
const { EventIterator } = require("event-iterator"); | ||
const PCancelable = __importDefault(require("p-cancelable")).default; | ||
const pTimeout = __importDefault(require("p-timeout")).default; | ||
import _cjsDefaultImport0 from "event-iterator"; const EventIterator = __importDefault(_cjsDefaultImport0).default; | ||
import { makeWebSocket } from "./ws_node.js"; | ||
@@ -67,16 +63,26 @@ /** WebSocket transport. */ | ||
function connect(uri, opts = {}) { | ||
var _a; | ||
return pTimeout(new PCancelable((resolve, reject, onCancel) => { | ||
const { connectTimeout = 10000, signal, } = opts; | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
const sock = makeWebSocket(uri); | ||
const fail = (err) => { | ||
sock.close(); | ||
reject(err); | ||
}; | ||
const timeout = setTimeout(() => fail(new Error("connectTimeout")), connectTimeout); | ||
const onabort = () => fail(new Error("abort")); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", () => onabort); | ||
const onerror = (evt) => { | ||
sock.close(); | ||
reject(new Error(evt.message)); | ||
sock.close(); | ||
}; | ||
sock.addEventListener("error", onerror); | ||
sock.addEventListener("open", () => { | ||
var _a; | ||
clearTimeout(timeout); | ||
sock.removeEventListener("error", onerror); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", onabort); | ||
resolve(new WsTransport(sock, opts)); | ||
}); | ||
onCancel(() => sock.close()); | ||
}), (_a = opts.connectTimeout) !== null && _a !== void 0 ? _a : 10000); | ||
}); | ||
} | ||
@@ -83,0 +89,0 @@ WsTransport.connect = connect; |
import { L3Face, Transport } from "@ndn/l3face"; | ||
import type { AbortSignal } from "abort-controller"; | ||
/** WebSocket transport. */ | ||
@@ -19,2 +20,4 @@ export declare class WsTransport extends Transport { | ||
connectTimeout?: number; | ||
/** AbortSignal that allows canceling connection attempt via AbortController. */ | ||
signal?: AbortSignal | globalThis.AbortSignal; | ||
/** Buffer amount (in bytes) to start TX throttling. */ | ||
@@ -21,0 +24,0 @@ highWaterMark?: number; |
{ | ||
"name": "@ndn/ws-transport", | ||
"version": "0.0.20200909", | ||
"version": "0.0.20210203", | ||
"description": "NDNts: WebSocket Transport", | ||
@@ -25,10 +25,9 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/l3face": "0.0.20200909", | ||
"@ndn/l3face": "0.0.20210203", | ||
"abort-controller": "^3.0.0", | ||
"event-iterator": "^2.0.0", | ||
"p-cancelable": "^2.0.0", | ||
"p-timeout": "^3.2.0", | ||
"tslib": "^2.0.1", | ||
"ws": "^7.3.1" | ||
"tslib": "^2.1.0", | ||
"ws": "^7.4.3" | ||
}, | ||
"types": "lib/mod.d.ts" | ||
} |
@@ -33,3 +33,3 @@ # @ndn/ws-transport | ||
// We can now send Interests and retrieve Data. | ||
let seq = Math.floor(Math.random() * 99999999); | ||
let seq = Math.floor(Math.random() * 1e9); | ||
for (let i = 0; i < 5; ++i) { | ||
@@ -41,3 +41,3 @@ try { | ||
console.log(`>D ${data.name}`); | ||
} catch (err) { | ||
} catch (err: unknown) { | ||
console.warn(err); | ||
@@ -44,0 +44,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
12032
5
230
0
0
+ Addedabort-controller@^3.0.0
+ Added@ndn/fw@0.0.20210203(transitive)
+ Added@ndn/l3face@0.0.20210203(transitive)
+ Added@ndn/lp@0.0.20210203(transitive)
+ Added@ndn/packet@0.0.20210203(transitive)
+ Added@ndn/tlv@0.0.20210203(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedit-pushable@1.4.0(transitive)
- Removedp-cancelable@^2.0.0
- Removedp-timeout@^3.2.0
- Removed@ndn/fw@0.0.20200909(transitive)
- Removed@ndn/l3face@0.0.20200909(transitive)
- Removed@ndn/lp@0.0.20200909(transitive)
- Removed@ndn/packet@0.0.20200909(transitive)
- Removed@ndn/tlv@0.0.20200909(transitive)
- Removedit-pushable@1.4.2(transitive)
- Removedloglevel@1.9.2(transitive)
- Removedp-cancelable@2.1.1(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
Updated@ndn/l3face@0.0.20210203
Updatedtslib@^2.1.0
Updatedws@^7.4.3