@coze/realtime-api 1.3.0 → 1.3.2

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,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;
package/dist/umd/index.js CHANGED
@@ -350,6 +350,10 @@
350
350
  * en: Mode updated
351
351
  * zh: 更新房间模式成功
352
352
  */ EventNames["MODE_UPDATED"] = "server.mode.updated";
353
+ /**
354
+ * en: Live created
355
+ * zh: 直播创建
356
+ */ EventNames["LIVE_CREATED"] = "server.live.created";
353
357
  return EventNames;
354
358
  }(event_names_EventNames || {});
355
359
  /* ESM default export */ const event_names = event_names_EventNames;
@@ -692,6 +696,7 @@
692
696
  if (isTestEnv) rtc_default().setParameter('ICE_CONFIG_REQUEST_URLS', [
693
697
  'rtc-test.bytedance.com'
694
698
  ]);
699
+ else localStorage.removeItem('RTC_ACCESS_URLS-VolcEngine');
695
700
  this.engine = rtc_default().createEngine(appId);
696
701
  this.handleMessage = this.handleMessage.bind(this);
697
702
  this.handleUserJoin = this.handleUserJoin.bind(this);
@@ -725,7 +730,7 @@
725
730
  else {
726
731
  const config = {};
727
732
  if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
728
- if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode;
733
+ if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode || api_.RoomMode.Default;
729
734
  if (this._config.videoConfig) {
730
735
  if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
731
736
  stream_video_type: 'screen'
@@ -734,7 +739,9 @@
734
739
  stream_video_type: 'main'
735
740
  };
736
741
  }
737
- roomInfo = await this._api.audio.rooms.create({
742
+ if (this._config.translateConfig) config.translate_config = this._config.translateConfig;
743
+ if (this._config.turnDetection) config.turn_detection = this._config.turnDetection;
744
+ const params = {
738
745
  bot_id: botId,
739
746
  conversation_id: conversationId || void 0,
740
747
  voice_id: voiceId && voiceId.length > 0 ? voiceId : void 0,
@@ -742,7 +749,8 @@
742
749
  uid: this._config.userId || void 0,
743
750
  workflow_id: this._config.workflowId || void 0,
744
751
  config
745
- });
752
+ };
753
+ roomInfo = await this._api.audio.rooms.create(params);
746
754
  }
747
755
  } catch (error) {
748
756
  this.dispatch(event_names.ERROR, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze/realtime-api",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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,6 +31,11 @@
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",
@@ -54,7 +59,7 @@
54
59
  "test:cov": "vitest --coverage --run"
55
60
  },
56
61
  "dependencies": {
57
- "@coze/api": "1.3.0",
62
+ "@coze/api": "1.3.7",
58
63
  "@volcengine/rtc": "~4.62.11"
59
64
  },
60
65
  "devDependencies": {
@@ -86,6 +91,11 @@
86
91
  "require": "./dist/cjs/event-names/index.js",
87
92
  "import": "./dist/esm/event-names/index.js",
88
93
  "types": "./dist/types/event-names/event-names.d.ts"
94
+ },
95
+ "./live": {
96
+ "require": "./dist/cjs/live/index.js",
97
+ "import": "./dist/esm/live/index.js",
98
+ "types": "./dist/types/live/live/index.d.ts"
89
99
  }
90
100
  },
91
101
  "main": "dist/cjs/index.js",