0.0.26 • Published 1 year ago
socket.ts v0.0.26
socket.ts
A simple, easy-to-use, high-performance, and plug-in Socket solution.
Install
npm install socket.ts
Quick Start
import { Socket, SocketState } from 'socket.ts';
const socket = new Socket({
url: 'ws://localhost:3000'
});
// Subscribe to Socket state changes
socket.subscribeState((state) => {
console.log(state);
});
// Listen for server data push
socket.subscribeMessage((messageEvent) => {
console.log(messageEvent);
});
// The event triggered after calling the transformMessage method to parse the data.
socket.subscribeData((data) => {
console.log(data);
});
// Send data to the server
socket.send({ msg: 'I am ready.' });
socket.connect();
// Disconnect
// socket.disconnect();
// Dispose memory and remove all event listeners
// socket.dispose()
Options
export interface SocketOptions {
/**
* The URL of the Socket request.
*/
url?: string;
/**
* The protocol of the Socket request.
*/
protocols?: string | string[];
/**
* The interval between reconnection attempts after the connection is lost, in milliseconds. Default is: 1000 * 30.
*/
retryInterval?: number;
/**
* The interval between sending heartbeats, in milliseconds. Default is: 1000 * 60.
*/
pingInterval?: number;
/**
* The data to be sent with the heartbeat.
*/
pingData?: any;
/**
* Create a bridge. The default bridge is WorkerSocketBridge.
* @param socket The current Socket instance.
* @returns
*/
createBridge: (socket: Socket) => SocketBridge;
/**
* After receiving data pushed from the server, you want to convert it into another format.
* @param event
* @returns Returns the converted data.
*/
transformResponse?: (event: MessageEvent) => any
/**
* The plugins used.
*/
plugins?: SocketPlugin[];
}
0.0.26
1 year ago
0.0.25
1 year ago
0.0.24
1 year ago
0.0.23
1 year ago
0.0.22
1 year ago
0.0.21
1 year ago
0.0.20
1 year ago
0.0.19
1 year ago
0.0.18
1 year ago
0.0.17
1 year ago
0.0.16
1 year ago
0.0.15
1 year ago
0.0.14
1 year ago
0.0.13
1 year ago
0.0.12
1 year ago
0.0.11
1 year ago
0.0.10
1 year ago
0.0.9
1 year ago
0.0.8
1 year ago
0.0.7
1 year ago
0.0.6
1 year ago
0.0.5
1 year ago
0.0.4
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago
0.0.1
1 year ago
1.0.1
2 years ago
1.0.0
2 years ago