Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client-js/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
BotReadyData,
BotTTSTextData,
ClientMessageData,
DeviceState,
ErrorData,
LLMContextMessage,
LLMFunctionCallData,
Expand Down Expand Up @@ -61,6 +62,7 @@ export type RTVIEventCallbacks = Partial<{
onDisconnected: () => void;
onError: (message: RTVIMessage) => void;
onTransportStateChanged: (state: TransportState) => void;
onDeviceStateChanged: (state: DeviceState) => void;

onBotConnected: (participant: Participant) => void;
onBotReady: (botReadyData: BotReadyData) => void;
Expand Down Expand Up @@ -199,6 +201,10 @@ export class PipecatClient extends RTVIEventEmitter {
options?.callbacks?.onTransportStateChanged?.(state);
this.emit(RTVIEvent.TransportStateChanged, state);
},
onDeviceStateChanged: (state: DeviceState) => {
options?.callbacks?.onDeviceStateChanged?.(state);
this.emit(RTVIEvent.DeviceStateChanged, state);
},
onParticipantJoined: (p) => {
options?.callbacks?.onParticipantJoined?.(p);
this.emit(RTVIEvent.ParticipantConnected, p);
Expand Down Expand Up @@ -484,6 +490,10 @@ export class PipecatClient extends RTVIEventEmitter {
return this._transport.state;
}

public get deviceState(): DeviceState {
return this._transport.deviceState;
}

public get version(): string {
return packageJson.version;
}
Expand Down
6 changes: 5 additions & 1 deletion client-js/client/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

import { RTVIError, RTVIMessage, TransportState } from "../rtvi";
import { DeviceState, RTVIError, RTVIMessage, TransportState } from "../rtvi";
import { PipecatClientOptions, RTVIEventCallbacks } from "./client";

export type Tracks = {
Expand All @@ -30,6 +30,7 @@ export abstract class Transport {
protected declare _callbacks: RTVIEventCallbacks;
protected declare _abortController: AbortController | undefined;
protected _state: TransportState = "disconnected";
protected _deviceState: DeviceState = "not_ready";

constructor() {}

Expand Down Expand Up @@ -86,6 +87,9 @@ export abstract class Transport {
abstract get state(): TransportState;
abstract set state(state: TransportState);

abstract get deviceState(): DeviceState;
abstract set deviceState(state: DeviceState);

abstract getAllMics(): Promise<MediaDeviceInfo[]>;
abstract getAllCams(): Promise<MediaDeviceInfo[]>;
abstract getAllSpeakers(): Promise<MediaDeviceInfo[]>;
Expand Down
13 changes: 9 additions & 4 deletions client-js/rtvi/common_types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export type TransportState =
| "disconnected"
| "initializing"
| "initialized"
| "authenticating"
| "authenticated"
| "connecting"
Expand All @@ -12,8 +10,6 @@ export type TransportState =

export enum TransportStateEnum {
DISCONNECTED = "disconnected",
INITIALIZING = "initializing",
INITIALIZED = "initialized",
AUTHENTICATING = "authenticating",
AUTHENTICATED = "authenticated",
CONNECTING = "connecting",
Expand All @@ -23,6 +19,15 @@ export enum TransportStateEnum {
ERROR = "error",
}

export type DeviceState = "not_ready" | "initializing" | "ready" | "blocked";

export enum DeviceStateEnum {
NOT_READY = "not_ready",
INITIALIZING = "initializing",
READY = "ready",
BLOCKED = "blocked",
}

export type Participant = {
id: string;
name: string;
Expand Down
4 changes: 3 additions & 1 deletion client-js/rtvi/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

import { Participant, TransportState } from "./common_types";
import { DeviceState, Participant, TransportState } from "./common_types";
import { DeviceError } from "./errors";
import {
BotLLMSearchResponseData,
Expand All @@ -22,6 +22,7 @@ export enum RTVIEvent {
Connected = "connected",
Disconnected = "disconnected",
TransportStateChanged = "transportStateChanged",
DeviceStateChanged = "deviceStateChanged",

/** remote connection state events */
BotConnected = "botConnected",
Expand Down Expand Up @@ -90,6 +91,7 @@ export type RTVIEvents = Partial<{
connected: () => void;
disconnected: () => void;
transportStateChanged: (state: TransportState) => void;
deviceStateChanged: (state: DeviceState) => void;

/** remote connection state events */
botConnected: (participant: Participant) => void;
Expand Down