Observer Client SDK
This is the client SDK for the Observer service. It is a library that can be used to connect to the Observer service and
execute operations on it.
Table of Contents
Install and Connect
npm install observer-client-sdk
import { ObserverClient } from '@huddle01/observer-client-sdk';
const observerClient = new ObserverClient({
connection: {
url: 'http://localhost:8080',
getAccessToken: async () => {
}
},
});
observerClient.connect();
ObserverClient
The ObserverClient
API provides an interface for interacting with data streams and real-time data updates via WebSocket connections. This client enables users to access call data, ongoing call information, client snapshots, and other related data through the following methods and events:
Events
- 'close': Triggered when the WebSocket connection is closed.
Configuration
- ObserverClientConfig: Configuration object used to initialize the
ObserverClient
.
connection
: Configuration for the WebSocket connection, using WebSocketConnectorConfig
.
Methods
connect(accessToken?: string): Promise
- Establishes a WebSocket connection.
accessToken
(optional): An access token to authenticate the connection.
close(): void
- Closes the WebSocket connection and cleans up resources.
findCalls(params: DashboardQueryOperations['findCalls']): Promise
- Queries the system for historical calls based on specified parameters.
params
: Object containing query filters such as producerId, consumerId, transportId, callId, roomId, clientId, and mediaTrackId
fetchOngoingCalls(): Promise
- Retrieves data about ongoing calls.
- No parameters required.
getSummaryStats(params: DashboardQueryOperations['getSummaryStats']): Promise
- Fetches summarized statistics based on the given parameters.
params
: Parameters to filter and aggregate the summary data.
createDatabaseFrame(resourceId: K, conditions: DatabaseFrameConditions<DatabaseFrameSchema[K]>, updateOnCreate = true): Promise<DataFrame<DatabaseFrameSchema[K]>>
- Creates a data frame for a specific resource in the database with filtering conditions.
resourceId
: Identifier for the database resource.conditions
: Filter conditions for the data.updateOnCreate
(optional): Whether to fetch the initial data on creation.
createCallSnapshotsFrame(callId: string): Promise<DataFrame>
- Creates a data frame for tracking snapshots of a specific call.
callId
: Unique identifier of the call.
createClientSnapshotsFrame(options: { callId: string, clientId: string }): Promise<DataFrame>
- Creates a data frame for tracking snapshots of a specific client within a call.
options
: An object containing:
callId
: Unique identifier of the call.clientId
: Unique identifier of the client.
This API provides a structured way to access and interact with call and client data in real-time, making it suitable for applications that require live monitoring and data analysis.
DataFrame
The DataFrame
API provides a flexible and efficient interface for data extraction and real-time data updates. It allows users to either:
-
Batch Retrieval: Extract large volumes of data in chunks, such as comprehensive reports on calls or clients. This is useful for obtaining historical data or performing extensive data analysis.
-
Continuous Streaming: Subscribe to updates for a particular resource, receiving real-time data as it changes. This is ideal for monitoring ongoing events or tracking live updates, such as changes in call status or client activity.
Constructor
constructor(
config: DataFrameConfig,
channel: WebSocketConnector,
sortFn?: (a: T, b: T) => number
)
- config: Configuration object containing the unique
dataFrameId
. - channel: WebSocket connector instance used for backend communication.
- sortFn (optional): Function to sort the rows within the data frame.
Methods
- close(): void: Closes the data frame, stops receiving updates, and triggers a 'close' event.
- update(): Promise: Fetches the latest data from the server and updates the local data frame. If a sorting function is provided, the rows will be sorted after the update.
- Symbol.iterator: IterableIterator: Allows iteration over the rows in the data frame.
- dispatch(event: DashboardDataStreamNotification['event']): void: Handles incoming WebSocket events and updates the data frame accordingly.
Events
- 'close': Emitted when the data frame is closed.
- 'newrow' (row: T): Emitted whenever a new row of data is added to the data frame.
- 'error' (error: string): Emitted when an error occurs.
Usage Example
const myDataFrame = observerClient.createClientSnapshotsFrame({
callId: '12345',
clientId: '67890',
});
myDataFrame.on('newrow', (row) => {
console.log('New data row received:', row);
});
myDataFrame.on('error', (error) => {
console.error('Data frame error:', error);
});
await myDataFrame.update();
for (const row of myDataFrame) {
console.log('Row:', row);
}
myDataFrame.close();