mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
fix format
This commit is contained in:
parent
5c22d0e783
commit
1e7396ee45
@ -10,7 +10,7 @@ const client = new RTEngineClient({
|
|||||||
url: "wss://example.com/socket",
|
url: "wss://example.com/socket",
|
||||||
token: "auth-token-here",
|
token: "auth-token-here",
|
||||||
autoReconnect: true
|
autoReconnect: true
|
||||||
});
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Default | Description |
|
| Parameter | Type | Default | Description |
|
||||||
@ -50,7 +50,7 @@ The client state can be accessed via `client.state`:
|
|||||||
Establishes a connection to the WebSocket server.
|
Establishes a connection to the WebSocket server.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await client.connect();
|
await client.connect()
|
||||||
```
|
```
|
||||||
|
|
||||||
| Returns | Description |
|
| Returns | Description |
|
||||||
@ -62,7 +62,7 @@ await client.connect();
|
|||||||
Closes the current WebSocket connection.
|
Closes the current WebSocket connection.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await client.disconnect();
|
await client.disconnect()
|
||||||
```
|
```
|
||||||
|
|
||||||
| Returns | Description |
|
| Returns | Description |
|
||||||
@ -74,9 +74,9 @@ await client.disconnect();
|
|||||||
Registers an event handler.
|
Registers an event handler.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
client.on('message', (data) => {
|
client.on("message", (data) => {
|
||||||
console.log('Message received:', data);
|
console.log("Message received:", data)
|
||||||
});
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -89,7 +89,7 @@ client.on('message', (data) => {
|
|||||||
Removes an event handler.
|
Removes an event handler.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
client.off('message', messageHandler);
|
client.off("message", messageHandler)
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -102,9 +102,9 @@ client.off('message', messageHandler);
|
|||||||
Registers a one-time event handler.
|
Registers a one-time event handler.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
client.once('connected', () => {
|
client.once("connected", () => {
|
||||||
console.log('Connected!');
|
console.log("Connected!")
|
||||||
});
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -117,7 +117,7 @@ client.once('connected', () => {
|
|||||||
Sends an event to the WebSocket server.
|
Sends an event to the WebSocket server.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await client.emit('chat:message', { text: 'Hello!' });
|
await client.emit("chat:message", { text: "Hello!" })
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -132,45 +132,45 @@ The client includes a `TopicsController` instance accessible via `client.topics`
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Subscribe to a topic
|
// Subscribe to a topic
|
||||||
await client.topics.subscribe('chat/room1');
|
await client.topics.subscribe("chat/room1")
|
||||||
|
|
||||||
// Listen for events on a specific topic
|
// Listen for events on a specific topic
|
||||||
client.topics.on('chat/room1', 'message', handleMessage);
|
client.topics.on("chat/room1", "message", handleMessage)
|
||||||
|
|
||||||
// Unsubscribe from a topic
|
// Unsubscribe from a topic
|
||||||
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"
|
||||||
|
|
||||||
// Initialize the client
|
// Initialize the client
|
||||||
const client = new RTEngineClient({
|
const client = new RTEngineClient({
|
||||||
url: 'wss://api.example.com/socket',
|
url: "wss://api.example.com/socket",
|
||||||
token: 'user-auth-token'
|
token: "user-auth-token" // optional if server not requires authentication
|
||||||
});
|
})
|
||||||
|
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
await client.connect();
|
await client.connect()
|
||||||
|
|
||||||
// Subscribe to a topic
|
// Subscribe to a topic
|
||||||
await client.topics.subscribe('updates');
|
await client.topics.subscribe("updates")
|
||||||
|
|
||||||
// Listen for specific events
|
// Listen for specific events
|
||||||
client.on('notification', (data) => {
|
client.on("notification", (data) => {
|
||||||
console.log('New notification:', data);
|
console.log("New notification:", data)
|
||||||
});
|
})
|
||||||
|
|
||||||
// Listen for events on a specific topic
|
// Listen for events on a specific topic
|
||||||
client.topics.on('updates', 'new_version', (data) => {
|
client.topics.on("updates", "new_version", (data) => {
|
||||||
console.log('New version available:', data.version);
|
console.log("New version available:", data.version)
|
||||||
});
|
})
|
||||||
|
|
||||||
// Send an event
|
// Send an event
|
||||||
await client.emit('user:status', { status: 'online' });
|
await client.emit("user:status", { status: "online" })
|
||||||
|
|
||||||
// Disconnect when done
|
// Disconnect when done
|
||||||
await client.disconnect();
|
await client.disconnect()
|
||||||
```
|
```
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
## API Reference
|
## API Reference
|
||||||
### Constructor
|
### Constructor
|
||||||
```javascript
|
```javascript
|
||||||
const topicsController = new TopicsController(client);
|
const topicsController = new TopicsController(client)
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -25,9 +25,9 @@ const topicsController = new TopicsController(client);
|
|||||||
Registers a callback for a specific event on a given topic.
|
Registers a callback for a specific event on a given topic.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
topicsController.on('chat/room1', 'message', (data, payload) => {
|
topicsController.on("chat/room1", "message", (data, payload) => {
|
||||||
console.log('Message received:', data);
|
console.log("Message received:", data)
|
||||||
});
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -41,7 +41,7 @@ topicsController.on('chat/room1', 'message', (data, payload) => {
|
|||||||
Subscribes to a specific topic.
|
Subscribes to a specific topic.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await topicsController.subscribe('chat/room1');
|
await topicsController.subscribe("chat/room1")
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -54,7 +54,7 @@ await topicsController.subscribe('chat/room1');
|
|||||||
Unsubscribes from a specific topic.
|
Unsubscribes from a specific topic.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await topicsController.unsubscribe('chat/room1');
|
await topicsController.unsubscribe("chat/room1")
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
@ -67,7 +67,7 @@ await topicsController.unsubscribe('chat/room1');
|
|||||||
Unsubscribes from all currently subscribed topics.
|
Unsubscribes from all currently subscribed topics.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await topicsController.unsubscribeAll();
|
await topicsController.unsubscribeAll()
|
||||||
```
|
```
|
||||||
|
|
||||||
| Returns | Promise<boolean> | Resolves to true when all unsubscriptions are complete |
|
| Returns | Promise<boolean> | Resolves to true when all unsubscriptions are complete |
|
||||||
@ -77,7 +77,7 @@ await topicsController.unsubscribeAll();
|
|||||||
Refreshes all current subscriptions by unsubscribing and resubscribing.
|
Refreshes all current subscriptions by unsubscribing and resubscribing.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await topicsController.regenerate();
|
await topicsController.regenerate()
|
||||||
```
|
```
|
||||||
|
|
||||||
| Returns | Promise<boolean> | Resolves to true when regeneration is complete |
|
| Returns | Promise<boolean> | Resolves to true when regeneration is complete |
|
||||||
@ -86,16 +86,16 @@ await topicsController.regenerate();
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Initialize
|
// Initialize
|
||||||
const topicsController = new TopicsController(realTimeClient);
|
const topicsController = new TopicsController(realTimeClient)
|
||||||
|
|
||||||
// Subscribe to a topic
|
// Subscribe to a topic
|
||||||
await topicsController.subscribe('notifications');
|
await topicsController.subscribe("notifications")
|
||||||
|
|
||||||
// Listen for events on that topic
|
// Listen for events on that topic
|
||||||
topicsController.on('notifications', 'new', handleNewNotification);
|
topicsController.on("notifications", "new", handleNewNotification)
|
||||||
|
|
||||||
// Clean up when done
|
// Clean up when done
|
||||||
await topicsController.unsubscribe('notifications');
|
await topicsController.unsubscribe("notifications")
|
||||||
// Or unsubscribe from everything
|
// Or unsubscribe from everything
|
||||||
await topicsController.unsubscribeAll();
|
await topicsController.unsubscribeAll()
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user