@coze/realtime-api 0.0.4 → 1.0.0-alpha.7419f0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":"5.6.3"}
@@ -1,27 +1,34 @@
1
1
  import { type AudioPropertiesConfig, type onUserJoinedEvent, type onUserLeaveEvent, type UserMessageEvent } from '@volcengine/rtc';
2
2
  import { RealtimeEventHandler } from './event-handler';
3
+ import { type VideoConfig } from '.';
3
4
  export declare class EngineClient extends RealtimeEventHandler {
4
5
  private engine;
5
6
  private joinUserId;
6
7
  private _AIAnsExtension;
7
- constructor(appId: string, debug?: boolean, isTestEnv?: boolean);
8
+ private _isSupportVideo;
9
+ constructor(appId: string, debug?: boolean, isTestEnv?: boolean, isSupportVideo?: boolean);
8
10
  bindEngineEvents(): void;
9
11
  removeEventListener(): void;
12
+ _parseMessage(event: UserMessageEvent): any;
10
13
  handleMessage(event: UserMessageEvent): void;
11
14
  handleEventError(e: unknown): void;
12
15
  handleUserJoin(event: onUserJoinedEvent): void;
13
16
  handleUserLeave(event: onUserLeaveEvent): void;
17
+ handlePlayerEvent(event: unknown): void;
14
18
  joinRoom(options: {
15
19
  token: string;
16
20
  roomId: string;
17
21
  uid: string;
18
22
  audioMutedDefault?: boolean;
23
+ videoOnDefault?: boolean;
24
+ isAutoSubscribeAudio?: boolean;
19
25
  }): Promise<void>;
20
26
  setAudioInputDevice(deviceId: string): Promise<void>;
21
27
  setAudioOutputDevice(deviceId: string): Promise<void>;
22
- createLocalStream(): Promise<void>;
28
+ createLocalStream(userId?: string, videoConfig?: VideoConfig): Promise<void>;
23
29
  disconnect(): Promise<void>;
24
30
  changeAudioState(isMicOn: boolean): Promise<void>;
31
+ changeVideoState(isVideoOn: boolean): Promise<void>;
25
32
  stop(): Promise<void>;
26
33
  sendMessage(message: Record<string, unknown>): Promise<void>;
27
34
  enableAudioPropertiesReport(config?: AudioPropertiesConfig): void;
@@ -8,10 +8,18 @@ export declare enum RealtimeError {
8
8
  PERMISSION_DENIED = "PERMISSION_DENIED",
9
9
  NETWORK_ERROR = "NETWORK_ERROR",
10
10
  INVALID_STATE = "INVALID_STATE",
11
- CREATE_ROOM_ERROR = "CREATE_ROOM_ERROR"
11
+ CREATE_ROOM_ERROR = "CREATE_ROOM_ERROR",
12
+ PARSE_MESSAGE_ERROR = "PARSE_MESSAGE_ERROR",
13
+ HANDLER_MESSAGE_ERROR = "HANDLER_MESSAGE_ERROR"
12
14
  }
13
15
  export declare const ErrorMessages: Record<RealtimeError, string>;
14
16
  export declare class RealtimeAPIError extends Error {
15
17
  code: RealtimeError;
16
- constructor(code: RealtimeError, message: string);
18
+ error?: unknown;
19
+ /**
20
+ * @param code - Error code
21
+ * @param message - Error message
22
+ * @param error - Error object
23
+ */
24
+ constructor(code: RealtimeError, message: string, error?: unknown);
17
25
  }
@@ -39,6 +39,21 @@ export declare enum EventNames {
39
39
  * zh: 客户端音频静音
40
40
  */
41
41
  AUDIO_MUTED = "client.audio.muted",
42
+ /**
43
+ * en: Client video on
44
+ * zh: 客户端视频开启
45
+ */
46
+ VIDEO_ON = "client.video.on",
47
+ /**
48
+ * en: Client video off
49
+ * zh: 客户端视频关闭
50
+ */
51
+ VIDEO_OFF = "client.video.off",
52
+ /**
53
+ * en: Client video event
54
+ * zh: 客户端视频事件
55
+ */
56
+ PLAYER_EVENT = "client.video.event",
42
57
  /**
43
58
  * en: Client error
44
59
  * zh: 客户端错误
@@ -63,9 +78,54 @@ export declare enum EventNames {
63
78
  * en: Audio output device changed
64
79
  * zh: 音频输出设备改变
65
80
  */
66
- AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed"
81
+ AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
82
+ /**
83
+ * en: Bot joined
84
+ * zh: Bot 加入
85
+ */
86
+ BOT_JOIN = "server.bot.join",
87
+ /**
88
+ * en: Bot left
89
+ * zh: Bot 离开
90
+ */
91
+ BOT_LEAVE = "server.bot.leave",
92
+ /**
93
+ * en: Audio speech started
94
+ * zh: 开始说话
95
+ */
96
+ AUDIO_AGENT_SPEECH_STARTED = "server.audio.agent.speech_started",
97
+ /**
98
+ * en: Audio speech stopped
99
+ * zh: 停止说话
100
+ */
101
+ AUDIO_SPEECH_STOPPED = "server.audio.speech_stopped",
102
+ /**
103
+ * en: Server error
104
+ * zh: 服务端错误
105
+ */
106
+ SERVER_ERROR = "server.error",
107
+ /**
108
+ * en: User speech started
109
+ * zh: 用户开始说话
110
+ */
111
+ AUDIO_USER_SPEECH_STARTED = "server.audio.user.speech_started",
112
+ /**
113
+ * en: User speech stopped
114
+ * zh: 用户停止说话
115
+ */
116
+ AUDIO_USER_SPEECH_STOPPED = "server.audio.user.speech_stopped",
117
+ /**
118
+ * en: User successfully enters the room
119
+ * zh: 用户成功进入房间后,会收到该事件
120
+ */
121
+ SESSION_CREATED = "server.session.created",
122
+ /**
123
+ * en: Session updated
124
+ * zh: 会话更新
125
+ */
126
+ SESSION_UPDATE = "server.session.update"
67
127
  }
68
- type EventCallback = (eventName: string, event: unknown) => void;
128
+ export type EventCallback = (eventName: string, event: unknown) => void;
69
129
  export declare class RealtimeEventHandler {
70
130
  private eventHandlers;
71
131
  protected _debug: boolean;
@@ -74,7 +134,6 @@ export declare class RealtimeEventHandler {
74
134
  on(eventName: string, callback: EventCallback): EventCallback;
75
135
  off(eventName: string, callback: EventCallback): void;
76
136
  private _dispatchToHandlers;
77
- dispatch(eventName: string, event: unknown): void;
137
+ dispatch(eventName: string, event: unknown, consoleLog?: boolean): void;
78
138
  _log(message: string): void;
79
139
  }
80
- export {};
@@ -1,9 +1,14 @@
1
1
  import { type AudioPropertiesConfig } from '@volcengine/rtc';
2
+ import { type GetToken } from '@coze/api';
2
3
  import * as RealtimeUtils from './utils';
3
4
  import { RealtimeEventHandler, EventNames } from './event-handler';
4
5
  import { RealtimeAPIError, RealtimeError } from './error';
6
+ export interface VideoConfig {
7
+ videoOnDefault?: boolean /** optional, Whether to turn on video by default, defaults to true */;
8
+ renderDom?: string /** optional, The DOM element to render the video stream to */;
9
+ }
5
10
  export interface RealtimeClientConfig {
6
- accessToken: string /** required, Access Token */;
11
+ accessToken: GetToken /** required, Access Token */;
7
12
  botId: string /** required, Bot Id */;
8
13
  voiceId?: string /** optional, Voice Id */;
9
14
  conversationId?: string /** optional, Conversation Id */;
@@ -17,14 +22,16 @@ export interface RealtimeClientConfig {
17
22
  connectorId: string /** required, Connector Id */;
18
23
  suppressStationaryNoise?: boolean /** optional, Suppress stationary noise, defaults to false */;
19
24
  suppressNonStationaryNoise?: boolean /** optional, Suppress non-stationary noise, defaults to false */;
25
+ videoConfig?: VideoConfig /** optional, Video configuration */;
26
+ isAutoSubscribeAudio?: boolean /** optional, Whether to automatically subscribe to bot reply audio streams, defaults to true */;
20
27
  }
21
28
  declare class RealtimeClient extends RealtimeEventHandler {
22
29
  private _config;
23
30
  private _client;
24
- private _roomInfo;
25
31
  isConnected: boolean;
26
32
  private _api;
27
33
  private _isTestEnv;
34
+ _isSupportVideo: boolean;
28
35
  /**
29
36
  * Constructor for initializing a RealtimeClient instance.
30
37
  *
@@ -54,6 +61,7 @@ declare class RealtimeClient extends RealtimeEventHandler {
54
61
  * 可选,默认是否抑制静态噪声,默认值为 false。
55
62
  * @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
56
63
  * 可选,默认是否抑制非静态噪声,默认值为 false。
64
+ * @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
57
65
  */
58
66
  constructor(config: RealtimeClientConfig);
59
67
  /**
@@ -86,6 +94,7 @@ declare class RealtimeClient extends RealtimeEventHandler {
86
94
  * zh: 启用或禁用音频
87
95
  */
88
96
  setAudioEnable(isEnable: boolean): Promise<void>;
97
+ setVideoEnable(isEnable: boolean): Promise<void>;
89
98
  /**
90
99
  * en: Enable audio properties reporting (debug mode only)
91
100
  *
@@ -6,14 +6,27 @@
6
6
  + */
7
7
  export declare const sleep: (milliseconds: number) => Promise<void>;
8
8
  /**
9
+ * @deprecated use checkDevicePermission instead
9
10
  * Check microphone permission,return boolean
10
11
  */
11
- export declare const checkPermission: () => Promise<boolean>;
12
+ export declare const checkPermission: ({ audio, video, }?: {
13
+ audio?: boolean;
14
+ video?: boolean;
15
+ }) => Promise<boolean>;
16
+ export declare const checkDevicePermission: (checkVideo?: boolean) => Promise<{
17
+ video: boolean;
18
+ audio: boolean;
19
+ videoExceptionError?: DOMException | undefined;
20
+ audioExceptionError?: DOMException | undefined;
21
+ }>;
12
22
  /**
13
23
  * Get audio devices
14
24
  * @returns Promise<AudioDevices> Object containing arrays of audio input and output devices
15
25
  */
16
- export declare const getAudioDevices: () => Promise<{
26
+ export declare const getAudioDevices: ({ video, }?: {
27
+ video?: boolean;
28
+ }) => Promise<{
17
29
  audioInputs: MediaDeviceInfo[];
18
30
  audioOutputs: MediaDeviceInfo[];
31
+ videoInputs: MediaDeviceInfo[];
19
32
  }>;