From 056b9f10efd1c33162cc5a4f48417bc7cf2278a7 Mon Sep 17 00:00:00 2001 From: Actionbot Date: Wed, 26 Mar 2025 14:41:58 +0000 Subject: [PATCH] chore(docs): Sync docs to wiki [skip-cd] --- client/rtengine/index.md => Client.md | 137 ++++++++++++++++++++++---- Home.md | 1 + Server.md | 1 + client/index.md | 4 - client/rtengine/topics.md | 105 -------------------- 5 files changed, 120 insertions(+), 128 deletions(-) rename client/rtengine/index.md => Client.md (61%) create mode 100644 Home.md create mode 100644 Server.md delete mode 100644 client/index.md delete mode 100644 client/rtengine/topics.md diff --git a/client/rtengine/index.md b/Client.md similarity index 61% rename from client/rtengine/index.md rename to Client.md index 4c6dee5..6d0a6d5 100644 --- a/client/rtengine/index.md +++ b/Client.md @@ -1,13 +1,12 @@ -# RTEngineClient Documentation - -## Overview +# Client + - [RTEngineClient](#rteenginclient) +## 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. -## API Reference - -### Constructor - +### API Reference +#### Constructor ```javascript const client = new RTEngineClient({ refName: "main", @@ -26,16 +25,14 @@ const client = new RTEngineClient({ | params.maxConnectRetries | number | Infinity | Maximum number of reconnection attempts | | params.heartbeat | boolean | true | Whether to use heartbeat to monitor connection health | -### Static Properties - +#### Static Properties | Property | Type | Description | |----------|------|-------------| | version | string | Client library version | | heartbeatTimeout | number | Timeout for heartbeat checks (10000ms) | | reconnectTimeout | number | Delay between reconnection attempts (5000ms) | -### State Object - +#### State Object The client state can be accessed via `client.state`: | 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 | | connectionRetryCount | number | Number of reconnection attempts made | -### Methods +#### Methods -#### connect() +##### connect() Establishes a connection to the WebSocket server. @@ -63,7 +60,7 @@ await client.connect(); |---------|-------------| | Promise | Resolves when the connection is established | -#### disconnect() +##### disconnect() Closes the current WebSocket connection. @@ -75,7 +72,7 @@ await client.disconnect(); |---------|-------------| | Promise | Resolves to false if no connection exists, true otherwise | -#### on(event, handler) +##### on(event, handler) Registers an event handler. @@ -90,7 +87,7 @@ client.on('message', (data) => { | event | string | Event name to listen for | | handler | Function | Function to call when the event is received | -#### off(event, handler) +##### off(event, handler) Removes an event handler. @@ -103,7 +100,7 @@ client.off('message', messageHandler); | event | string | Event name to stop listening for | | handler | Function | Handler function to remove | -#### once(event, handler) +##### once(event, handler) Registers a one-time event handler. @@ -118,7 +115,7 @@ client.once('connected', () => { | event | string | Event name to listen for | | handler | Function | Function to call once when the event is received | -#### emit(event, data) +##### emit(event, data) Sends an event to the WebSocket server. @@ -147,7 +144,7 @@ client.topics.on('chat/room1', 'message', handleMessage); await client.topics.unsubscribe('chat/room1'); ``` -## Basic Usage Example +### Basic Usage Example ```javascript import RTEngineClient from './RTEngineClient'; @@ -180,3 +177,105 @@ await client.emit('user:status', { status: 'online' }); // Disconnect when done 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 | 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 | Resolves to true when unsubscription is complete | + +##### unsubscribeAll() + +Unsubscribes from all currently subscribed topics. + +```javascript +await topicsController.unsubscribeAll(); +``` + +| Returns | Promise | Resolves to true when all unsubscriptions are complete | + +##### regenerate() + +Refreshes all current subscriptions by unsubscribing and resubscribing. + +```javascript +await topicsController.regenerate(); +``` + +| Returns | Promise | 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(); +``` diff --git a/Home.md b/Home.md new file mode 100644 index 0000000..299abe2 --- /dev/null +++ b/Home.md @@ -0,0 +1 @@ +# LineBridge Documentation diff --git a/Server.md b/Server.md new file mode 100644 index 0000000..76ac08d --- /dev/null +++ b/Server.md @@ -0,0 +1 @@ +# Server diff --git a/client/index.md b/client/index.md deleted file mode 100644 index 1273167..0000000 --- a/client/index.md +++ /dev/null @@ -1,4 +0,0 @@ -# Client documentation index - -[RTEngine](./rtengine/index.md) -... diff --git a/client/rtengine/topics.md b/client/rtengine/topics.md deleted file mode 100644 index 64183f1..0000000 --- a/client/rtengine/topics.md +++ /dev/null @@ -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 | 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 | Resolves to true when unsubscription is complete | - -#### unsubscribeAll() - -Unsubscribes from all currently subscribed topics. - -```javascript -await topicsController.unsubscribeAll(); -``` - -| Returns | Promise | Resolves to true when all unsubscriptions are complete | - -#### regenerate() - -Refreshes all current subscriptions by unsubscribing and resubscribing. - -```javascript -await topicsController.regenerate(); -``` - -| Returns | Promise | 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(); -```