mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
chore(docs): Sync docs to wiki [skip-cd]
parent
2dcb4b1c78
commit
056b9f10ef
@ -1,13 +1,12 @@
|
|||||||
# RTEngineClient Documentation
|
# Client
|
||||||
|
- [RTEngineClient](#rteenginclient)
|
||||||
## Overview
|
|
||||||
|
|
||||||
|
## RTEngineClient
|
||||||
|
### Overview
|
||||||
`RTEngineClient` is a WebSocket client for real-time communication with backend services. It provides connection management, automatic reconnection, heartbeat monitoring, event handling, and topic-based subscriptions.
|
`RTEngineClient` is a WebSocket client for real-time communication with backend services. It provides connection management, automatic reconnection, heartbeat monitoring, event handling, and topic-based subscriptions.
|
||||||
|
|
||||||
## API Reference
|
### API Reference
|
||||||
|
#### Constructor
|
||||||
### Constructor
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const client = new RTEngineClient({
|
const client = new RTEngineClient({
|
||||||
refName: "main",
|
refName: "main",
|
||||||
@ -26,16 +25,14 @@ const client = new RTEngineClient({
|
|||||||
| params.maxConnectRetries | number | Infinity | Maximum number of reconnection attempts |
|
| params.maxConnectRetries | number | Infinity | Maximum number of reconnection attempts |
|
||||||
| params.heartbeat | boolean | true | Whether to use heartbeat to monitor connection health |
|
| params.heartbeat | boolean | true | Whether to use heartbeat to monitor connection health |
|
||||||
|
|
||||||
### Static Properties
|
#### Static Properties
|
||||||
|
|
||||||
| Property | Type | Description |
|
| Property | Type | Description |
|
||||||
|----------|------|-------------|
|
|----------|------|-------------|
|
||||||
| version | string | Client library version |
|
| version | string | Client library version |
|
||||||
| heartbeatTimeout | number | Timeout for heartbeat checks (10000ms) |
|
| heartbeatTimeout | number | Timeout for heartbeat checks (10000ms) |
|
||||||
| reconnectTimeout | number | Delay between reconnection attempts (5000ms) |
|
| reconnectTimeout | number | Delay between reconnection attempts (5000ms) |
|
||||||
|
|
||||||
### State Object
|
#### State Object
|
||||||
|
|
||||||
The client state can be accessed via `client.state`:
|
The client state can be accessed via `client.state`:
|
||||||
|
|
||||||
| Property | Type | Description |
|
| Property | Type | Description |
|
||||||
@ -49,9 +46,9 @@ The client state can be accessed via `client.state`:
|
|||||||
| reconnecting | boolean | Whether the client is attempting to reconnect |
|
| reconnecting | boolean | Whether the client is attempting to reconnect |
|
||||||
| connectionRetryCount | number | Number of reconnection attempts made |
|
| connectionRetryCount | number | Number of reconnection attempts made |
|
||||||
|
|
||||||
### Methods
|
#### Methods
|
||||||
|
|
||||||
#### connect()
|
##### connect()
|
||||||
|
|
||||||
Establishes a connection to the WebSocket server.
|
Establishes a connection to the WebSocket server.
|
||||||
|
|
||||||
@ -63,7 +60,7 @@ await client.connect();
|
|||||||
|---------|-------------|
|
|---------|-------------|
|
||||||
| Promise<void> | Resolves when the connection is established |
|
| Promise<void> | Resolves when the connection is established |
|
||||||
|
|
||||||
#### disconnect()
|
##### disconnect()
|
||||||
|
|
||||||
Closes the current WebSocket connection.
|
Closes the current WebSocket connection.
|
||||||
|
|
||||||
@ -75,7 +72,7 @@ await client.disconnect();
|
|||||||
|---------|-------------|
|
|---------|-------------|
|
||||||
| Promise<boolean> | Resolves to false if no connection exists, true otherwise |
|
| Promise<boolean> | Resolves to false if no connection exists, true otherwise |
|
||||||
|
|
||||||
#### on(event, handler)
|
##### on(event, handler)
|
||||||
|
|
||||||
Registers an event handler.
|
Registers an event handler.
|
||||||
|
|
||||||
@ -90,7 +87,7 @@ client.on('message', (data) => {
|
|||||||
| event | string | Event name to listen for |
|
| event | string | Event name to listen for |
|
||||||
| handler | Function | Function to call when the event is received |
|
| handler | Function | Function to call when the event is received |
|
||||||
|
|
||||||
#### off(event, handler)
|
##### off(event, handler)
|
||||||
|
|
||||||
Removes an event handler.
|
Removes an event handler.
|
||||||
|
|
||||||
@ -103,7 +100,7 @@ client.off('message', messageHandler);
|
|||||||
| event | string | Event name to stop listening for |
|
| event | string | Event name to stop listening for |
|
||||||
| handler | Function | Handler function to remove |
|
| handler | Function | Handler function to remove |
|
||||||
|
|
||||||
#### once(event, handler)
|
##### once(event, handler)
|
||||||
|
|
||||||
Registers a one-time event handler.
|
Registers a one-time event handler.
|
||||||
|
|
||||||
@ -118,7 +115,7 @@ client.once('connected', () => {
|
|||||||
| event | string | Event name to listen for |
|
| event | string | Event name to listen for |
|
||||||
| handler | Function | Function to call once when the event is received |
|
| handler | Function | Function to call once when the event is received |
|
||||||
|
|
||||||
#### emit(event, data)
|
##### emit(event, data)
|
||||||
|
|
||||||
Sends an event to the WebSocket server.
|
Sends an event to the WebSocket server.
|
||||||
|
|
||||||
@ -147,7 +144,7 @@ client.topics.on('chat/room1', 'message', handleMessage);
|
|||||||
await client.topics.unsubscribe('chat/room1');
|
await client.topics.unsubscribe('chat/room1');
|
||||||
```
|
```
|
||||||
|
|
||||||
## Basic Usage Example
|
### Basic Usage Example
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import RTEngineClient from './RTEngineClient';
|
import RTEngineClient from './RTEngineClient';
|
||||||
@ -180,3 +177,105 @@ await client.emit('user:status', { status: 'online' });
|
|||||||
// Disconnect when done
|
// Disconnect when done
|
||||||
await client.disconnect();
|
await client.disconnect();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## TopicsController
|
||||||
|
### Overview
|
||||||
|
`TopicsController` is a utility class for managing topic-based subscriptions in real-time applications. It handles subscribing to topics, listening for specific events, and managing subscription lifecycles.
|
||||||
|
|
||||||
|
### API Reference
|
||||||
|
#### Constructor
|
||||||
|
```javascript
|
||||||
|
const topicsController = new TopicsController(client);
|
||||||
|
```
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
|-----------|------|-------------|
|
||||||
|
| client | Object | RTEngine client |
|
||||||
|
|
||||||
|
#### Properties
|
||||||
|
|
||||||
|
| Property | Type | Description |
|
||||||
|
|----------|------|-------------|
|
||||||
|
| subscribed | Set | Stores currently subscribed topics |
|
||||||
|
|
||||||
|
#### Methods
|
||||||
|
|
||||||
|
##### on(topic, event, callback)
|
||||||
|
|
||||||
|
Registers a callback for a specific event on a given topic.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
topicsController.on('chat/room1', 'message', (data, payload) => {
|
||||||
|
console.log('Message received:', data);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
|-----------|------|-------------|
|
||||||
|
| topic | string | Topic to associate the event with |
|
||||||
|
| event | string | Name of the event to listen for |
|
||||||
|
| callback | Function | Function to execute when the event occurs on the topic |
|
||||||
|
|
||||||
|
##### subscribe(topic)
|
||||||
|
|
||||||
|
Subscribes to a specific topic.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await topicsController.subscribe('chat/room1');
|
||||||
|
```
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
|-----------|------|-------------|
|
||||||
|
| topic | string | Topic to subscribe to |
|
||||||
|
| Returns | Promise<boolean> | Resolves to true when subscription is complete |
|
||||||
|
|
||||||
|
##### unsubscribe(topic)
|
||||||
|
|
||||||
|
Unsubscribes from a specific topic.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await topicsController.unsubscribe('chat/room1');
|
||||||
|
```
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
|-----------|------|-------------|
|
||||||
|
| topic | string | Topic to unsubscribe from |
|
||||||
|
| Returns | Promise<boolean> | Resolves to true when unsubscription is complete |
|
||||||
|
|
||||||
|
##### unsubscribeAll()
|
||||||
|
|
||||||
|
Unsubscribes from all currently subscribed topics.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await topicsController.unsubscribeAll();
|
||||||
|
```
|
||||||
|
|
||||||
|
| Returns | Promise<boolean> | Resolves to true when all unsubscriptions are complete |
|
||||||
|
|
||||||
|
##### regenerate()
|
||||||
|
|
||||||
|
Refreshes all current subscriptions by unsubscribing and resubscribing.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await topicsController.regenerate();
|
||||||
|
```
|
||||||
|
|
||||||
|
| Returns | Promise<boolean> | Resolves to true when regeneration is complete |
|
||||||
|
|
||||||
|
### Basic Usage Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Initialize
|
||||||
|
const topicsController = new TopicsController(realTimeClient);
|
||||||
|
|
||||||
|
// Subscribe to a topic
|
||||||
|
await topicsController.subscribe('notifications');
|
||||||
|
|
||||||
|
// Listen for events on that topic
|
||||||
|
topicsController.on('notifications', 'new', handleNewNotification);
|
||||||
|
|
||||||
|
// Clean up when done
|
||||||
|
await topicsController.unsubscribe('notifications');
|
||||||
|
// Or unsubscribe from everything
|
||||||
|
await topicsController.unsubscribeAll();
|
||||||
|
```
|
1
Home.md
Normal file
1
Home.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# LineBridge Documentation
|
1
Server.md
Normal file
1
Server.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Server
|
@ -1,4 +0,0 @@
|
|||||||
# Client documentation index
|
|
||||||
|
|
||||||
[RTEngine](./rtengine/index.md)
|
|
||||||
...
|
|
@ -1,105 +0,0 @@
|
|||||||
# TopicsController Documentation
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
`TopicsController` is a utility class for managing topic-based subscriptions in real-time applications. It handles subscribing to topics, listening for specific events, and managing subscription lifecycles.
|
|
||||||
|
|
||||||
## API Reference
|
|
||||||
|
|
||||||
### Constructor
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const topicsController = new TopicsController(client);
|
|
||||||
```
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
|-----------|------|-------------|
|
|
||||||
| client | Object | RTEngine client |
|
|
||||||
|
|
||||||
### Properties
|
|
||||||
|
|
||||||
| Property | Type | Description |
|
|
||||||
|----------|------|-------------|
|
|
||||||
| subscribed | Set | Stores currently subscribed topics |
|
|
||||||
|
|
||||||
### Methods
|
|
||||||
|
|
||||||
#### on(topic, event, callback)
|
|
||||||
|
|
||||||
Registers a callback for a specific event on a given topic.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
topicsController.on('chat/room1', 'message', (data, payload) => {
|
|
||||||
console.log('Message received:', data);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
|-----------|------|-------------|
|
|
||||||
| topic | string | Topic to associate the event with |
|
|
||||||
| event | string | Name of the event to listen for |
|
|
||||||
| callback | Function | Function to execute when the event occurs on the topic |
|
|
||||||
|
|
||||||
#### subscribe(topic)
|
|
||||||
|
|
||||||
Subscribes to a specific topic.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
await topicsController.subscribe('chat/room1');
|
|
||||||
```
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
|-----------|------|-------------|
|
|
||||||
| topic | string | Topic to subscribe to |
|
|
||||||
| Returns | Promise<boolean> | Resolves to true when subscription is complete |
|
|
||||||
|
|
||||||
#### unsubscribe(topic)
|
|
||||||
|
|
||||||
Unsubscribes from a specific topic.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
await topicsController.unsubscribe('chat/room1');
|
|
||||||
```
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
|-----------|------|-------------|
|
|
||||||
| topic | string | Topic to unsubscribe from |
|
|
||||||
| Returns | Promise<boolean> | Resolves to true when unsubscription is complete |
|
|
||||||
|
|
||||||
#### unsubscribeAll()
|
|
||||||
|
|
||||||
Unsubscribes from all currently subscribed topics.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
await topicsController.unsubscribeAll();
|
|
||||||
```
|
|
||||||
|
|
||||||
| Returns | Promise<boolean> | Resolves to true when all unsubscriptions are complete |
|
|
||||||
|
|
||||||
#### regenerate()
|
|
||||||
|
|
||||||
Refreshes all current subscriptions by unsubscribing and resubscribing.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
await topicsController.regenerate();
|
|
||||||
```
|
|
||||||
|
|
||||||
| Returns | Promise<boolean> | Resolves to true when regeneration is complete |
|
|
||||||
|
|
||||||
## Basic Usage Example
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Initialize
|
|
||||||
const topicsController = new TopicsController(realTimeClient);
|
|
||||||
|
|
||||||
// Subscribe to a topic
|
|
||||||
await topicsController.subscribe('notifications');
|
|
||||||
|
|
||||||
// Listen for events on that topic
|
|
||||||
topicsController.on('notifications', 'new', handleNewNotification);
|
|
||||||
|
|
||||||
// Clean up when done
|
|
||||||
await topicsController.unsubscribe('notifications');
|
|
||||||
// Or unsubscribe from everything
|
|
||||||
await topicsController.unsubscribeAll();
|
|
||||||
```
|
|
Loading…
x
Reference in New Issue
Block a user