@coze/realtime-api 1.2.0-beta.1 → 1.2.1-beta.10
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/dist/cjs/event-names/index.js +9 -1
- package/dist/cjs/index.js +60 -27
- package/dist/esm/event-names/index.js +9 -1
- package/dist/esm/index.js +60 -27
- package/dist/types/client.d.ts +1 -0
- package/dist/types/event-names/client.d.ts +1 -0
- package/dist/types/event-names/event-names.d.ts +11 -1
- package/dist/types/event-names/index.d.ts +3 -1
- package/dist/types/event-names.d.ts +11 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/umd/index.js +60 -27
- package/package.json +5 -5
@@ -49,6 +49,10 @@ var EventNames = /*#__PURE__*/ function(EventNames) {
|
|
49
49
|
* zh: 所有服务端事件
|
50
50
|
*/ EventNames["ALL_SERVER"] = "server.*";
|
51
51
|
/**
|
52
|
+
* en: Room info
|
53
|
+
* zh: 房间信息
|
54
|
+
*/ EventNames["ROOM_INFO"] = "client.room.info";
|
55
|
+
/**
|
52
56
|
* en: Client connected
|
53
57
|
* zh: 客户端连接
|
54
58
|
*/ EventNames["CONNECTED"] = "client.connected";
|
@@ -81,6 +85,10 @@ var EventNames = /*#__PURE__*/ function(EventNames) {
|
|
81
85
|
* zh: 客户端视频关闭
|
82
86
|
*/ EventNames["VIDEO_OFF"] = "client.video.off";
|
83
87
|
/**
|
88
|
+
* en: Client video error
|
89
|
+
* zh: 客户端视频(或屏幕共享)错误
|
90
|
+
*/ EventNames["VIDEO_ERROR"] = "client.video.error";
|
91
|
+
/**
|
84
92
|
* en: Client video event
|
85
93
|
* zh: 客户端视频事件
|
86
94
|
*/ EventNames["PLAYER_EVENT"] = "client.video.event";
|
@@ -147,7 +155,7 @@ var EventNames = /*#__PURE__*/ function(EventNames) {
|
|
147
155
|
/**
|
148
156
|
* en: Session updated
|
149
157
|
* zh: 会话更新
|
150
|
-
*/ EventNames["
|
158
|
+
*/ EventNames["SESSION_UPDATED"] = "server.session.updated";
|
151
159
|
return EventNames;
|
152
160
|
}(EventNames || {});
|
153
161
|
/* ESM default export */ const __WEBPACK_DEFAULT_EXPORT__ = EventNames;
|
package/dist/cjs/index.js
CHANGED
@@ -162,6 +162,10 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
162
162
|
* zh: 所有服务端事件
|
163
163
|
*/ EventNames["ALL_SERVER"] = "server.*";
|
164
164
|
/**
|
165
|
+
* en: Room info
|
166
|
+
* zh: 房间信息
|
167
|
+
*/ EventNames["ROOM_INFO"] = "client.room.info";
|
168
|
+
/**
|
165
169
|
* en: Client connected
|
166
170
|
* zh: 客户端连接
|
167
171
|
*/ EventNames["CONNECTED"] = "client.connected";
|
@@ -194,6 +198,10 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
194
198
|
* zh: 客户端视频关闭
|
195
199
|
*/ EventNames["VIDEO_OFF"] = "client.video.off";
|
196
200
|
/**
|
201
|
+
* en: Client video error
|
202
|
+
* zh: 客户端视频(或屏幕共享)错误
|
203
|
+
*/ EventNames["VIDEO_ERROR"] = "client.video.error";
|
204
|
+
/**
|
197
205
|
* en: Client video event
|
198
206
|
* zh: 客户端视频事件
|
199
207
|
*/ EventNames["PLAYER_EVENT"] = "client.video.event";
|
@@ -260,7 +268,7 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
260
268
|
/**
|
261
269
|
* en: Session updated
|
262
270
|
* zh: 会话更新
|
263
|
-
*/ EventNames["
|
271
|
+
*/ EventNames["SESSION_UPDATED"] = "server.session.updated";
|
264
272
|
return EventNames;
|
265
273
|
}(event_names_EventNames || {});
|
266
274
|
/* ESM default export */ const event_names = event_names_EventNames;
|
@@ -350,6 +358,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
350
358
|
this.engine.on(rtc_default().events.onUserLeave, this.handleUserLeave);
|
351
359
|
this.engine.on(rtc_default().events.onError, this.handleEventError);
|
352
360
|
this.engine.on(rtc_default().events.onNetworkQuality, this.handleNetworkQuality);
|
361
|
+
this.engine.on(rtc_default().events.onTrackEnded, this.handleTrackEnded);
|
353
362
|
if (this._isSupportVideo) this.engine.on(rtc_default().events.onPlayerEvent, this.handlePlayerEvent);
|
354
363
|
if (this._debug) {
|
355
364
|
this.engine.on(rtc_default().events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
@@ -362,6 +371,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
362
371
|
this.engine.off(rtc_default().events.onUserLeave, this.handleUserLeave);
|
363
372
|
this.engine.off(rtc_default().events.onError, this.handleEventError);
|
364
373
|
this.engine.off(rtc_default().events.onNetworkQuality, this.handleNetworkQuality);
|
374
|
+
this.engine.off(rtc_default().events.onTrackEnded, this.handleTrackEnded);
|
365
375
|
if (this._isSupportVideo) this.engine.off(rtc_default().events.onPlayerEvent, this.handlePlayerEvent);
|
366
376
|
if (this._debug) {
|
367
377
|
this.engine.off(rtc_default().events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
@@ -412,6 +422,10 @@ class EngineClient extends RealtimeEventHandler {
|
|
412
422
|
downlinkNetworkQuality
|
413
423
|
});
|
414
424
|
}
|
425
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
426
|
+
handleTrackEnded(event) {
|
427
|
+
if ((null == event ? void 0 : event.kind) === 'video') this.dispatch(event_names.VIDEO_OFF, event);
|
428
|
+
}
|
415
429
|
async joinRoom(options) {
|
416
430
|
const { token, roomId, uid, audioMutedDefault, videoOnDefault, isAutoSubscribeAudio } = options;
|
417
431
|
try {
|
@@ -446,6 +460,10 @@ class EngineClient extends RealtimeEventHandler {
|
|
446
460
|
video: true
|
447
461
|
});
|
448
462
|
if (!isMobileVideoDevice(deviceId) && -1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
463
|
+
this.engine.setLocalVideoPlayer(isScreenShareDevice(deviceId) ? rtc_namespaceObject.StreamIndex.STREAM_INDEX_SCREEN : rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN, {
|
464
|
+
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
465
|
+
userId: this._roomUserId
|
466
|
+
});
|
449
467
|
await this.changeVideoState(false);
|
450
468
|
if (isScreenShareDevice(deviceId)) {
|
451
469
|
if (this._streamIndex === rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN);
|
@@ -461,10 +479,6 @@ class EngineClient extends RealtimeEventHandler {
|
|
461
479
|
if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
|
462
480
|
this._streamIndex = rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN;
|
463
481
|
}
|
464
|
-
this.engine.setLocalVideoPlayer(this._streamIndex, {
|
465
|
-
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
466
|
-
userId: this._roomUserId
|
467
|
-
});
|
468
482
|
}
|
469
483
|
async createLocalStream(userId, videoConfig) {
|
470
484
|
this._roomUserId = userId;
|
@@ -474,7 +488,12 @@ class EngineClient extends RealtimeEventHandler {
|
|
474
488
|
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
475
489
|
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
476
490
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
477
|
-
if (this._isSupportVideo)
|
491
|
+
if (this._isSupportVideo) try {
|
492
|
+
await this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
493
|
+
this.dispatch((null == videoConfig ? void 0 : videoConfig.videoOnDefault) ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
494
|
+
} catch (e) {
|
495
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
496
|
+
}
|
478
497
|
}
|
479
498
|
async disconnect() {
|
480
499
|
try {
|
@@ -497,23 +516,18 @@ class EngineClient extends RealtimeEventHandler {
|
|
497
516
|
}
|
498
517
|
}
|
499
518
|
async changeVideoState(isVideoOn) {
|
500
|
-
|
501
|
-
if (
|
502
|
-
if (this._streamIndex === rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
503
|
-
else {
|
504
|
-
var _this__videoConfig;
|
505
|
-
this.engine.setVideoSourceType(rtc_namespaceObject.StreamIndex.STREAM_INDEX_SCREEN, rtc_namespaceObject.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
506
|
-
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
507
|
-
await this.engine.publishScreen(rtc_namespaceObject.MediaType.VIDEO);
|
508
|
-
}
|
509
|
-
} else if (this._streamIndex === rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
519
|
+
if (isVideoOn) {
|
520
|
+
if (this._streamIndex === rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
510
521
|
else {
|
511
|
-
|
512
|
-
|
522
|
+
var _this__videoConfig;
|
523
|
+
this.engine.setVideoSourceType(rtc_namespaceObject.StreamIndex.STREAM_INDEX_SCREEN, rtc_namespaceObject.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
524
|
+
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
525
|
+
await this.engine.publishScreen(rtc_namespaceObject.MediaType.VIDEO);
|
513
526
|
}
|
514
|
-
}
|
515
|
-
|
516
|
-
|
527
|
+
} else if (this._streamIndex === rtc_namespaceObject.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
528
|
+
else {
|
529
|
+
await this.engine.stopScreenCapture();
|
530
|
+
await this.engine.unpublishScreen(rtc_namespaceObject.MediaType.VIDEO);
|
517
531
|
}
|
518
532
|
}
|
519
533
|
async stop() {
|
@@ -603,6 +617,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
603
617
|
this.handleEventError = this.handleEventError.bind(this);
|
604
618
|
this.handlePlayerEvent = this.handlePlayerEvent.bind(this);
|
605
619
|
this.handleNetworkQuality = this.handleNetworkQuality.bind(this);
|
620
|
+
this.handleTrackEnded = this.handleTrackEnded.bind(this);
|
606
621
|
// Debug only
|
607
622
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
608
623
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
@@ -628,6 +643,7 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
628
643
|
else {
|
629
644
|
const config = {};
|
630
645
|
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
646
|
+
if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode;
|
631
647
|
if (this._config.videoConfig) {
|
632
648
|
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
633
649
|
stream_video_type: 'screen'
|
@@ -650,6 +666,12 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
650
666
|
this.dispatch(event_names.ERROR, error);
|
651
667
|
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
652
668
|
}
|
669
|
+
this.dispatch(event_names.ROOM_INFO, {
|
670
|
+
roomId: roomInfo.room_id,
|
671
|
+
uid: roomInfo.uid,
|
672
|
+
token: roomInfo.token,
|
673
|
+
appId: roomInfo.app_id
|
674
|
+
});
|
653
675
|
this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
|
654
676
|
// Step2 create engine
|
655
677
|
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
|
@@ -731,10 +753,14 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
731
753
|
else this.dispatch(event_names.AUDIO_MUTED, {});
|
732
754
|
}
|
733
755
|
async setVideoEnable(isEnable) {
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
756
|
+
try {
|
757
|
+
var _this__client;
|
758
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
|
759
|
+
this.dispatch(isEnable ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
760
|
+
} catch (e) {
|
761
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
762
|
+
throw e;
|
763
|
+
}
|
738
764
|
}
|
739
765
|
/**
|
740
766
|
* en: Enable audio properties reporting (debug mode only)
|
@@ -796,8 +822,14 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
796
822
|
*
|
797
823
|
* zh: 设置视频输入设备
|
798
824
|
*/ async setVideoInputDevice(deviceId) {
|
799
|
-
|
800
|
-
|
825
|
+
try {
|
826
|
+
var _this__client;
|
827
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
828
|
+
this.dispatch(event_names.VIDEO_ON, {});
|
829
|
+
} catch (e) {
|
830
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
831
|
+
throw e;
|
832
|
+
}
|
801
833
|
this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
|
802
834
|
deviceId
|
803
835
|
});
|
@@ -853,6 +885,7 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
853
885
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
854
886
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
855
887
|
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
888
|
+
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
856
889
|
*/ constructor(config){
|
857
890
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
858
891
|
this._config = config;
|
@@ -12,6 +12,10 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
12
12
|
* zh: 所有服务端事件
|
13
13
|
*/ EventNames["ALL_SERVER"] = "server.*";
|
14
14
|
/**
|
15
|
+
* en: Room info
|
16
|
+
* zh: 房间信息
|
17
|
+
*/ EventNames["ROOM_INFO"] = "client.room.info";
|
18
|
+
/**
|
15
19
|
* en: Client connected
|
16
20
|
* zh: 客户端连接
|
17
21
|
*/ EventNames["CONNECTED"] = "client.connected";
|
@@ -44,6 +48,10 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
44
48
|
* zh: 客户端视频关闭
|
45
49
|
*/ EventNames["VIDEO_OFF"] = "client.video.off";
|
46
50
|
/**
|
51
|
+
* en: Client video error
|
52
|
+
* zh: 客户端视频(或屏幕共享)错误
|
53
|
+
*/ EventNames["VIDEO_ERROR"] = "client.video.error";
|
54
|
+
/**
|
47
55
|
* en: Client video event
|
48
56
|
* zh: 客户端视频事件
|
49
57
|
*/ EventNames["PLAYER_EVENT"] = "client.video.event";
|
@@ -110,7 +118,7 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
110
118
|
/**
|
111
119
|
* en: Session updated
|
112
120
|
* zh: 会话更新
|
113
|
-
*/ EventNames["
|
121
|
+
*/ EventNames["SESSION_UPDATED"] = "server.session.updated";
|
114
122
|
return EventNames;
|
115
123
|
}(event_names_EventNames || {});
|
116
124
|
/* ESM default export */ const event_names = event_names_EventNames;
|
package/dist/esm/index.js
CHANGED
@@ -135,6 +135,10 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
135
135
|
* zh: 所有服务端事件
|
136
136
|
*/ EventNames["ALL_SERVER"] = "server.*";
|
137
137
|
/**
|
138
|
+
* en: Room info
|
139
|
+
* zh: 房间信息
|
140
|
+
*/ EventNames["ROOM_INFO"] = "client.room.info";
|
141
|
+
/**
|
138
142
|
* en: Client connected
|
139
143
|
* zh: 客户端连接
|
140
144
|
*/ EventNames["CONNECTED"] = "client.connected";
|
@@ -167,6 +171,10 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
167
171
|
* zh: 客户端视频关闭
|
168
172
|
*/ EventNames["VIDEO_OFF"] = "client.video.off";
|
169
173
|
/**
|
174
|
+
* en: Client video error
|
175
|
+
* zh: 客户端视频(或屏幕共享)错误
|
176
|
+
*/ EventNames["VIDEO_ERROR"] = "client.video.error";
|
177
|
+
/**
|
170
178
|
* en: Client video event
|
171
179
|
* zh: 客户端视频事件
|
172
180
|
*/ EventNames["PLAYER_EVENT"] = "client.video.event";
|
@@ -233,7 +241,7 @@ var event_names_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
233
241
|
/**
|
234
242
|
* en: Session updated
|
235
243
|
* zh: 会话更新
|
236
|
-
*/ EventNames["
|
244
|
+
*/ EventNames["SESSION_UPDATED"] = "server.session.updated";
|
237
245
|
return EventNames;
|
238
246
|
}(event_names_EventNames || {});
|
239
247
|
/* ESM default export */ const event_names = event_names_EventNames;
|
@@ -321,6 +329,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
321
329
|
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserLeave, this.handleUserLeave);
|
322
330
|
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onError, this.handleEventError);
|
323
331
|
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onNetworkQuality, this.handleNetworkQuality);
|
332
|
+
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onTrackEnded, this.handleTrackEnded);
|
324
333
|
if (this._isSupportVideo) this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onPlayerEvent, this.handlePlayerEvent);
|
325
334
|
if (this._debug) {
|
326
335
|
this.engine.on(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
@@ -333,6 +342,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
333
342
|
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onUserLeave, this.handleUserLeave);
|
334
343
|
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onError, this.handleEventError);
|
335
344
|
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onNetworkQuality, this.handleNetworkQuality);
|
345
|
+
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onTrackEnded, this.handleTrackEnded);
|
336
346
|
if (this._isSupportVideo) this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onPlayerEvent, this.handlePlayerEvent);
|
337
347
|
if (this._debug) {
|
338
348
|
this.engine.off(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__["default"].events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
@@ -383,6 +393,10 @@ class EngineClient extends RealtimeEventHandler {
|
|
383
393
|
downlinkNetworkQuality
|
384
394
|
});
|
385
395
|
}
|
396
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
397
|
+
handleTrackEnded(event) {
|
398
|
+
if ((null == event ? void 0 : event.kind) === 'video') this.dispatch(event_names.VIDEO_OFF, event);
|
399
|
+
}
|
386
400
|
async joinRoom(options) {
|
387
401
|
const { token, roomId, uid, audioMutedDefault, videoOnDefault, isAutoSubscribeAudio } = options;
|
388
402
|
try {
|
@@ -417,6 +431,10 @@ class EngineClient extends RealtimeEventHandler {
|
|
417
431
|
video: true
|
418
432
|
});
|
419
433
|
if (!isMobileVideoDevice(deviceId) && -1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
434
|
+
this.engine.setLocalVideoPlayer(isScreenShareDevice(deviceId) ? __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN : __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN, {
|
435
|
+
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
436
|
+
userId: this._roomUserId
|
437
|
+
});
|
420
438
|
await this.changeVideoState(false);
|
421
439
|
if (isScreenShareDevice(deviceId)) {
|
422
440
|
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN);
|
@@ -432,10 +450,6 @@ class EngineClient extends RealtimeEventHandler {
|
|
432
450
|
if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
|
433
451
|
this._streamIndex = __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN;
|
434
452
|
}
|
435
|
-
this.engine.setLocalVideoPlayer(this._streamIndex, {
|
436
|
-
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
437
|
-
userId: this._roomUserId
|
438
|
-
});
|
439
453
|
}
|
440
454
|
async createLocalStream(userId, videoConfig) {
|
441
455
|
this._roomUserId = userId;
|
@@ -445,7 +459,12 @@ class EngineClient extends RealtimeEventHandler {
|
|
445
459
|
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
446
460
|
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
447
461
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
448
|
-
if (this._isSupportVideo)
|
462
|
+
if (this._isSupportVideo) try {
|
463
|
+
await this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
464
|
+
this.dispatch((null == videoConfig ? void 0 : videoConfig.videoOnDefault) ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
465
|
+
} catch (e) {
|
466
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
467
|
+
}
|
449
468
|
}
|
450
469
|
async disconnect() {
|
451
470
|
try {
|
@@ -468,23 +487,18 @@ class EngineClient extends RealtimeEventHandler {
|
|
468
487
|
}
|
469
488
|
}
|
470
489
|
async changeVideoState(isVideoOn) {
|
471
|
-
|
472
|
-
if (
|
473
|
-
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
474
|
-
else {
|
475
|
-
var _this__videoConfig;
|
476
|
-
this.engine.setVideoSourceType(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN, __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
477
|
-
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
478
|
-
await this.engine.publishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
|
479
|
-
}
|
480
|
-
} else if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
490
|
+
if (isVideoOn) {
|
491
|
+
if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
481
492
|
else {
|
482
|
-
|
483
|
-
|
493
|
+
var _this__videoConfig;
|
494
|
+
this.engine.setVideoSourceType(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_SCREEN, __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
495
|
+
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
496
|
+
await this.engine.publishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
|
484
497
|
}
|
485
|
-
}
|
486
|
-
|
487
|
-
|
498
|
+
} else if (this._streamIndex === __WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
499
|
+
else {
|
500
|
+
await this.engine.stopScreenCapture();
|
501
|
+
await this.engine.unpublishScreen(__WEBPACK_EXTERNAL_MODULE__volcengine_rtc__.MediaType.VIDEO);
|
488
502
|
}
|
489
503
|
}
|
490
504
|
async stop() {
|
@@ -574,6 +588,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
574
588
|
this.handleEventError = this.handleEventError.bind(this);
|
575
589
|
this.handlePlayerEvent = this.handlePlayerEvent.bind(this);
|
576
590
|
this.handleNetworkQuality = this.handleNetworkQuality.bind(this);
|
591
|
+
this.handleTrackEnded = this.handleTrackEnded.bind(this);
|
577
592
|
// Debug only
|
578
593
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
579
594
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
@@ -599,6 +614,7 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
599
614
|
else {
|
600
615
|
const config = {};
|
601
616
|
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
617
|
+
if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode;
|
602
618
|
if (this._config.videoConfig) {
|
603
619
|
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
604
620
|
stream_video_type: 'screen'
|
@@ -621,6 +637,12 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
621
637
|
this.dispatch(event_names.ERROR, error);
|
622
638
|
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
623
639
|
}
|
640
|
+
this.dispatch(event_names.ROOM_INFO, {
|
641
|
+
roomId: roomInfo.room_id,
|
642
|
+
uid: roomInfo.uid,
|
643
|
+
token: roomInfo.token,
|
644
|
+
appId: roomInfo.app_id
|
645
|
+
});
|
624
646
|
this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
|
625
647
|
// Step2 create engine
|
626
648
|
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
|
@@ -702,10 +724,14 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
702
724
|
else this.dispatch(event_names.AUDIO_MUTED, {});
|
703
725
|
}
|
704
726
|
async setVideoEnable(isEnable) {
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
727
|
+
try {
|
728
|
+
var _this__client;
|
729
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
|
730
|
+
this.dispatch(isEnable ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
731
|
+
} catch (e) {
|
732
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
733
|
+
throw e;
|
734
|
+
}
|
709
735
|
}
|
710
736
|
/**
|
711
737
|
* en: Enable audio properties reporting (debug mode only)
|
@@ -767,8 +793,14 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
767
793
|
*
|
768
794
|
* zh: 设置视频输入设备
|
769
795
|
*/ async setVideoInputDevice(deviceId) {
|
770
|
-
|
771
|
-
|
796
|
+
try {
|
797
|
+
var _this__client;
|
798
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
799
|
+
this.dispatch(event_names.VIDEO_ON, {});
|
800
|
+
} catch (e) {
|
801
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
802
|
+
throw e;
|
803
|
+
}
|
772
804
|
this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
|
773
805
|
deviceId
|
774
806
|
});
|
@@ -824,6 +856,7 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
824
856
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
825
857
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
826
858
|
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
859
|
+
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
827
860
|
*/ constructor(config){
|
828
861
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
829
862
|
this._config = config;
|
package/dist/types/client.d.ts
CHANGED
@@ -19,6 +19,7 @@ export declare class EngineClient extends RealtimeEventHandler {
|
|
19
19
|
handleUserLeave(event: onUserLeaveEvent): void;
|
20
20
|
handlePlayerEvent(event: unknown): void;
|
21
21
|
handleNetworkQuality(uplinkNetworkQuality: NetworkQuality, downlinkNetworkQuality: NetworkQuality): void;
|
22
|
+
handleTrackEnded(event: any): void;
|
22
23
|
joinRoom(options: {
|
23
24
|
token: string;
|
24
25
|
roomId: string;
|
@@ -19,6 +19,7 @@ export declare class EngineClient extends RealtimeEventHandler {
|
|
19
19
|
handleUserLeave(event: onUserLeaveEvent): void;
|
20
20
|
handlePlayerEvent(event: unknown): void;
|
21
21
|
handleNetworkQuality(uplinkNetworkQuality: NetworkQuality, downlinkNetworkQuality: NetworkQuality): void;
|
22
|
+
handleTrackEnded(event: any): void;
|
22
23
|
joinRoom(options: {
|
23
24
|
token: string;
|
24
25
|
roomId: string;
|
@@ -14,6 +14,11 @@ declare enum EventNames {
|
|
14
14
|
* zh: 所有服务端事件
|
15
15
|
*/
|
16
16
|
ALL_SERVER = "server.*",
|
17
|
+
/**
|
18
|
+
* en: Room info
|
19
|
+
* zh: 房间信息
|
20
|
+
*/
|
21
|
+
ROOM_INFO = "client.room.info",
|
17
22
|
/**
|
18
23
|
* en: Client connected
|
19
24
|
* zh: 客户端连接
|
@@ -54,6 +59,11 @@ declare enum EventNames {
|
|
54
59
|
* zh: 客户端视频关闭
|
55
60
|
*/
|
56
61
|
VIDEO_OFF = "client.video.off",
|
62
|
+
/**
|
63
|
+
* en: Client video error
|
64
|
+
* zh: 客户端视频(或屏幕共享)错误
|
65
|
+
*/
|
66
|
+
VIDEO_ERROR = "client.video.error",
|
57
67
|
/**
|
58
68
|
* en: Client video event
|
59
69
|
* zh: 客户端视频事件
|
@@ -138,6 +148,6 @@ declare enum EventNames {
|
|
138
148
|
* en: Session updated
|
139
149
|
* zh: 会话更新
|
140
150
|
*/
|
141
|
-
|
151
|
+
SESSION_UPDATED = "server.session.updated"
|
142
152
|
}
|
143
153
|
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 } from '@coze/api';
|
2
|
+
import { type CreateRoomData, type GetToken, type RoomMode } from '@coze/api';
|
3
3
|
import * as RealtimeUtils from './utils';
|
4
4
|
import EventNames from './event-names';
|
5
5
|
import { RealtimeEventHandler } from './event-handler';
|
@@ -31,6 +31,7 @@ export interface RealtimeClientConfig {
|
|
31
31
|
videoConfig?: VideoConfig /** optional, Video configuration */;
|
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
|
+
roomMode?: RoomMode /** optional, Room mode */;
|
34
35
|
}
|
35
36
|
declare class RealtimeClient extends RealtimeEventHandler {
|
36
37
|
_config: RealtimeClientConfig;
|
@@ -82,6 +83,7 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
82
83
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
83
84
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
84
85
|
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
86
|
+
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
85
87
|
*/
|
86
88
|
constructor(config: RealtimeClientConfig);
|
87
89
|
/**
|
@@ -14,6 +14,11 @@ declare enum EventNames {
|
|
14
14
|
* zh: 所有服务端事件
|
15
15
|
*/
|
16
16
|
ALL_SERVER = "server.*",
|
17
|
+
/**
|
18
|
+
* en: Room info
|
19
|
+
* zh: 房间信息
|
20
|
+
*/
|
21
|
+
ROOM_INFO = "client.room.info",
|
17
22
|
/**
|
18
23
|
* en: Client connected
|
19
24
|
* zh: 客户端连接
|
@@ -54,6 +59,11 @@ declare enum EventNames {
|
|
54
59
|
* zh: 客户端视频关闭
|
55
60
|
*/
|
56
61
|
VIDEO_OFF = "client.video.off",
|
62
|
+
/**
|
63
|
+
* en: Client video error
|
64
|
+
* zh: 客户端视频(或屏幕共享)错误
|
65
|
+
*/
|
66
|
+
VIDEO_ERROR = "client.video.error",
|
57
67
|
/**
|
58
68
|
* en: Client video event
|
59
69
|
* zh: 客户端视频事件
|
@@ -138,6 +148,6 @@ declare enum EventNames {
|
|
138
148
|
* en: Session updated
|
139
149
|
* zh: 会话更新
|
140
150
|
*/
|
141
|
-
|
151
|
+
SESSION_UPDATED = "server.session.updated"
|
142
152
|
}
|
143
153
|
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 } from '@coze/api';
|
2
|
+
import { type CreateRoomData, type GetToken, type RoomMode } from '@coze/api';
|
3
3
|
import * as RealtimeUtils from './utils';
|
4
4
|
import EventNames from './event-names';
|
5
5
|
import { RealtimeEventHandler } from './event-handler';
|
@@ -31,6 +31,7 @@ export interface RealtimeClientConfig {
|
|
31
31
|
videoConfig?: VideoConfig /** optional, Video configuration */;
|
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
|
+
roomMode?: RoomMode /** optional, Room mode */;
|
34
35
|
}
|
35
36
|
declare class RealtimeClient extends RealtimeEventHandler {
|
36
37
|
_config: RealtimeClientConfig;
|
@@ -82,6 +83,7 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
82
83
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
83
84
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
84
85
|
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
86
|
+
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
85
87
|
*/
|
86
88
|
constructor(config: RealtimeClientConfig);
|
87
89
|
/**
|
package/dist/umd/index.js
CHANGED
@@ -199,6 +199,10 @@
|
|
199
199
|
* zh: 所有服务端事件
|
200
200
|
*/ EventNames["ALL_SERVER"] = "server.*";
|
201
201
|
/**
|
202
|
+
* en: Room info
|
203
|
+
* zh: 房间信息
|
204
|
+
*/ EventNames["ROOM_INFO"] = "client.room.info";
|
205
|
+
/**
|
202
206
|
* en: Client connected
|
203
207
|
* zh: 客户端连接
|
204
208
|
*/ EventNames["CONNECTED"] = "client.connected";
|
@@ -231,6 +235,10 @@
|
|
231
235
|
* zh: 客户端视频关闭
|
232
236
|
*/ EventNames["VIDEO_OFF"] = "client.video.off";
|
233
237
|
/**
|
238
|
+
* en: Client video error
|
239
|
+
* zh: 客户端视频(或屏幕共享)错误
|
240
|
+
*/ EventNames["VIDEO_ERROR"] = "client.video.error";
|
241
|
+
/**
|
234
242
|
* en: Client video event
|
235
243
|
* zh: 客户端视频事件
|
236
244
|
*/ EventNames["PLAYER_EVENT"] = "client.video.event";
|
@@ -297,7 +305,7 @@
|
|
297
305
|
/**
|
298
306
|
* en: Session updated
|
299
307
|
* zh: 会话更新
|
300
|
-
*/ EventNames["
|
308
|
+
*/ EventNames["SESSION_UPDATED"] = "server.session.updated";
|
301
309
|
return EventNames;
|
302
310
|
}(event_names_EventNames || {});
|
303
311
|
/* ESM default export */ const event_names = event_names_EventNames;
|
@@ -388,6 +396,7 @@
|
|
388
396
|
this.engine.on(rtc_default().events.onUserLeave, this.handleUserLeave);
|
389
397
|
this.engine.on(rtc_default().events.onError, this.handleEventError);
|
390
398
|
this.engine.on(rtc_default().events.onNetworkQuality, this.handleNetworkQuality);
|
399
|
+
this.engine.on(rtc_default().events.onTrackEnded, this.handleTrackEnded);
|
391
400
|
if (this._isSupportVideo) this.engine.on(rtc_default().events.onPlayerEvent, this.handlePlayerEvent);
|
392
401
|
if (this._debug) {
|
393
402
|
this.engine.on(rtc_default().events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
@@ -400,6 +409,7 @@
|
|
400
409
|
this.engine.off(rtc_default().events.onUserLeave, this.handleUserLeave);
|
401
410
|
this.engine.off(rtc_default().events.onError, this.handleEventError);
|
402
411
|
this.engine.off(rtc_default().events.onNetworkQuality, this.handleNetworkQuality);
|
412
|
+
this.engine.off(rtc_default().events.onTrackEnded, this.handleTrackEnded);
|
403
413
|
if (this._isSupportVideo) this.engine.off(rtc_default().events.onPlayerEvent, this.handlePlayerEvent);
|
404
414
|
if (this._debug) {
|
405
415
|
this.engine.off(rtc_default().events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
@@ -450,6 +460,10 @@
|
|
450
460
|
downlinkNetworkQuality
|
451
461
|
});
|
452
462
|
}
|
463
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
464
|
+
handleTrackEnded(event) {
|
465
|
+
if ((null == event ? void 0 : event.kind) === 'video') this.dispatch(event_names.VIDEO_OFF, event);
|
466
|
+
}
|
453
467
|
async joinRoom(options) {
|
454
468
|
const { token, roomId, uid, audioMutedDefault, videoOnDefault, isAutoSubscribeAudio } = options;
|
455
469
|
try {
|
@@ -484,6 +498,10 @@
|
|
484
498
|
video: true
|
485
499
|
});
|
486
500
|
if (!isMobileVideoDevice(deviceId) && -1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
501
|
+
this.engine.setLocalVideoPlayer(isScreenShareDevice(deviceId) ? rtc_.StreamIndex.STREAM_INDEX_SCREEN : rtc_.StreamIndex.STREAM_INDEX_MAIN, {
|
502
|
+
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
503
|
+
userId: this._roomUserId
|
504
|
+
});
|
487
505
|
await this.changeVideoState(false);
|
488
506
|
if (isScreenShareDevice(deviceId)) {
|
489
507
|
if (this._streamIndex === rtc_.StreamIndex.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(rtc_.StreamIndex.STREAM_INDEX_MAIN);
|
@@ -499,10 +517,6 @@
|
|
499
517
|
if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
|
500
518
|
this._streamIndex = rtc_.StreamIndex.STREAM_INDEX_MAIN;
|
501
519
|
}
|
502
|
-
this.engine.setLocalVideoPlayer(this._streamIndex, {
|
503
|
-
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
504
|
-
userId: this._roomUserId
|
505
|
-
});
|
506
520
|
}
|
507
521
|
async createLocalStream(userId, videoConfig) {
|
508
522
|
this._roomUserId = userId;
|
@@ -512,7 +526,12 @@
|
|
512
526
|
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
513
527
|
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
514
528
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
515
|
-
if (this._isSupportVideo)
|
529
|
+
if (this._isSupportVideo) try {
|
530
|
+
await this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
531
|
+
this.dispatch((null == videoConfig ? void 0 : videoConfig.videoOnDefault) ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
532
|
+
} catch (e) {
|
533
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
534
|
+
}
|
516
535
|
}
|
517
536
|
async disconnect() {
|
518
537
|
try {
|
@@ -535,23 +554,18 @@
|
|
535
554
|
}
|
536
555
|
}
|
537
556
|
async changeVideoState(isVideoOn) {
|
538
|
-
|
539
|
-
if (
|
540
|
-
if (this._streamIndex === rtc_.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
541
|
-
else {
|
542
|
-
var _this__videoConfig;
|
543
|
-
this.engine.setVideoSourceType(rtc_.StreamIndex.STREAM_INDEX_SCREEN, rtc_.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
544
|
-
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
545
|
-
await this.engine.publishScreen(rtc_.MediaType.VIDEO);
|
546
|
-
}
|
547
|
-
} else if (this._streamIndex === rtc_.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
557
|
+
if (isVideoOn) {
|
558
|
+
if (this._streamIndex === rtc_.StreamIndex.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
548
559
|
else {
|
549
|
-
|
550
|
-
|
560
|
+
var _this__videoConfig;
|
561
|
+
this.engine.setVideoSourceType(rtc_.StreamIndex.STREAM_INDEX_SCREEN, rtc_.VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
562
|
+
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
563
|
+
await this.engine.publishScreen(rtc_.MediaType.VIDEO);
|
551
564
|
}
|
552
|
-
}
|
553
|
-
|
554
|
-
|
565
|
+
} else if (this._streamIndex === rtc_.StreamIndex.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
566
|
+
else {
|
567
|
+
await this.engine.stopScreenCapture();
|
568
|
+
await this.engine.unpublishScreen(rtc_.MediaType.VIDEO);
|
555
569
|
}
|
556
570
|
}
|
557
571
|
async stop() {
|
@@ -641,6 +655,7 @@
|
|
641
655
|
this.handleEventError = this.handleEventError.bind(this);
|
642
656
|
this.handlePlayerEvent = this.handlePlayerEvent.bind(this);
|
643
657
|
this.handleNetworkQuality = this.handleNetworkQuality.bind(this);
|
658
|
+
this.handleTrackEnded = this.handleTrackEnded.bind(this);
|
644
659
|
// Debug only
|
645
660
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
646
661
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
@@ -666,6 +681,7 @@
|
|
666
681
|
else {
|
667
682
|
const config = {};
|
668
683
|
if (this._config.prologueContent) config.prologue_content = this._config.prologueContent;
|
684
|
+
if (void 0 !== this._config.roomMode && null !== this._config.roomMode) config.room_mode = this._config.roomMode;
|
669
685
|
if (this._config.videoConfig) {
|
670
686
|
if (isScreenShareDevice(this._config.videoConfig.videoInputDeviceId)) config.video_config = {
|
671
687
|
stream_video_type: 'screen'
|
@@ -688,6 +704,12 @@
|
|
688
704
|
this.dispatch(event_names.ERROR, error);
|
689
705
|
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
690
706
|
}
|
707
|
+
this.dispatch(event_names.ROOM_INFO, {
|
708
|
+
roomId: roomInfo.room_id,
|
709
|
+
uid: roomInfo.uid,
|
710
|
+
token: roomInfo.token,
|
711
|
+
appId: roomInfo.app_id
|
712
|
+
});
|
691
713
|
this._isTestEnv = TEST_APP_ID === roomInfo.app_id;
|
692
714
|
// Step2 create engine
|
693
715
|
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
|
@@ -769,10 +791,14 @@
|
|
769
791
|
else this.dispatch(event_names.AUDIO_MUTED, {});
|
770
792
|
}
|
771
793
|
async setVideoEnable(isEnable) {
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
794
|
+
try {
|
795
|
+
var _this__client;
|
796
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
|
797
|
+
this.dispatch(isEnable ? event_names.VIDEO_ON : event_names.VIDEO_OFF, {});
|
798
|
+
} catch (e) {
|
799
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
800
|
+
throw e;
|
801
|
+
}
|
776
802
|
}
|
777
803
|
/**
|
778
804
|
* en: Enable audio properties reporting (debug mode only)
|
@@ -834,8 +860,14 @@
|
|
834
860
|
*
|
835
861
|
* zh: 设置视频输入设备
|
836
862
|
*/ async setVideoInputDevice(deviceId) {
|
837
|
-
|
838
|
-
|
863
|
+
try {
|
864
|
+
var _this__client;
|
865
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
866
|
+
this.dispatch(event_names.VIDEO_ON, {});
|
867
|
+
} catch (e) {
|
868
|
+
this.dispatch(event_names.VIDEO_ERROR, e);
|
869
|
+
throw e;
|
870
|
+
}
|
839
871
|
this.dispatch(event_names.VIDEO_INPUT_DEVICE_CHANGED, {
|
840
872
|
deviceId
|
841
873
|
});
|
@@ -891,6 +923,7 @@
|
|
891
923
|
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
892
924
|
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
893
925
|
* @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
|
926
|
+
* @param config.roomMode - Optional, Room mode. | 可选,房间模式。
|
894
927
|
*/ constructor(config){
|
895
928
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
896
929
|
this._config = config;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@coze/realtime-api",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.1-beta.10",
|
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",
|
@@ -54,8 +54,8 @@
|
|
54
54
|
"test:cov": "vitest --coverage --run"
|
55
55
|
},
|
56
56
|
"dependencies": {
|
57
|
-
"@coze/api": "1.2.1-beta.
|
58
|
-
"@volcengine/rtc": "
|
57
|
+
"@coze/api": "1.2.1-beta.20",
|
58
|
+
"@volcengine/rtc": "~4.62.11"
|
59
59
|
},
|
60
60
|
"devDependencies": {
|
61
61
|
"@coze-infra/eslint-config": "workspace:*",
|
@@ -66,10 +66,10 @@
|
|
66
66
|
"@types/node": "^20",
|
67
67
|
"@types/uuid": "^9.0.1",
|
68
68
|
"@types/whatwg-fetch": "^0.0.33",
|
69
|
-
"@vitest/coverage-v8": "~2.1.
|
69
|
+
"@vitest/coverage-v8": "~2.1.9",
|
70
70
|
"axios": "^1.7.7",
|
71
71
|
"typescript": "^5.5.3",
|
72
|
-
"vitest": "~2.1.
|
72
|
+
"vitest": "~2.1.9"
|
73
73
|
},
|
74
74
|
"cozePublishConfig": {
|
75
75
|
"exports": {
|