Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tracerbench/websocket-message-transport

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tracerbench/websocket-message-transport - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

dist/index.d.ts

@@ -1,2 +0,5 @@

export { default } from "./openWebSocket";
import { AttachMessageTransport } from "@tracerbench/message-transport";
import { RaceCancellation } from "race-cancellation";
export declare type CloseWebSocket = () => void;
export default function openWebSocket(url: string, raceCancellation?: RaceCancellation): Promise<[AttachMessageTransport, CloseWebSocket]>;
//# sourceMappingURL=index.d.ts.map

50

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var openWebSocket_1 = require("./openWebSocket");
exports.default = openWebSocket_1.default;
const race_cancellation_1 = require("race-cancellation");
const NodeWebSocket = require("ws");
async function openWebSocket(url, raceCancellation) {
const ws = new NodeWebSocket(url);
let lastError;
ws.on("error", (err) => {
lastError = err;
});
await race_cancellation_1.disposablePromise((resolve, reject) => {
ws.on("open", resolve);
ws.on("close", onClose);
function onClose() {
let message = `Failed to open ${url}`;
if (lastError !== undefined) {
message += `: ${lastError.stack}`;
}
reject(new Error(message));
}
return () => {
ws.removeListener("open", resolve);
ws.removeListener("close", onClose);
};
}, raceCancellation);
return [
(onMessage, onClose) => {
// we should be open still when attach is called
// but double check here
if (ws.readyState !== ws.OPEN) {
setImmediate(handleClose);
}
let called = false;
function handleClose() {
if (called) {
return;
}
called = true;
ws.removeListener("message", onMessage);
ws.removeListener("close", handleClose);
onClose(lastError);
}
ws.on("message", onMessage);
ws.on("close", handleClose);
return message => ws.send(message);
},
() => ws.close(),
];
}
exports.default = openWebSocket;
//# sourceMappingURL=index.js.map
{
"name": "@tracerbench/websocket-message-transport",
"version": "1.0.1",
"version": "1.1.0",
"license": "BSD-2-Clause",

@@ -13,4 +13,4 @@ "author": "Kris Selden <kris.selden@gmail.com>",

"scripts": {
"build": "tsc",
"build:clean": "rm -rf dist && yarn run build",
"build": "tsc -b",
"clean": "rm -rf dist tsconfig.tsbuildinfo",
"lint": "tslint -p tsconfig.json",

@@ -20,15 +20,15 @@ "prepare": "yarn run build"

"dependencies": {
"@tracerbench/message-transport": "^1.0.1",
"@tracerbench/message-transport": "^1.1.0",
"race-cancellation": "^0.4.1",
"ws": "^7.0.1"
"ws": "^7.1.2"
},
"devDependencies": {
"@types/ws": "*",
"@types/ws": "^6.0.3",
"prettier": "^1.18.2",
"tslint": "^5.18.0",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.5.2"
"typescript": "^3.6.4"
},
"gitHead": "e37b27bd4de7c6c49ad7ad8593263e67ad6018a0"
"gitHead": "5952575b4e979ed608d48972982dc6881edf6ce9"
}

@@ -1,1 +0,59 @@

export { default } from "./openWebSocket";
import { AttachMessageTransport } from "@tracerbench/message-transport";
import { disposablePromise, RaceCancellation } from "race-cancellation";
import NodeWebSocket = require("ws");
export type CloseWebSocket = () => void;
export default async function openWebSocket(
url: string,
raceCancellation?: RaceCancellation,
): Promise<[AttachMessageTransport, CloseWebSocket]> {
const ws = new NodeWebSocket(url);
let lastError: Error | undefined;
ws.on("error", (err: Error) => {
lastError = err;
});
await disposablePromise((resolve, reject) => {
ws.on("open", resolve);
ws.on("close", onClose);
function onClose() {
let message = `Failed to open ${url}`;
if (lastError !== undefined) {
message += `: ${lastError.stack}`;
}
reject(new Error(message));
}
return () => {
ws.removeListener("open", resolve);
ws.removeListener("close", onClose);
};
}, raceCancellation);
return [
(onMessage, onClose) => {
// we should be open still when attach is called
// but double check here
if (ws.readyState !== ws.OPEN) {
setImmediate(handleClose);
}
let called = false;
function handleClose() {
if (called) {
return;
}
called = true;
ws.removeListener("message", onMessage);
ws.removeListener("close", handleClose);
onClose(lastError);
}
ws.on("message", onMessage);
ws.on("close", handleClose);
return message => ws.send(message);
},
() => ws.close(),
];
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc