Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
partysocket
Advanced tools
(Forked from the wonderful reconnecting-websocket project, updated with pending PRs and bugfixes)
A better WebSocket that Just Works™
npm install partysocket
import { WebSocket } from "partysocket";
const ws = new WebSocket("wss://my.site.com");
ws.addEventListener("open", () => {
ws.send("hello!");
});
import PartySocket from "partysocket";
const ws = new PartySocket({
host: "project.name.partykit.dev", // or localhost:1999 in dev
room: "my-room",
// add an optional id to identify the client,
// if not provided, a random id will be generated
id: "some-connection-id",
});
// optionally, update the properties of the connection
// (e.g. to change the host or room)
ws.updateProperties({
host: "another-project.username.partykit.dev",
room: "my-new-room",
});
ws.reconnect(); // make sure to call reconnect() after updating the properties
The url
parameter will be resolved before connecting, with possible types:
string
() => string
() => Promise<string>
import { WebSocket } from "partysocket";
const urls = [
"wss://my.site.com",
"wss://your.site.com",
"wss://their.site.com",
];
let urlIndex = 0;
// round robin url provider
const urlProvider = () => urls[urlIndex++ % urls.length];
const ws = new WebSocket(urlProvider);
import { WebSocket } from "partysocket";
// async url provider
const urlProvider = async () => {
const token = await getSessionToken();
return `wss://my.site.com/${token}`;
};
const ws = new WebSocket(urlProvider);
The protocols
parameter will be resolved before connecting, possible types:
null
string
string[]
() => string | string[] | null
() => Promise<string | string[] | null>
import { WebSocket } from "partysocket";
const ws = new WebSocket("wss://your.site.com", "your protocol");
import WebSocket from 'partysocket`;
const protocols = ['p1', 'p2', ['p3.1', 'p3.2']];
let protocolsIndex = 0;
// round robin protocols provider
const protocolsProvider = () => protocols[protocolsIndex++ % protocols.length];
const ws = new WebSocket('wss://your.site.com', protocolsProvider);
import { WebSocket } from "partysocket";
import WS from "ws";
const options = {
WebSocket: WS, // custom WebSocket constructor
connectionTimeout: 1000,
maxRetries: 10,
};
const ws = new WebSocket("wss://my.site.com", [], options);
type Options = {
WebSocket?: any; // WebSocket constructor, if none provided, defaults to global WebSocket
maxReconnectionDelay?: number; // max delay in ms between reconnections
minReconnectionDelay?: number; // min delay in ms between reconnections
reconnectionDelayGrowFactor?: number; // how fast the reconnection delay grows
minUptime?: number; // min time in ms to consider connection as stable
connectionTimeout?: number; // retry connect if not connected after this time, in ms
maxRetries?: number; // maximum number of retries
maxEnqueuedMessages?: number; // maximum number of messages to buffer until reconnection
startClosed?: boolean; // start websocket in CLOSED state, call `.reconnect()` to connect
debug?: boolean; // enables debug output
};
WebSocket: undefined,
maxReconnectionDelay: 10000,
minReconnectionDelay: 1000 + Math.random() * 4000,
reconnectionDelayGrowFactor: 1.3,
minUptime: 5000,
connectionTimeout: 4000,
maxRetries: Infinity,
maxEnqueuedMessages: Infinity,
startClosed: false,
debug: false,
constructor(url: UrlProvider, protocols?: ProtocolsProvider, options?: Options)
close(code?: number, reason?: string)
reconnect(code?: number, reason?: string)
send(data: string | ArrayBuffer | Blob | ArrayBufferView)
addEventListener(type: 'open' | 'close' | 'message' | 'error', listener: EventListener)
removeEventListener(type: 'open' | 'close' | 'message' | 'error', listener: EventListener)
binaryType: string;
bufferedAmount: number;
extensions: string;
onclose: EventListener;
onerror: EventListener;
onmessage: EventListener;
onopen: EventListener;
protocol: string;
readyState: number;
url: string;
retryCount: number;
CONNECTING 0 The connection is not yet open.
OPEN 1 The connection is open and ready to communicate.
CLOSING 2 The connection is in the process of closing.
CLOSED 3 The connection is closed or couldn't be opened.
MIT
FAQs
A better WebSocket that Just Works™
The npm package partysocket receives a total of 43,130 weekly downloads. As such, partysocket popularity was classified as popular.
We found that partysocket demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.