[C] RealtimeClient
constructor
Creates a new RealtimeClient to interact with realtime transcription models. If you make use of the client, you can generate this instance automatically via MeetingBot.getRealtimeClient()
.
If this would be used on the front-end, then you can fetch the websocket url in the back-end, forward it to the front-end and use this class directly.
Parameter | Default | Description |
---|---|---|
ws_url | required | URL to the websocket server |
import { RealtimeClient } from '@skribby/sdk'
const realtimeClient = new RealtimeClient('wss://example.org/123456');
Properties
connected
Simple property to be able to check whether the client is connected or not.
By default it's false
until the connect
method is called and connection is established.
Returns
boolean
Example
console.log(realtimeClient.connected);
Methods
on
Create a new event listener with a callback to handle events
Parameters
Parameter | Default | Description |
---|---|---|
event | required (string) | Event name to listen to. Refer to the Realtime Core Concepts for all available events. |
callback | required (function with 1 parameter) | Callback when event has been triggered. Refer to the Realtime Core Concepts for returned data per event. The callback will contain the data segment, if data is not provided the returned parameter will be undefined . |
Returns
void
Example
realtimeClient.on('start', () => {
console.log('Bot has started!');
});
realtimeClient.on('ts', data => {
console.log(`${data.speaker_name} said: ${data.transcript}`);
});
send
Send an action to the bot
Parameters
Parameter | Default | Description |
---|---|---|
action | required (string) | Action name. Refer to the Realtime Core Concepts for all available actions. |
data | conditionally required (depending on the action) | Data to send alongside the action. Refer to the Realtime Core Concepts for required data per action. The required data to be sent is the data portion of each action in that document. |
Returns
void
Example
realtimeClient.send('chat-message', {
content: "Hello from my script!"
});
realtimeClient.send('stop');
connect
Start connection with the websocket server.
Returns
void
Example
await realtimeClient.connect();
disconnect
Disconnect from the websocket server.
Returns
void
Example
await realtimeClient.disconnect();