
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
@bytesocket/server
Advanced tools
Shared server logic for ByteSocket WebSocket server implementations
Shared server logic for ByteSocket WebSocket server implementations. This package provides the abstract base classes, interfaces, and types that the transport‑specific adaptors (@bytesocket/node, @bytesocket/uws) extend to create a fully‑typed, real‑time server.
You do not need to install this package directly; it is a dependency of the main packages.
ByteSocketServerBase handles message parsing, middleware execution, event routing, authentication, room join/leave, and lifecycle hooks. You only implement the transport‑specific parts./test-utils) let you run the exact same test suite against every adaptor.npm install @bytesocket/server
This package is not meant to be used directly. Choose an adaptor that matches your WebSocket library:
@bytesocket/node- for Node.jsws@bytesocket/uws- for uWebSockets.js
@bytesocket/server)ByteSocketServerBase - abstract server classSocketServerBase - abstract per‑connection socket classIByteSocket / ISocket / ISocketRooms / IRoomsServer / ILifecycleServer - public API interfacesByteSocketOptionsBase - configuration options shared by every adaptorServerIncomingData / ServerOutgoingData - type aliases for raw WebSocket dataMiddleware, EventCallback, RoomEventMiddleware, AuthFunction, MiddlewareNext - callback typesSocketData - the user data shape attached to every socketencode / decode - serialization helpers (MessagePack / JSON)@bytesocket/server/test-utils)Factory functions that create a server + test client for running integration tests across adaptors:
import { serverConnectionTest } from "@bytesocket/server/test-utils";
Available test suites:
serverConnectionTest - connection open/close, origin checks, header gettersserverHeartbeatTest - empty‑binary ping/pong, automatic keep‑aliveserverAuthTest - authentication flow (success / failure / timeout)serverLifecycleTest - lifecycle hook ordering and errorsserverMessagingTest - message send / receive, serializationserverRoomsSingleTest - single‑room join/leave/emitserverRoomsBulkTest - bulk room operationsEach factory function receives:
import * as vitest from 'vitest')createByteSocket functioncreateByteSocketServer functiondestroyByteSocketServer functionSee the adaptor packages for concrete examples.
ByteSocketServerBaseThe abstract server class. Adaptors extend it and implement attach, publishRaw, and the upgrade lifecycle methods.
import { ByteSocketServerBase } from "@bytesocket/server";
class MyByteSocket extends ByteSocketServerBase<MyEvents> {
attach(server: unknown, path: string): this {
/* … */
}
// …
}
Key protected methods (call these from your adaptor):
message(socket, data, isBinary) - process an incoming WebSocket messageclose(socket, code, reason) - handle a transport close eventPublic API: emit, on, off, once, use (middleware), encode, decode, destroy.
SocketServerBaseAbstract socket instance. Adaptors subclass it to provide sendRaw, publishRaw, joinRoom, leaveRoom, and closeTransport.
ByteSocketOptionsBase)| Option | Type | Default | Description |
|---|---|---|---|
debug | boolean | false | Enable debug logging |
serialization | "json" | "binary" | "binary" | Payload encoding format |
broadcastRoom | string | "__bytesocket_broadcast__" | Internal room used for global broadcasts |
authTimeout | number | 0 | Max milliseconds to wait for an auth response |
middlewareTimeout | number | 0 | Timeout for global middleware |
roomMiddlewareTimeout | number | 0 | Timeout for room middleware |
idleTimeout | number | 120000 | Milliseconds before an idle connection is closed |
sendPingsAutomatically | boolean | true | Send WebSocket pings to keep the connection alive |
origins | string[] | - | Allowed origin list (empty = all allowed) |
onMiddlewareError | "ignore" | "close" | function | "ignore" | Action when global middleware errors |
onMiddlewareTimeout | "ignore" | "close" | function | "ignore" | Action when global middleware times out |
msgpackrOptions | object | - | Options forwarded to the msgpackr Packr instance |
auth | AuthFunction | - | User‑supplied authentication handler |
import { ByteSocket } from '@bytesocket/node'; // or '@bytesocket/uws'
import { SocketEvents } from '@bytesocket/core';
type MyEvents = SocketEvents<{
"chat:message": { text: string };
"user:joined": { userId: string };
}>;
const io = new ByteSocket<MyEvents>({ debug: true });
io.on('chat:message', (socket, data) => {
console.log(\`${socket.id} says: ${data.text}\`);
});
io.emit('user:joined', { userId: 'server' });
// attach to an HTTP server or uWS app
io.attach(server, '/ws');
Transport‑specific implementations:
ws libraryBoth expose a concrete ByteSocket class that you instantiate directly.
// packages/node/tests/connection.test.ts
import * as vitest from "vitest";
import { serverConnectionTest } from "@bytesocket/server/test-utils";
import { createByteSocket, createByteSocketServer, destroyByteSocketServer } from "./factory";
describe("ByteSocket node: Connection", () => {
serverConnectionTest(vitest, createByteSocket, createByteSocketServer, destroyByteSocketServer);
});
Your factory file provides the three functions that wrap your specific transport setup. The shared test suite handles the rest.
MIT © 2026 Ahmed Ouda
FAQs
Shared server logic for ByteSocket WebSocket server implementations
The npm package @bytesocket/server receives a total of 5 weekly downloads. As such, @bytesocket/server popularity was classified as not popular.
We found that @bytesocket/server 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
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.