@marketrix.ai/link-server
v2.0.0
Published
This is the server-side library for the Link protocol. It provides a WebSocket server implementation with support for multiplexed streams.
Readme
Link Server
This is the server-side library for the Link protocol. It provides a WebSocket server implementation with support for multiplexed streams.
Installation
npm install @marketrix.ai/link-serverUsage
You can use the LinkServer class to create a WebSocket server or integrate it into an existing application.
Basic Usage
import { LinkServer } from '@marketrix.ai/link-server';
const server = new LinkServer({ port: 8080 });
server.onListening(() => {
console.log('Server is listening on port 8080');
});
server.onConnection((connection) => {
console.log('Client connected:', connection.id);
// Handle new streams created by the client
connection.onStream((stream) => {
console.log(`Stream ${stream.id} created`);
stream.onData((data) => {
console.log(`Received data on stream ${stream.id}:`, data);
// Example: sending data back
// stream.send({ message: 'Hello from server' });
});
stream.onClose(() => {
console.log(`Stream ${stream.id} closed`);
});
});
connection.onClose(() => {
console.log('Client disconnected');
});
});Options
The LinkServer constructor accepts the same options as the ws WebSocket.Server:
const server = new LinkServer({
port: 8080,
// host: '0.0.0.0',
// ... other ws options
});