@coze/realtime-api 1.3.0 → 1.3.1
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 +4 -0
- package/dist/cjs/index.js +10 -3
- package/dist/cjs/live/index.js +292 -0
- package/dist/esm/event-names/index.js +4 -0
- package/dist/esm/index.js +10 -3
- package/dist/esm/live/index.js +250 -0
- package/dist/types/event-names/event-names.d.ts +6 -1
- package/dist/types/event-names/index.d.ts +2 -1
- package/dist/types/event-names/live/index.d.ts +86 -0
- package/dist/types/event-names.d.ts +6 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/live/client.d.ts +49 -0
- package/dist/types/live/error.d.ts +25 -0
- package/dist/types/live/event-handler.d.ts +12 -0
- package/dist/types/live/event-names.d.ts +213 -0
- package/dist/types/live/index.d.ts +86 -0
- package/dist/types/live/live/index.d.ts +86 -0
- package/dist/types/live/utils.d.ts +49 -0
- package/dist/umd/index.js +10 -3
- package/package.json +12 -2
@@ -203,6 +203,11 @@ declare enum EventNames {
|
|
203
203
|
* en: Mode updated
|
204
204
|
* zh: 更新房间模式成功
|
205
205
|
*/
|
206
|
-
MODE_UPDATED = "server.mode.updated"
|
206
|
+
MODE_UPDATED = "server.mode.updated",
|
207
|
+
/**
|
208
|
+
* en: Live created
|
209
|
+
* zh: 直播创建
|
210
|
+
*/
|
211
|
+
LIVE_CREATED = "server.live.created"
|
207
212
|
}
|
208
213
|
export default EventNames;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type ScreenConfig, type AudioPropertiesConfig, type IRTCEngine } from '@volcengine/rtc';
|
2
|
-
import { type CreateRoomData, type GetToken, type
|
2
|
+
import { RoomMode, type CreateRoomData, type GetToken, type TranslateConfig } from '@coze/api';
|
3
3
|
import * as RealtimeUtils from './utils';
|
4
4
|
import EventNames from './event-names';
|
5
5
|
import { RealtimeEventHandler } from './event-handler';
|
@@ -32,6 +32,7 @@ export interface RealtimeClientConfig {
|
|
32
32
|
isAutoSubscribeAudio?: boolean /** optional, Whether to automatically subscribe to bot reply audio streams, defaults to true */;
|
33
33
|
prologueContent?: string /** optional, Prologue content */;
|
34
34
|
roomMode?: RoomMode /** optional, Room mode */;
|
35
|
+
translateConfig?: TranslateConfig /** optional, Translation configuration */;
|
35
36
|
}
|
36
37
|
declare class RealtimeClient extends RealtimeEventHandler {
|
37
38
|
_config: RealtimeClientConfig;
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/**
|
2
|
+
* WebRTC资源状态
|
3
|
+
*/
|
4
|
+
export declare enum ResourceStatus {
|
5
|
+
IDLE = "idle",// 初始状态
|
6
|
+
CONNECTING = "connecting",// 连接中
|
7
|
+
CONNECTED = "connected",// 已连接
|
8
|
+
FAILED = "failed",// 连接失败
|
9
|
+
CLOSING = "closing",// 关闭中
|
10
|
+
CLOSED = "closed"
|
11
|
+
}
|
12
|
+
export type StatusChangeCallback = (status: ResourceStatus) => void;
|
13
|
+
/**
|
14
|
+
* 同声传译客户端
|
15
|
+
*/
|
16
|
+
export declare class WebLiveClient {
|
17
|
+
private peerConnection;
|
18
|
+
private resourceUrl;
|
19
|
+
private status;
|
20
|
+
private player;
|
21
|
+
private statusListeners;
|
22
|
+
private liveId;
|
23
|
+
constructor(liveId: string);
|
24
|
+
/**
|
25
|
+
* 获取当前连接状态
|
26
|
+
*/
|
27
|
+
getStatus(): ResourceStatus;
|
28
|
+
/**
|
29
|
+
* 添加状态变化监听器
|
30
|
+
* @param callback 状态变化回调函数
|
31
|
+
*/
|
32
|
+
onStatusChange(callback: StatusChangeCallback): void;
|
33
|
+
/**
|
34
|
+
* 移除状态变化监听器
|
35
|
+
* @param callback 要移除的回调函数
|
36
|
+
*/
|
37
|
+
offStatusChange(callback: StatusChangeCallback): void;
|
38
|
+
/**
|
39
|
+
* 移除状态变化监听器
|
40
|
+
* @param callback 要移除的回调函数
|
41
|
+
*/
|
42
|
+
removeStatusListener(callback: StatusChangeCallback): void;
|
43
|
+
/**
|
44
|
+
* 订阅音频资源
|
45
|
+
* @param appId 应用ID
|
46
|
+
* @param streamId 流ID
|
47
|
+
* @param clientId 客户端ID
|
48
|
+
*/
|
49
|
+
subscribe(appId: string, streamId: string, clientId?: string): Promise<{
|
50
|
+
status: ResourceStatus;
|
51
|
+
peerConnection: RTCPeerConnection;
|
52
|
+
}>;
|
53
|
+
/**
|
54
|
+
* 销毁订阅资源
|
55
|
+
*/
|
56
|
+
unsubscribe(): Promise<boolean>;
|
57
|
+
/**
|
58
|
+
* 静音/取消静音
|
59
|
+
* @param muted 是否静音
|
60
|
+
*/
|
61
|
+
setMuted(muted: boolean): void;
|
62
|
+
/**
|
63
|
+
* 关闭并清理资源
|
64
|
+
*/
|
65
|
+
close(): void;
|
66
|
+
/**
|
67
|
+
* 获取直播信息
|
68
|
+
*/
|
69
|
+
getLiveData: () => Promise<import("@coze/api").RetrieveLiveData>;
|
70
|
+
/**
|
71
|
+
* 等待ICE收集完成
|
72
|
+
* @param pc RTCPeerConnection实例
|
73
|
+
*/
|
74
|
+
private waitForIceGathering;
|
75
|
+
private setupPeerConnectionListeners;
|
76
|
+
/**
|
77
|
+
* 关闭PeerConnection
|
78
|
+
*/
|
79
|
+
private closePeerConnection;
|
80
|
+
/**
|
81
|
+
* 设置状态并触发监听回调
|
82
|
+
* @param newStatus 新状态
|
83
|
+
* @private 私有方法,仅内部使用
|
84
|
+
*/
|
85
|
+
private setStatus;
|
86
|
+
}
|
@@ -203,6 +203,11 @@ declare enum EventNames {
|
|
203
203
|
* en: Mode updated
|
204
204
|
* zh: 更新房间模式成功
|
205
205
|
*/
|
206
|
-
MODE_UPDATED = "server.mode.updated"
|
206
|
+
MODE_UPDATED = "server.mode.updated",
|
207
|
+
/**
|
208
|
+
* en: Live created
|
209
|
+
* zh: 直播创建
|
210
|
+
*/
|
211
|
+
LIVE_CREATED = "server.live.created"
|
207
212
|
}
|
208
213
|
export default EventNames;
|
package/dist/types/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type ScreenConfig, type AudioPropertiesConfig, type IRTCEngine } from '@volcengine/rtc';
|
2
|
-
import { type CreateRoomData, type GetToken, type
|
2
|
+
import { RoomMode, type CreateRoomData, type GetToken, type TranslateConfig } from '@coze/api';
|
3
3
|
import * as RealtimeUtils from './utils';
|
4
4
|
import EventNames from './event-names';
|
5
5
|
import { RealtimeEventHandler } from './event-handler';
|
@@ -32,6 +32,7 @@ export interface RealtimeClientConfig {
|
|
32
32
|
isAutoSubscribeAudio?: boolean /** optional, Whether to automatically subscribe to bot reply audio streams, defaults to true */;
|
33
33
|
prologueContent?: string /** optional, Prologue content */;
|
34
34
|
roomMode?: RoomMode /** optional, Room mode */;
|
35
|
+
translateConfig?: TranslateConfig /** optional, Translation configuration */;
|
35
36
|
}
|
36
37
|
declare class RealtimeClient extends RealtimeEventHandler {
|
37
38
|
_config: RealtimeClientConfig;
|
@@ -0,0 +1,49 @@
|
|
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
|
+
}
|
@@ -0,0 +1,25 @@
|
|
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
|
+
}
|
@@ -0,0 +1,12 @@
|
|
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
|
+
}
|
@@ -0,0 +1,213 @@
|
|
1
|
+
declare enum EventNames {
|
2
|
+
/**
|
3
|
+
* en: All events
|
4
|
+
* zh: 所有事件
|
5
|
+
*/
|
6
|
+
ALL = "realtime.event",
|
7
|
+
/**
|
8
|
+
* en: All client events
|
9
|
+
* zh: 所有客户端事件
|
10
|
+
*/
|
11
|
+
ALL_CLIENT = "client.*",
|
12
|
+
/**
|
13
|
+
* en: All server events
|
14
|
+
* zh: 所有服务端事件
|
15
|
+
*/
|
16
|
+
ALL_SERVER = "server.*",
|
17
|
+
/**
|
18
|
+
* en: Room info
|
19
|
+
* zh: 房间信息
|
20
|
+
*/
|
21
|
+
ROOM_INFO = "client.room.info",
|
22
|
+
/**
|
23
|
+
* en: Client connected
|
24
|
+
* zh: 客户端连接
|
25
|
+
*/
|
26
|
+
CONNECTED = "client.connected",
|
27
|
+
/**
|
28
|
+
* en: Client connecting
|
29
|
+
* zh: 客户端连接中
|
30
|
+
*/
|
31
|
+
CONNECTING = "client.connecting",
|
32
|
+
/**
|
33
|
+
* en: Client interrupted
|
34
|
+
* zh: 客户端中断
|
35
|
+
*/
|
36
|
+
INTERRUPTED = "client.interrupted",
|
37
|
+
/**
|
38
|
+
* en: Client disconnected
|
39
|
+
* zh: 客户端断开
|
40
|
+
*/
|
41
|
+
DISCONNECTED = "client.disconnected",
|
42
|
+
/**
|
43
|
+
* en: Client audio unmuted
|
44
|
+
* zh: 客户端音频未静音
|
45
|
+
*/
|
46
|
+
AUDIO_UNMUTED = "client.audio.unmuted",
|
47
|
+
/**
|
48
|
+
* en: Client audio muted
|
49
|
+
* zh: 客户端音频静音
|
50
|
+
*/
|
51
|
+
AUDIO_MUTED = "client.audio.muted",
|
52
|
+
/**
|
53
|
+
* en: Client video on
|
54
|
+
* zh: 客户端视频开启
|
55
|
+
*/
|
56
|
+
VIDEO_ON = "client.video.on",
|
57
|
+
/**
|
58
|
+
* en: Client video off
|
59
|
+
* zh: 客户端视频关闭
|
60
|
+
*/
|
61
|
+
VIDEO_OFF = "client.video.off",
|
62
|
+
/**
|
63
|
+
* en: Client video error
|
64
|
+
* zh: 客户端视频(或屏幕共享)错误
|
65
|
+
*/
|
66
|
+
VIDEO_ERROR = "client.video.error",
|
67
|
+
/**
|
68
|
+
* en: Client video event
|
69
|
+
* zh: 客户端视频事件
|
70
|
+
*/
|
71
|
+
PLAYER_EVENT = "client.video.event",
|
72
|
+
/**
|
73
|
+
* en: Client error
|
74
|
+
* zh: 客户端错误
|
75
|
+
*/
|
76
|
+
ERROR = "client.error",
|
77
|
+
/**
|
78
|
+
* en: Audio noise reduction enabled
|
79
|
+
* zh: 抑制平稳噪声
|
80
|
+
*/
|
81
|
+
SUPPRESS_STATIONARY_NOISE = "client.suppress.stationary.noise",
|
82
|
+
/**
|
83
|
+
* en: Suppress non-stationary noise
|
84
|
+
* zh: 抑制非平稳噪声
|
85
|
+
*/
|
86
|
+
SUPPRESS_NON_STATIONARY_NOISE = "client.suppress.non.stationary.noise",
|
87
|
+
/**
|
88
|
+
* en: Audio input device changed
|
89
|
+
* zh: 音频输入设备改变
|
90
|
+
*/
|
91
|
+
AUDIO_INPUT_DEVICE_CHANGED = "client.input.device.changed",
|
92
|
+
/**
|
93
|
+
* en: Audio output device changed
|
94
|
+
* zh: 音频输出设备改变
|
95
|
+
*/
|
96
|
+
AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
|
97
|
+
/**
|
98
|
+
* en: Video input device changed
|
99
|
+
* zh: 视频输入设备改变
|
100
|
+
*/
|
101
|
+
VIDEO_INPUT_DEVICE_CHANGED = "client.video.input.device.changed",
|
102
|
+
/**
|
103
|
+
* en: Network quality changed
|
104
|
+
* zh: 网络质量改变
|
105
|
+
*/
|
106
|
+
NETWORK_QUALITY = "client.network.quality",
|
107
|
+
/**
|
108
|
+
* en: Bot joined
|
109
|
+
* zh: Bot 加入
|
110
|
+
*/
|
111
|
+
BOT_JOIN = "server.bot.join",
|
112
|
+
/**
|
113
|
+
* en: Bot left
|
114
|
+
* zh: Bot 离开
|
115
|
+
*/
|
116
|
+
BOT_LEAVE = "server.bot.leave",
|
117
|
+
/**
|
118
|
+
* en: Audio speech started
|
119
|
+
* zh: 开始说话
|
120
|
+
*/
|
121
|
+
AUDIO_AGENT_SPEECH_STARTED = "server.audio.agent.speech_started",
|
122
|
+
/**
|
123
|
+
* en: Audio speech stopped
|
124
|
+
* zh: 停止说话
|
125
|
+
*/
|
126
|
+
AUDIO_AGENT_SPEECH_STOPPED = "server.audio.agent.speech_stopped",
|
127
|
+
/**
|
128
|
+
* en: Server error
|
129
|
+
* zh: 服务端错误
|
130
|
+
*/
|
131
|
+
SERVER_ERROR = "server.error",
|
132
|
+
/**
|
133
|
+
* en: User speech started
|
134
|
+
* zh: 用户开始说话
|
135
|
+
*/
|
136
|
+
AUDIO_USER_SPEECH_STARTED = "server.audio.user.speech_started",
|
137
|
+
/**
|
138
|
+
* en: User speech stopped
|
139
|
+
* zh: 用户停止说话
|
140
|
+
*/
|
141
|
+
AUDIO_USER_SPEECH_STOPPED = "server.audio.user.speech_stopped",
|
142
|
+
/**
|
143
|
+
* en: User successfully enters the room
|
144
|
+
* zh: 用户成功进入房间后,会收到该事件
|
145
|
+
*/
|
146
|
+
SESSION_CREATED = "server.session.created",
|
147
|
+
/**
|
148
|
+
* en: Session updated
|
149
|
+
* zh: 会话更新
|
150
|
+
*/
|
151
|
+
SESSION_UPDATED = "server.session.updated",
|
152
|
+
/**
|
153
|
+
* en: Conversation created
|
154
|
+
* zh: 会话创建
|
155
|
+
*/
|
156
|
+
CONVERSATION_CREATED = "server.conversation.created",
|
157
|
+
/**
|
158
|
+
* en: Conversation chat created
|
159
|
+
* zh: 会话对话创建
|
160
|
+
*/
|
161
|
+
CONVERSATION_CHAT_CREATED = "server.conversation.chat.created",
|
162
|
+
/**
|
163
|
+
* en: Conversation chat in progress
|
164
|
+
* zh: 对话正在处理中
|
165
|
+
*/
|
166
|
+
CONVERSATION_CHAT_IN_PROGRESS = "server.conversation.chat.in_progress",
|
167
|
+
/**
|
168
|
+
* en: Conversation message delta received
|
169
|
+
* zh: 文本消息增量返回
|
170
|
+
*/
|
171
|
+
CONVERSATION_MESSAGE_DELTA = "server.conversation.message.delta",
|
172
|
+
/**
|
173
|
+
* en: Conversation message completed
|
174
|
+
* zh: 文本消息完成
|
175
|
+
*/
|
176
|
+
CONVERSATION_MESSAGE_COMPLETED = "server.conversation.message.completed",
|
177
|
+
/**
|
178
|
+
* en: Conversation chat completed
|
179
|
+
* zh: 对话完成
|
180
|
+
*/
|
181
|
+
CONVERSATION_CHAT_COMPLETED = "server.conversation.chat.completed",
|
182
|
+
/**
|
183
|
+
* en: Conversation chat requires action
|
184
|
+
* zh: 对话需要插件
|
185
|
+
*/
|
186
|
+
CONVERSATION_CHAT_REQUIRES_ACTION = "server.conversation.chat.requires_action",
|
187
|
+
/**
|
188
|
+
* en: Conversation chat failed
|
189
|
+
* zh: 对话失败
|
190
|
+
*/
|
191
|
+
CONVERSATION_CHAT_FAILED = "server.conversation.chat.failed",
|
192
|
+
/**
|
193
|
+
* en: Session pre answer updated
|
194
|
+
* zh: 安抚配置更新成功
|
195
|
+
*/
|
196
|
+
SESSION_PRE_ANSWER_UPDATED = "server.session.pre_answer.updated",
|
197
|
+
/**
|
198
|
+
* en: Conversation audio transcript delta
|
199
|
+
* zh: 用户语音识别字幕
|
200
|
+
*/
|
201
|
+
CONVERSATION_AUDIO_TRANSCRIPT_DELTA = "server.conversation.audio_transcript.delta",
|
202
|
+
/**
|
203
|
+
* en: Mode updated
|
204
|
+
* zh: 更新房间模式成功
|
205
|
+
*/
|
206
|
+
MODE_UPDATED = "server.mode.updated",
|
207
|
+
/**
|
208
|
+
* en: Live created
|
209
|
+
* zh: 直播创建
|
210
|
+
*/
|
211
|
+
LIVE_CREATED = "server.live.created"
|
212
|
+
}
|
213
|
+
export default EventNames;
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/**
|
2
|
+
* WebRTC资源状态
|
3
|
+
*/
|
4
|
+
export declare enum ResourceStatus {
|
5
|
+
IDLE = "idle",// 初始状态
|
6
|
+
CONNECTING = "connecting",// 连接中
|
7
|
+
CONNECTED = "connected",// 已连接
|
8
|
+
FAILED = "failed",// 连接失败
|
9
|
+
CLOSING = "closing",// 关闭中
|
10
|
+
CLOSED = "closed"
|
11
|
+
}
|
12
|
+
export type StatusChangeCallback = (status: ResourceStatus) => void;
|
13
|
+
/**
|
14
|
+
* 同声传译客户端
|
15
|
+
*/
|
16
|
+
export declare class WebLiveClient {
|
17
|
+
private peerConnection;
|
18
|
+
private resourceUrl;
|
19
|
+
private status;
|
20
|
+
private player;
|
21
|
+
private statusListeners;
|
22
|
+
private liveId;
|
23
|
+
constructor(liveId: string);
|
24
|
+
/**
|
25
|
+
* 获取当前连接状态
|
26
|
+
*/
|
27
|
+
getStatus(): ResourceStatus;
|
28
|
+
/**
|
29
|
+
* 添加状态变化监听器
|
30
|
+
* @param callback 状态变化回调函数
|
31
|
+
*/
|
32
|
+
onStatusChange(callback: StatusChangeCallback): void;
|
33
|
+
/**
|
34
|
+
* 移除状态变化监听器
|
35
|
+
* @param callback 要移除的回调函数
|
36
|
+
*/
|
37
|
+
offStatusChange(callback: StatusChangeCallback): void;
|
38
|
+
/**
|
39
|
+
* 移除状态变化监听器
|
40
|
+
* @param callback 要移除的回调函数
|
41
|
+
*/
|
42
|
+
removeStatusListener(callback: StatusChangeCallback): void;
|
43
|
+
/**
|
44
|
+
* 订阅音频资源
|
45
|
+
* @param appId 应用ID
|
46
|
+
* @param streamId 流ID
|
47
|
+
* @param clientId 客户端ID
|
48
|
+
*/
|
49
|
+
subscribe(appId: string, streamId: string, clientId?: string): Promise<{
|
50
|
+
status: ResourceStatus;
|
51
|
+
peerConnection: RTCPeerConnection;
|
52
|
+
}>;
|
53
|
+
/**
|
54
|
+
* 销毁订阅资源
|
55
|
+
*/
|
56
|
+
unsubscribe(): Promise<boolean>;
|
57
|
+
/**
|
58
|
+
* 静音/取消静音
|
59
|
+
* @param muted 是否静音
|
60
|
+
*/
|
61
|
+
setMuted(muted: boolean): void;
|
62
|
+
/**
|
63
|
+
* 关闭并清理资源
|
64
|
+
*/
|
65
|
+
close(): void;
|
66
|
+
/**
|
67
|
+
* 获取直播信息
|
68
|
+
*/
|
69
|
+
getLiveData: () => Promise<import("@coze/api").RetrieveLiveData>;
|
70
|
+
/**
|
71
|
+
* 等待ICE收集完成
|
72
|
+
* @param pc RTCPeerConnection实例
|
73
|
+
*/
|
74
|
+
private waitForIceGathering;
|
75
|
+
private setupPeerConnectionListeners;
|
76
|
+
/**
|
77
|
+
* 关闭PeerConnection
|
78
|
+
*/
|
79
|
+
private closePeerConnection;
|
80
|
+
/**
|
81
|
+
* 设置状态并触发监听回调
|
82
|
+
* @param newStatus 新状态
|
83
|
+
* @private 私有方法,仅内部使用
|
84
|
+
*/
|
85
|
+
private setStatus;
|
86
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/**
|
2
|
+
* WebRTC资源状态
|
3
|
+
*/
|
4
|
+
export declare enum ResourceStatus {
|
5
|
+
IDLE = "idle",// 初始状态
|
6
|
+
CONNECTING = "connecting",// 连接中
|
7
|
+
CONNECTED = "connected",// 已连接
|
8
|
+
FAILED = "failed",// 连接失败
|
9
|
+
CLOSING = "closing",// 关闭中
|
10
|
+
CLOSED = "closed"
|
11
|
+
}
|
12
|
+
export type StatusChangeCallback = (status: ResourceStatus) => void;
|
13
|
+
/**
|
14
|
+
* 同声传译客户端
|
15
|
+
*/
|
16
|
+
export declare class WebLiveClient {
|
17
|
+
private peerConnection;
|
18
|
+
private resourceUrl;
|
19
|
+
private status;
|
20
|
+
private player;
|
21
|
+
private statusListeners;
|
22
|
+
private liveId;
|
23
|
+
constructor(liveId: string);
|
24
|
+
/**
|
25
|
+
* 获取当前连接状态
|
26
|
+
*/
|
27
|
+
getStatus(): ResourceStatus;
|
28
|
+
/**
|
29
|
+
* 添加状态变化监听器
|
30
|
+
* @param callback 状态变化回调函数
|
31
|
+
*/
|
32
|
+
onStatusChange(callback: StatusChangeCallback): void;
|
33
|
+
/**
|
34
|
+
* 移除状态变化监听器
|
35
|
+
* @param callback 要移除的回调函数
|
36
|
+
*/
|
37
|
+
offStatusChange(callback: StatusChangeCallback): void;
|
38
|
+
/**
|
39
|
+
* 移除状态变化监听器
|
40
|
+
* @param callback 要移除的回调函数
|
41
|
+
*/
|
42
|
+
removeStatusListener(callback: StatusChangeCallback): void;
|
43
|
+
/**
|
44
|
+
* 订阅音频资源
|
45
|
+
* @param appId 应用ID
|
46
|
+
* @param streamId 流ID
|
47
|
+
* @param clientId 客户端ID
|
48
|
+
*/
|
49
|
+
subscribe(appId: string, streamId: string, clientId?: string): Promise<{
|
50
|
+
status: ResourceStatus;
|
51
|
+
peerConnection: RTCPeerConnection;
|
52
|
+
}>;
|
53
|
+
/**
|
54
|
+
* 销毁订阅资源
|
55
|
+
*/
|
56
|
+
unsubscribe(): Promise<boolean>;
|
57
|
+
/**
|
58
|
+
* 静音/取消静音
|
59
|
+
* @param muted 是否静音
|
60
|
+
*/
|
61
|
+
setMuted(muted: boolean): void;
|
62
|
+
/**
|
63
|
+
* 关闭并清理资源
|
64
|
+
*/
|
65
|
+
close(): void;
|
66
|
+
/**
|
67
|
+
* 获取直播信息
|
68
|
+
*/
|
69
|
+
getLiveData: () => Promise<import("@coze/api").RetrieveLiveData>;
|
70
|
+
/**
|
71
|
+
* 等待ICE收集完成
|
72
|
+
* @param pc RTCPeerConnection实例
|
73
|
+
*/
|
74
|
+
private waitForIceGathering;
|
75
|
+
private setupPeerConnectionListeners;
|
76
|
+
/**
|
77
|
+
* 关闭PeerConnection
|
78
|
+
*/
|
79
|
+
private closePeerConnection;
|
80
|
+
/**
|
81
|
+
* 设置状态并触发监听回调
|
82
|
+
* @param newStatus 新状态
|
83
|
+
* @private 私有方法,仅内部使用
|
84
|
+
*/
|
85
|
+
private setStatus;
|
86
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
+ * Delays execution for the specified duration
|
3
|
+
+ * @param milliseconds The time to sleep in milliseconds
|
4
|
+
+ * @throws {Error} If milliseconds is negative
|
5
|
+
+ * @returns Promise that resolves after the specified duration
|
6
|
+
+ */
|
7
|
+
export declare const sleep: (milliseconds: number) => Promise<void>;
|
8
|
+
/**
|
9
|
+
* @deprecated use checkDevicePermission instead
|
10
|
+
* Check microphone permission,return boolean
|
11
|
+
*/
|
12
|
+
export declare const checkPermission: ({ audio, video, }?: {
|
13
|
+
audio?: boolean;
|
14
|
+
video?: boolean;
|
15
|
+
}) => Promise<boolean>;
|
16
|
+
/**
|
17
|
+
* Checks device permissions for audio and video
|
18
|
+
* @param checkVideo Whether to check video permissions (default: false)
|
19
|
+
* @returns Promise that resolves with the device permission status
|
20
|
+
*/
|
21
|
+
export declare const checkDevicePermission: (checkVideo?: boolean) => Promise<{
|
22
|
+
video: boolean;
|
23
|
+
audio: boolean;
|
24
|
+
videoExceptionError?: DOMException | undefined;
|
25
|
+
audioExceptionError?: DOMException | undefined;
|
26
|
+
}>;
|
27
|
+
/**
|
28
|
+
* Get audio devices
|
29
|
+
* @returns Promise<AudioDevices> Object containing arrays of audio input and output devices
|
30
|
+
*/
|
31
|
+
export declare const getAudioDevices: ({ video, }?: {
|
32
|
+
video?: boolean;
|
33
|
+
}) => Promise<{
|
34
|
+
audioInputs: MediaDeviceInfo[];
|
35
|
+
audioOutputs: MediaDeviceInfo[];
|
36
|
+
videoInputs: MediaDeviceInfo[];
|
37
|
+
}>;
|
38
|
+
export declare const isScreenShareDevice: (deviceId?: string) => boolean;
|
39
|
+
/**
|
40
|
+
* 判断是否前后置摄像头
|
41
|
+
* @param deviceId
|
42
|
+
* @returns
|
43
|
+
*/
|
44
|
+
export declare const isMobileVideoDevice: (deviceId?: string) => boolean;
|
45
|
+
/**
|
46
|
+
* Check if browser supports screen sharing
|
47
|
+
* 检查浏览器是否支持屏幕共享
|
48
|
+
*/
|
49
|
+
export declare function isScreenShareSupported(): boolean;
|