@coze/realtime-api 1.3.0 → 1.3.2-alpha.f7fe14
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.
- package/README.md +3 -0
- package/README.zh-CN.md +3 -0
- package/dist/cjs/event-names/index.js +220 -210
- package/dist/cjs/index.js +762 -624
- package/dist/cjs/live/index.js +289 -0
- package/dist/esm/event-names/index.js +216 -169
- package/dist/esm/index.js +757 -591
- package/dist/esm/live/index.js +287 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/event-names/event-names.d.ts +8 -2
- package/dist/types/index.d.ts +330 -9
- package/dist/types/live/live/index.d.ts +91 -0
- package/package.json +26 -6
- package/dist/types/client.d.ts +0 -49
- package/dist/types/error.d.ts +0 -25
- package/dist/types/event-handler.d.ts +0 -12
- package/dist/types/event-names/client.d.ts +0 -49
- package/dist/types/event-names/error.d.ts +0 -25
- package/dist/types/event-names/event-handler.d.ts +0 -12
- package/dist/types/event-names/index.d.ts +0 -163
- package/dist/types/event-names/utils.d.ts +0 -49
- package/dist/types/event-names.d.ts +0 -208
- package/dist/types/utils.d.ts +0 -49
- package/dist/umd/index.js +0 -987
package/dist/types/index.d.ts
CHANGED
|
@@ -1,16 +1,333 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { ScreenConfig, AudioPropertiesConfig, IRTCEngine } from '@volcengine/rtc';
|
|
2
|
+
import { GetToken, CreateRoomData, RoomMode, TranslateConfig, CreateRoomTurnDetection } from '@coze/api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
+ * Delays execution for the specified duration
|
|
6
|
+
+ * @param milliseconds The time to sleep in milliseconds
|
|
7
|
+
+ * @throws {Error} If milliseconds is negative
|
|
8
|
+
+ * @returns Promise that resolves after the specified duration
|
|
9
|
+
+ */
|
|
10
|
+
declare const sleep: (milliseconds: number) => Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated use checkDevicePermission instead
|
|
13
|
+
* Check microphone permission,return boolean
|
|
14
|
+
*/
|
|
15
|
+
declare const checkPermission: ({ audio, video, }?: {
|
|
16
|
+
audio?: boolean;
|
|
17
|
+
video?: boolean;
|
|
18
|
+
}) => Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Checks device permissions for audio and video
|
|
21
|
+
* @param checkVideo Whether to check video permissions (default: false)
|
|
22
|
+
* @returns Promise that resolves with the device permission status
|
|
23
|
+
*/
|
|
24
|
+
declare const checkDevicePermission: (checkVideo?: boolean) => Promise<{
|
|
25
|
+
video: boolean;
|
|
26
|
+
audio: boolean;
|
|
27
|
+
videoExceptionError?: DOMException | undefined;
|
|
28
|
+
audioExceptionError?: DOMException | undefined;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Get audio devices
|
|
32
|
+
* @returns Promise<AudioDevices> Object containing arrays of audio input and output devices
|
|
33
|
+
*/
|
|
34
|
+
declare const getAudioDevices: ({ video, }?: {
|
|
35
|
+
video?: boolean;
|
|
36
|
+
}) => Promise<{
|
|
37
|
+
audioInputs: MediaDeviceInfo[];
|
|
38
|
+
audioOutputs: MediaDeviceInfo[];
|
|
39
|
+
videoInputs: MediaDeviceInfo[];
|
|
40
|
+
}>;
|
|
41
|
+
declare const isScreenShareDevice: (deviceId?: string) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* 判断是否前后置摄像头
|
|
44
|
+
* @param deviceId
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
declare const isMobileVideoDevice: (deviceId?: string) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Check if browser supports screen sharing
|
|
50
|
+
* 检查浏览器是否支持屏幕共享
|
|
51
|
+
*/
|
|
52
|
+
declare function isScreenShareSupported(): boolean;
|
|
53
|
+
|
|
54
|
+
declare const utils_checkDevicePermission: typeof checkDevicePermission;
|
|
55
|
+
declare const utils_checkPermission: typeof checkPermission;
|
|
56
|
+
declare const utils_getAudioDevices: typeof getAudioDevices;
|
|
57
|
+
declare const utils_isMobileVideoDevice: typeof isMobileVideoDevice;
|
|
58
|
+
declare const utils_isScreenShareDevice: typeof isScreenShareDevice;
|
|
59
|
+
declare const utils_isScreenShareSupported: typeof isScreenShareSupported;
|
|
60
|
+
declare const utils_sleep: typeof sleep;
|
|
61
|
+
declare namespace utils {
|
|
62
|
+
export {
|
|
63
|
+
utils_checkDevicePermission as checkDevicePermission,
|
|
64
|
+
utils_checkPermission as checkPermission,
|
|
65
|
+
utils_getAudioDevices as getAudioDevices,
|
|
66
|
+
utils_isMobileVideoDevice as isMobileVideoDevice,
|
|
67
|
+
utils_isScreenShareDevice as isScreenShareDevice,
|
|
68
|
+
utils_isScreenShareSupported as isScreenShareSupported,
|
|
69
|
+
utils_sleep as sleep,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare enum EventNames {
|
|
74
|
+
/**
|
|
75
|
+
* en: All events
|
|
76
|
+
* zh: 所有事件
|
|
77
|
+
*/
|
|
78
|
+
ALL = "realtime.event",
|
|
79
|
+
/**
|
|
80
|
+
* en: All client events
|
|
81
|
+
* zh: 所有客户端事件
|
|
82
|
+
*/
|
|
83
|
+
ALL_CLIENT = "client.*",
|
|
84
|
+
/**
|
|
85
|
+
* en: All server events
|
|
86
|
+
* zh: 所有服务端事件
|
|
87
|
+
*/
|
|
88
|
+
ALL_SERVER = "server.*",
|
|
89
|
+
/**
|
|
90
|
+
* en: Room info
|
|
91
|
+
* zh: 房间信息
|
|
92
|
+
*/
|
|
93
|
+
ROOM_INFO = "client.room.info",
|
|
94
|
+
/**
|
|
95
|
+
* en: Client connected
|
|
96
|
+
* zh: 客户端连接
|
|
97
|
+
*/
|
|
98
|
+
CONNECTED = "client.connected",
|
|
99
|
+
/**
|
|
100
|
+
* en: Client connecting
|
|
101
|
+
* zh: 客户端连接中
|
|
102
|
+
*/
|
|
103
|
+
CONNECTING = "client.connecting",
|
|
104
|
+
/**
|
|
105
|
+
* en: Client interrupted
|
|
106
|
+
* zh: 客户端中断
|
|
107
|
+
*/
|
|
108
|
+
INTERRUPTED = "client.interrupted",
|
|
109
|
+
/**
|
|
110
|
+
* en: Client disconnected
|
|
111
|
+
* zh: 客户端断开
|
|
112
|
+
*/
|
|
113
|
+
DISCONNECTED = "client.disconnected",
|
|
114
|
+
/**
|
|
115
|
+
* en: Client audio unmuted
|
|
116
|
+
* zh: 客户端音频未静音
|
|
117
|
+
*/
|
|
118
|
+
AUDIO_UNMUTED = "client.audio.unmuted",
|
|
119
|
+
/**
|
|
120
|
+
* en: Client audio muted
|
|
121
|
+
* zh: 客户端音频静音
|
|
122
|
+
*/
|
|
123
|
+
AUDIO_MUTED = "client.audio.muted",
|
|
124
|
+
/**
|
|
125
|
+
* en: Client video on
|
|
126
|
+
* zh: 客户端视频开启
|
|
127
|
+
*/
|
|
128
|
+
VIDEO_ON = "client.video.on",
|
|
129
|
+
/**
|
|
130
|
+
* en: Client video off
|
|
131
|
+
* zh: 客户端视频关闭
|
|
132
|
+
*/
|
|
133
|
+
VIDEO_OFF = "client.video.off",
|
|
134
|
+
/**
|
|
135
|
+
* en: Client video error
|
|
136
|
+
* zh: 客户端视频(或屏幕共享)错误
|
|
137
|
+
*/
|
|
138
|
+
VIDEO_ERROR = "client.video.error",
|
|
139
|
+
/**
|
|
140
|
+
* en: Client video event
|
|
141
|
+
* zh: 客户端视频事件
|
|
142
|
+
*/
|
|
143
|
+
PLAYER_EVENT = "client.video.event",
|
|
144
|
+
/**
|
|
145
|
+
* en: Client error
|
|
146
|
+
* zh: 客户端错误
|
|
147
|
+
*/
|
|
148
|
+
ERROR = "client.error",
|
|
149
|
+
/**
|
|
150
|
+
* en: Audio noise reduction enabled
|
|
151
|
+
* zh: 抑制平稳噪声
|
|
152
|
+
*/
|
|
153
|
+
SUPPRESS_STATIONARY_NOISE = "client.suppress.stationary.noise",
|
|
154
|
+
/**
|
|
155
|
+
* en: Suppress non-stationary noise
|
|
156
|
+
* zh: 抑制非平稳噪声
|
|
157
|
+
*/
|
|
158
|
+
SUPPRESS_NON_STATIONARY_NOISE = "client.suppress.non.stationary.noise",
|
|
159
|
+
/**
|
|
160
|
+
* en: Audio input device changed
|
|
161
|
+
* zh: 音频输入设备改变
|
|
162
|
+
*/
|
|
163
|
+
AUDIO_INPUT_DEVICE_CHANGED = "client.input.device.changed",
|
|
164
|
+
/**
|
|
165
|
+
* en: Audio output device changed
|
|
166
|
+
* zh: 音频输出设备改变
|
|
167
|
+
*/
|
|
168
|
+
AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
|
|
169
|
+
/**
|
|
170
|
+
* en: Video input device changed
|
|
171
|
+
* zh: 视频输入设备改变
|
|
172
|
+
*/
|
|
173
|
+
VIDEO_INPUT_DEVICE_CHANGED = "client.video.input.device.changed",
|
|
174
|
+
/**
|
|
175
|
+
* en: Network quality changed
|
|
176
|
+
* zh: 网络质量改变
|
|
177
|
+
*/
|
|
178
|
+
NETWORK_QUALITY = "client.network.quality",
|
|
179
|
+
/**
|
|
180
|
+
* en: Bot joined
|
|
181
|
+
* zh: Bot 加入
|
|
182
|
+
*/
|
|
183
|
+
BOT_JOIN = "server.bot.join",
|
|
184
|
+
/**
|
|
185
|
+
* en: Bot left
|
|
186
|
+
* zh: Bot 离开
|
|
187
|
+
*/
|
|
188
|
+
BOT_LEAVE = "server.bot.leave",
|
|
189
|
+
/**
|
|
190
|
+
* en: Audio speech started
|
|
191
|
+
* zh: 开始说话
|
|
192
|
+
*/
|
|
193
|
+
AUDIO_AGENT_SPEECH_STARTED = "server.audio.agent.speech_started",
|
|
194
|
+
/**
|
|
195
|
+
* en: Audio speech stopped
|
|
196
|
+
* zh: 停止说话
|
|
197
|
+
*/
|
|
198
|
+
AUDIO_AGENT_SPEECH_STOPPED = "server.audio.agent.speech_stopped",
|
|
199
|
+
/**
|
|
200
|
+
* en: Server error
|
|
201
|
+
* zh: 服务端错误
|
|
202
|
+
*/
|
|
203
|
+
SERVER_ERROR = "server.error",
|
|
204
|
+
/**
|
|
205
|
+
* en: User speech started
|
|
206
|
+
* zh: 用户开始说话
|
|
207
|
+
*/
|
|
208
|
+
AUDIO_USER_SPEECH_STARTED = "server.audio.user.speech_started",
|
|
209
|
+
/**
|
|
210
|
+
* en: User speech stopped
|
|
211
|
+
* zh: 用户停止说话
|
|
212
|
+
*/
|
|
213
|
+
AUDIO_USER_SPEECH_STOPPED = "server.audio.user.speech_stopped",
|
|
214
|
+
/**
|
|
215
|
+
* en: User successfully enters the room
|
|
216
|
+
* zh: 用户成功进入房间后,会收到该事件
|
|
217
|
+
*/
|
|
218
|
+
SESSION_CREATED = "server.session.created",
|
|
219
|
+
/**
|
|
220
|
+
* en: Session updated
|
|
221
|
+
* zh: 会话更新
|
|
222
|
+
*/
|
|
223
|
+
SESSION_UPDATED = "server.session.updated",
|
|
224
|
+
/**
|
|
225
|
+
* en: Conversation created
|
|
226
|
+
* zh: 会话创建
|
|
227
|
+
*/
|
|
228
|
+
CONVERSATION_CREATED = "server.conversation.created",
|
|
229
|
+
/**
|
|
230
|
+
* en: Conversation chat created
|
|
231
|
+
* zh: 会话对话创建
|
|
232
|
+
*/
|
|
233
|
+
CONVERSATION_CHAT_CREATED = "server.conversation.chat.created",
|
|
234
|
+
/**
|
|
235
|
+
* en: Conversation chat in progress
|
|
236
|
+
* zh: 对话正在处理中
|
|
237
|
+
*/
|
|
238
|
+
CONVERSATION_CHAT_IN_PROGRESS = "server.conversation.chat.in_progress",
|
|
239
|
+
/**
|
|
240
|
+
* en: Conversation message delta received
|
|
241
|
+
* zh: 文本消息增量返回
|
|
242
|
+
*/
|
|
243
|
+
CONVERSATION_MESSAGE_DELTA = "server.conversation.message.delta",
|
|
244
|
+
/**
|
|
245
|
+
* en: Conversation message completed
|
|
246
|
+
* zh: 文本消息完成
|
|
247
|
+
*/
|
|
248
|
+
CONVERSATION_MESSAGE_COMPLETED = "server.conversation.message.completed",
|
|
249
|
+
/**
|
|
250
|
+
* en: Conversation chat completed
|
|
251
|
+
* zh: 对话完成
|
|
252
|
+
*/
|
|
253
|
+
CONVERSATION_CHAT_COMPLETED = "server.conversation.chat.completed",
|
|
254
|
+
/**
|
|
255
|
+
* en: Conversation chat requires action
|
|
256
|
+
* zh: 对话需要插件
|
|
257
|
+
*/
|
|
258
|
+
CONVERSATION_CHAT_REQUIRES_ACTION = "server.conversation.chat.requires_action",
|
|
259
|
+
/**
|
|
260
|
+
* en: Conversation chat failed
|
|
261
|
+
* zh: 对话失败
|
|
262
|
+
*/
|
|
263
|
+
CONVERSATION_CHAT_FAILED = "server.conversation.chat.failed",
|
|
264
|
+
/**
|
|
265
|
+
* en: Session pre answer updated
|
|
266
|
+
* zh: 安抚配置更新成功
|
|
267
|
+
*/
|
|
268
|
+
SESSION_PRE_ANSWER_UPDATED = "server.session.pre_answer.updated",
|
|
269
|
+
/**
|
|
270
|
+
* en: Conversation audio transcript delta
|
|
271
|
+
* zh: 用户语音识别字幕
|
|
272
|
+
*/
|
|
273
|
+
CONVERSATION_AUDIO_TRANSCRIPT_DELTA = "server.conversation.audio_transcript.delta",
|
|
274
|
+
/**
|
|
275
|
+
* en: Mode updated
|
|
276
|
+
* zh: 更新房间模式成功
|
|
277
|
+
*/
|
|
278
|
+
MODE_UPDATED = "server.mode.updated",
|
|
279
|
+
/**
|
|
280
|
+
* en: Live created
|
|
281
|
+
* zh: 直播创建
|
|
282
|
+
*/
|
|
283
|
+
LIVE_CREATED = "server.live.created"
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
type EventCallback = (eventName: string, event: unknown) => void;
|
|
287
|
+
declare class RealtimeEventHandler {
|
|
288
|
+
private eventHandlers;
|
|
289
|
+
protected _debug: boolean;
|
|
290
|
+
constructor(debug?: boolean);
|
|
291
|
+
clearEventHandlers(): void;
|
|
292
|
+
on(eventName: string, callback: EventCallback): EventCallback;
|
|
293
|
+
off(eventName: string, callback: EventCallback): void;
|
|
294
|
+
private _dispatchToHandlers;
|
|
295
|
+
dispatch(eventName: string, event: unknown, consoleLog?: boolean): void;
|
|
296
|
+
_log(message: string, event?: unknown): void;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
declare enum RealtimeError {
|
|
300
|
+
DEVICE_ACCESS_ERROR = "DEVICE_ACCESS_ERROR",
|
|
301
|
+
STREAM_CREATION_ERROR = "STREAM_CREATION_ERROR",
|
|
302
|
+
CONNECTION_ERROR = "CONNECTION_ERROR",
|
|
303
|
+
DISCONNECTION_ERROR = "DISCONNECTION_ERROR",
|
|
304
|
+
INTERRUPT_ERROR = "INTERRUPT_ERROR",
|
|
305
|
+
EVENT_HANDLER_ERROR = "EVENT_HANDLER_ERROR",
|
|
306
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
307
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
308
|
+
INVALID_STATE = "INVALID_STATE",
|
|
309
|
+
CREATE_ROOM_ERROR = "CREATE_ROOM_ERROR",
|
|
310
|
+
PARSE_MESSAGE_ERROR = "PARSE_MESSAGE_ERROR",
|
|
311
|
+
HANDLER_MESSAGE_ERROR = "HANDLER_MESSAGE_ERROR"
|
|
312
|
+
}
|
|
313
|
+
declare class RealtimeAPIError extends Error {
|
|
314
|
+
code: RealtimeError;
|
|
315
|
+
error?: unknown;
|
|
316
|
+
/**
|
|
317
|
+
* @param code - Error code
|
|
318
|
+
* @param message - Error message
|
|
319
|
+
* @param error - Error object
|
|
320
|
+
*/
|
|
321
|
+
constructor(code: RealtimeError, message: string, error?: unknown);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
interface VideoConfig {
|
|
8
325
|
videoOnDefault?: boolean /** optional, Whether to turn on video by default, defaults to true */;
|
|
9
326
|
renderDom?: string /** optional, The DOM element to render the video stream to */;
|
|
10
327
|
videoInputDeviceId?: string /** optional, The device ID of the video input device to use */;
|
|
11
328
|
screenConfig?: ScreenConfig;
|
|
12
329
|
}
|
|
13
|
-
|
|
330
|
+
interface RealtimeClientConfig {
|
|
14
331
|
accessToken: GetToken /** required, Access Token */;
|
|
15
332
|
botId: string /** required, Bot Id */;
|
|
16
333
|
voiceId?: string /** optional, Voice Id */;
|
|
@@ -32,6 +349,8 @@ export interface RealtimeClientConfig {
|
|
|
32
349
|
isAutoSubscribeAudio?: boolean /** optional, Whether to automatically subscribe to bot reply audio streams, defaults to true */;
|
|
33
350
|
prologueContent?: string /** optional, Prologue content */;
|
|
34
351
|
roomMode?: RoomMode /** optional, Room mode */;
|
|
352
|
+
translateConfig?: TranslateConfig /** optional, Translation configuration */;
|
|
353
|
+
turnDetection?: CreateRoomTurnDetection /** optional, Turn detection */;
|
|
35
354
|
}
|
|
36
355
|
declare class RealtimeClient extends RealtimeEventHandler {
|
|
37
356
|
_config: RealtimeClientConfig;
|
|
@@ -160,4 +479,6 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
|
160
479
|
*/
|
|
161
480
|
getRtcEngine(): IRTCEngine | undefined;
|
|
162
481
|
}
|
|
163
|
-
|
|
482
|
+
|
|
483
|
+
export { EventNames, RealtimeAPIError, RealtimeClient, RealtimeError, utils as RealtimeUtils };
|
|
484
|
+
export type { RealtimeClientConfig, VideoConfig };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as _coze_api from '@coze/api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WebRTC资源状态
|
|
5
|
+
*/
|
|
6
|
+
declare enum ResourceStatus {
|
|
7
|
+
IDLE = "idle",// 初始状态
|
|
8
|
+
CONNECTING = "connecting",// 连接中
|
|
9
|
+
CONNECTED = "connected",// 已连接
|
|
10
|
+
FAILED = "failed",// 连接失败
|
|
11
|
+
CLOSING = "closing",// 关闭中
|
|
12
|
+
CLOSED = "closed"
|
|
13
|
+
}
|
|
14
|
+
type StatusChangeCallback = (status: ResourceStatus) => void;
|
|
15
|
+
/**
|
|
16
|
+
* 同声传译客户端
|
|
17
|
+
*/
|
|
18
|
+
declare class WebLiveClient {
|
|
19
|
+
private peerConnection;
|
|
20
|
+
private resourceUrl;
|
|
21
|
+
private status;
|
|
22
|
+
private player;
|
|
23
|
+
private statusListeners;
|
|
24
|
+
private liveId;
|
|
25
|
+
constructor(liveId: string);
|
|
26
|
+
/**
|
|
27
|
+
* 获取当前连接状态
|
|
28
|
+
*/
|
|
29
|
+
getStatus(): ResourceStatus;
|
|
30
|
+
/**
|
|
31
|
+
* 添加状态变化监听器
|
|
32
|
+
* @param callback 状态变化回调函数
|
|
33
|
+
*/
|
|
34
|
+
onStatusChange(callback: StatusChangeCallback): void;
|
|
35
|
+
/**
|
|
36
|
+
* 移除状态变化监听器
|
|
37
|
+
* @param callback 要移除的回调函数
|
|
38
|
+
*/
|
|
39
|
+
offStatusChange(callback: StatusChangeCallback): void;
|
|
40
|
+
/**
|
|
41
|
+
* 移除状态变化监听器
|
|
42
|
+
* @param callback 要移除的回调函数
|
|
43
|
+
*/
|
|
44
|
+
removeStatusListener(callback: StatusChangeCallback): void;
|
|
45
|
+
/**
|
|
46
|
+
* 订阅音频资源
|
|
47
|
+
* @param appId 应用ID
|
|
48
|
+
* @param streamId 流ID
|
|
49
|
+
* @param clientId 客户端ID
|
|
50
|
+
*/
|
|
51
|
+
subscribe(appId: string, streamId: string, clientId?: string): Promise<{
|
|
52
|
+
status: ResourceStatus;
|
|
53
|
+
peerConnection: RTCPeerConnection;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* 销毁订阅资源
|
|
57
|
+
*/
|
|
58
|
+
unsubscribe(): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* 静音/取消静音
|
|
61
|
+
* @param muted 是否静音
|
|
62
|
+
*/
|
|
63
|
+
setMuted(muted: boolean): void;
|
|
64
|
+
/**
|
|
65
|
+
* 关闭并清理资源
|
|
66
|
+
*/
|
|
67
|
+
close(): void;
|
|
68
|
+
/**
|
|
69
|
+
* 获取直播信息
|
|
70
|
+
*/
|
|
71
|
+
getLiveData: () => Promise<_coze_api.RetrieveLiveData>;
|
|
72
|
+
/**
|
|
73
|
+
* 等待ICE收集完成
|
|
74
|
+
* @param pc RTCPeerConnection实例
|
|
75
|
+
*/
|
|
76
|
+
private waitForIceGathering;
|
|
77
|
+
private setupPeerConnectionListeners;
|
|
78
|
+
/**
|
|
79
|
+
* 关闭PeerConnection
|
|
80
|
+
*/
|
|
81
|
+
private closePeerConnection;
|
|
82
|
+
/**
|
|
83
|
+
* 设置状态并触发监听回调
|
|
84
|
+
* @param newStatus 新状态
|
|
85
|
+
* @private 私有方法,仅内部使用
|
|
86
|
+
*/
|
|
87
|
+
private setStatus;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { ResourceStatus, WebLiveClient };
|
|
91
|
+
export type { StatusChangeCallback };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coze/realtime-api",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2-alpha.f7fe14",
|
|
4
4
|
"description": "A powerful real-time communication SDK for voice interactions with Coze AI bots | 扣子官方实时通信 SDK,用于与 Coze AI bots 进行语音交互",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"coze",
|
|
@@ -31,12 +31,16 @@
|
|
|
31
31
|
"require": "./dist/cjs/event-names/index.js",
|
|
32
32
|
"import": "./dist/esm/event-names/index.js",
|
|
33
33
|
"types": "./dist/types/event-names/event-names.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./live": {
|
|
36
|
+
"require": "./dist/cjs/live/index.js",
|
|
37
|
+
"import": "./dist/esm/live/index.js",
|
|
38
|
+
"types": "./dist/types/live/live/index.d.ts"
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
41
|
"main": "dist/cjs/index.js",
|
|
37
|
-
"unpkg": "dist/umd/index.js",
|
|
38
42
|
"module": "dist/esm/index.js",
|
|
39
|
-
"types": "./
|
|
43
|
+
"types": "./dist/types/index.d.ts",
|
|
40
44
|
"files": [
|
|
41
45
|
"dist",
|
|
42
46
|
"LICENSE",
|
|
@@ -44,23 +48,30 @@
|
|
|
44
48
|
"README.zh-CN.md"
|
|
45
49
|
],
|
|
46
50
|
"scripts": {
|
|
47
|
-
"build": "
|
|
51
|
+
"build": "rollup -c",
|
|
52
|
+
"build:rslib": "rslib build",
|
|
48
53
|
"buildAll": "npm run build && cd ../../examples/realtime-console && npm run build",
|
|
49
54
|
"demo": "npm run start & cd ../../examples/realtime-console && npm run start",
|
|
50
55
|
"format": "prettier --write .",
|
|
51
56
|
"lint": "eslint ./ --cache --quiet",
|
|
52
|
-
"start": "
|
|
57
|
+
"start": "rollup -c -w",
|
|
58
|
+
"start:rslib": "rslib build -w",
|
|
53
59
|
"test": "vitest",
|
|
54
60
|
"test:cov": "vitest --coverage --run"
|
|
55
61
|
},
|
|
56
62
|
"dependencies": {
|
|
57
|
-
"@coze/api": "1.3.
|
|
63
|
+
"@coze/api": "1.3.7-alpha.f7fe14",
|
|
58
64
|
"@volcengine/rtc": "~4.62.11"
|
|
59
65
|
},
|
|
60
66
|
"devDependencies": {
|
|
61
67
|
"@coze-infra/eslint-config": "workspace:*",
|
|
62
68
|
"@coze-infra/ts-config": "workspace:*",
|
|
63
69
|
"@coze-infra/vitest-config": "workspace:*",
|
|
70
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
71
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
72
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
73
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
74
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
64
75
|
"@rslib/core": "0.0.18",
|
|
65
76
|
"@swc/core": "^1.3.14",
|
|
66
77
|
"@types/node": "^20",
|
|
@@ -68,6 +79,10 @@
|
|
|
68
79
|
"@types/whatwg-fetch": "^0.0.33",
|
|
69
80
|
"@vitest/coverage-v8": "~2.1.9",
|
|
70
81
|
"axios": "^1.7.7",
|
|
82
|
+
"rollup": "^4.31.0",
|
|
83
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
84
|
+
"rollup-plugin-node-externals": "^7.1.3",
|
|
85
|
+
"tslib": "^2.8.1",
|
|
71
86
|
"typescript": "^5.5.3",
|
|
72
87
|
"vitest": "~2.1.9"
|
|
73
88
|
},
|
|
@@ -86,6 +101,11 @@
|
|
|
86
101
|
"require": "./dist/cjs/event-names/index.js",
|
|
87
102
|
"import": "./dist/esm/event-names/index.js",
|
|
88
103
|
"types": "./dist/types/event-names/event-names.d.ts"
|
|
104
|
+
},
|
|
105
|
+
"./live": {
|
|
106
|
+
"require": "./dist/cjs/live/index.js",
|
|
107
|
+
"import": "./dist/esm/live/index.js",
|
|
108
|
+
"types": "./dist/types/live/live/index.d.ts"
|
|
89
109
|
}
|
|
90
110
|
},
|
|
91
111
|
"main": "dist/cjs/index.js",
|
package/dist/types/client.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { type AudioPropertiesConfig, type IRTCEngine, type NetworkQuality, type onUserJoinedEvent, type onUserLeaveEvent, type UserMessageEvent } from '@volcengine/rtc';
|
|
2
|
-
import { RealtimeEventHandler } from './event-handler';
|
|
3
|
-
import { type VideoConfig } from '.';
|
|
4
|
-
export declare class EngineClient extends RealtimeEventHandler {
|
|
5
|
-
private engine;
|
|
6
|
-
private joinUserId;
|
|
7
|
-
private _AIAnsExtension;
|
|
8
|
-
private _isSupportVideo;
|
|
9
|
-
private _videoConfig?;
|
|
10
|
-
private _streamIndex?;
|
|
11
|
-
private _roomUserId?;
|
|
12
|
-
constructor(appId: string, debug?: boolean, isTestEnv?: boolean, isSupportVideo?: boolean, videoConfig?: VideoConfig);
|
|
13
|
-
bindEngineEvents(): void;
|
|
14
|
-
removeEventListener(): void;
|
|
15
|
-
_parseMessage(event: UserMessageEvent): any;
|
|
16
|
-
handleMessage(event: UserMessageEvent): void;
|
|
17
|
-
handleEventError(e: unknown): void;
|
|
18
|
-
handleUserJoin(event: onUserJoinedEvent): void;
|
|
19
|
-
handleUserLeave(event: onUserLeaveEvent): void;
|
|
20
|
-
handlePlayerEvent(event: unknown): void;
|
|
21
|
-
handleNetworkQuality(uplinkNetworkQuality: NetworkQuality, downlinkNetworkQuality: NetworkQuality): void;
|
|
22
|
-
handleTrackEnded(event: any): void;
|
|
23
|
-
joinRoom(options: {
|
|
24
|
-
token: string;
|
|
25
|
-
roomId: string;
|
|
26
|
-
uid: string;
|
|
27
|
-
audioMutedDefault?: boolean;
|
|
28
|
-
videoOnDefault?: boolean;
|
|
29
|
-
isAutoSubscribeAudio?: boolean;
|
|
30
|
-
}): Promise<void>;
|
|
31
|
-
setAudioInputDevice(deviceId: string): Promise<void>;
|
|
32
|
-
setAudioOutputDevice(deviceId: string): Promise<void>;
|
|
33
|
-
setVideoInputDevice(deviceId: string, isAutoCapture?: boolean): Promise<void>;
|
|
34
|
-
createLocalStream(userId?: string, videoConfig?: VideoConfig): Promise<void>;
|
|
35
|
-
disconnect(): Promise<void>;
|
|
36
|
-
changeAudioState(isMicOn: boolean): Promise<void>;
|
|
37
|
-
changeVideoState(isVideoOn: boolean): Promise<void>;
|
|
38
|
-
stop(): Promise<void>;
|
|
39
|
-
sendMessage(message: Record<string, unknown>): Promise<void>;
|
|
40
|
-
enableAudioPropertiesReport(config?: AudioPropertiesConfig): void;
|
|
41
|
-
handleLocalAudioPropertiesReport(event: any): void;
|
|
42
|
-
handleRemoteAudioPropertiesReport(event: unknown): void;
|
|
43
|
-
enableAudioNoiseReduction(): Promise<void>;
|
|
44
|
-
initAIAnsExtension(): Promise<void>;
|
|
45
|
-
changeAIAnsExtension(enable: boolean): void;
|
|
46
|
-
startAudioPlaybackDeviceTest(): Promise<void>;
|
|
47
|
-
stopAudioPlaybackDeviceTest(): void;
|
|
48
|
-
getRtcEngine(): IRTCEngine;
|
|
49
|
-
}
|
package/dist/types/error.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare enum RealtimeError {
|
|
2
|
-
DEVICE_ACCESS_ERROR = "DEVICE_ACCESS_ERROR",
|
|
3
|
-
STREAM_CREATION_ERROR = "STREAM_CREATION_ERROR",
|
|
4
|
-
CONNECTION_ERROR = "CONNECTION_ERROR",
|
|
5
|
-
DISCONNECTION_ERROR = "DISCONNECTION_ERROR",
|
|
6
|
-
INTERRUPT_ERROR = "INTERRUPT_ERROR",
|
|
7
|
-
EVENT_HANDLER_ERROR = "EVENT_HANDLER_ERROR",
|
|
8
|
-
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
9
|
-
NETWORK_ERROR = "NETWORK_ERROR",
|
|
10
|
-
INVALID_STATE = "INVALID_STATE",
|
|
11
|
-
CREATE_ROOM_ERROR = "CREATE_ROOM_ERROR",
|
|
12
|
-
PARSE_MESSAGE_ERROR = "PARSE_MESSAGE_ERROR",
|
|
13
|
-
HANDLER_MESSAGE_ERROR = "HANDLER_MESSAGE_ERROR"
|
|
14
|
-
}
|
|
15
|
-
export declare const ErrorMessages: Record<RealtimeError, string>;
|
|
16
|
-
export declare class RealtimeAPIError extends Error {
|
|
17
|
-
code: RealtimeError;
|
|
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);
|
|
25
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type EventCallback = (eventName: string, event: unknown) => void;
|
|
2
|
-
export declare class RealtimeEventHandler {
|
|
3
|
-
private eventHandlers;
|
|
4
|
-
protected _debug: boolean;
|
|
5
|
-
constructor(debug?: boolean);
|
|
6
|
-
clearEventHandlers(): void;
|
|
7
|
-
on(eventName: string, callback: EventCallback): EventCallback;
|
|
8
|
-
off(eventName: string, callback: EventCallback): void;
|
|
9
|
-
private _dispatchToHandlers;
|
|
10
|
-
dispatch(eventName: string, event: unknown, consoleLog?: boolean): void;
|
|
11
|
-
_log(message: string, event?: unknown): void;
|
|
12
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { type AudioPropertiesConfig, type IRTCEngine, type NetworkQuality, type onUserJoinedEvent, type onUserLeaveEvent, type UserMessageEvent } from '@volcengine/rtc';
|
|
2
|
-
import { RealtimeEventHandler } from './event-handler';
|
|
3
|
-
import { type VideoConfig } from '.';
|
|
4
|
-
export declare class EngineClient extends RealtimeEventHandler {
|
|
5
|
-
private engine;
|
|
6
|
-
private joinUserId;
|
|
7
|
-
private _AIAnsExtension;
|
|
8
|
-
private _isSupportVideo;
|
|
9
|
-
private _videoConfig?;
|
|
10
|
-
private _streamIndex?;
|
|
11
|
-
private _roomUserId?;
|
|
12
|
-
constructor(appId: string, debug?: boolean, isTestEnv?: boolean, isSupportVideo?: boolean, videoConfig?: VideoConfig);
|
|
13
|
-
bindEngineEvents(): void;
|
|
14
|
-
removeEventListener(): void;
|
|
15
|
-
_parseMessage(event: UserMessageEvent): any;
|
|
16
|
-
handleMessage(event: UserMessageEvent): void;
|
|
17
|
-
handleEventError(e: unknown): void;
|
|
18
|
-
handleUserJoin(event: onUserJoinedEvent): void;
|
|
19
|
-
handleUserLeave(event: onUserLeaveEvent): void;
|
|
20
|
-
handlePlayerEvent(event: unknown): void;
|
|
21
|
-
handleNetworkQuality(uplinkNetworkQuality: NetworkQuality, downlinkNetworkQuality: NetworkQuality): void;
|
|
22
|
-
handleTrackEnded(event: any): void;
|
|
23
|
-
joinRoom(options: {
|
|
24
|
-
token: string;
|
|
25
|
-
roomId: string;
|
|
26
|
-
uid: string;
|
|
27
|
-
audioMutedDefault?: boolean;
|
|
28
|
-
videoOnDefault?: boolean;
|
|
29
|
-
isAutoSubscribeAudio?: boolean;
|
|
30
|
-
}): Promise<void>;
|
|
31
|
-
setAudioInputDevice(deviceId: string): Promise<void>;
|
|
32
|
-
setAudioOutputDevice(deviceId: string): Promise<void>;
|
|
33
|
-
setVideoInputDevice(deviceId: string, isAutoCapture?: boolean): Promise<void>;
|
|
34
|
-
createLocalStream(userId?: string, videoConfig?: VideoConfig): Promise<void>;
|
|
35
|
-
disconnect(): Promise<void>;
|
|
36
|
-
changeAudioState(isMicOn: boolean): Promise<void>;
|
|
37
|
-
changeVideoState(isVideoOn: boolean): Promise<void>;
|
|
38
|
-
stop(): Promise<void>;
|
|
39
|
-
sendMessage(message: Record<string, unknown>): Promise<void>;
|
|
40
|
-
enableAudioPropertiesReport(config?: AudioPropertiesConfig): void;
|
|
41
|
-
handleLocalAudioPropertiesReport(event: any): void;
|
|
42
|
-
handleRemoteAudioPropertiesReport(event: unknown): void;
|
|
43
|
-
enableAudioNoiseReduction(): Promise<void>;
|
|
44
|
-
initAIAnsExtension(): Promise<void>;
|
|
45
|
-
changeAIAnsExtension(enable: boolean): void;
|
|
46
|
-
startAudioPlaybackDeviceTest(): Promise<void>;
|
|
47
|
-
stopAudioPlaybackDeviceTest(): void;
|
|
48
|
-
getRtcEngine(): IRTCEngine;
|
|
49
|
-
}
|