diff --git a/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-07-08-19.json b/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-07-08-19.json new file mode 100644 index 00000000..6d42410d --- /dev/null +++ b/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-07-08-19.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@coze/realtime-api", + "comment": "screen sharing bug", + "type": "patch" + } + ], + "packageName": "@coze/realtime-api", + "email": "shenxiaojie.316@bytedance.com" +} diff --git a/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-07-08-27.json b/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-07-08-27.json new file mode 100644 index 00000000..6d42410d --- /dev/null +++ b/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-07-08-27.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@coze/realtime-api", + "comment": "screen sharing bug", + "type": "patch" + } + ], + "packageName": "@coze/realtime-api", + "email": "shenxiaojie.316@bytedance.com" +} diff --git a/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-08-06-20.json b/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-08-06-20.json new file mode 100644 index 00000000..c7c2150a --- /dev/null +++ b/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-08-06-20.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@coze/realtime-api", + "comment": "Add check for video support before throwing device error", + "type": "patch" + } + ], + "packageName": "@coze/realtime-api", + "email": "shenxiaojie.316@bytedance.com" +} diff --git a/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-08-06-32.json b/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-08-06-32.json new file mode 100644 index 00000000..c7c2150a --- /dev/null +++ b/common/changes/@coze/realtime-api/feat-realtime-api_2025-01-08-06-32.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@coze/realtime-api", + "comment": "Add check for video support before throwing device error", + "type": "patch" + } + ], + "packageName": "@coze/realtime-api", + "email": "shenxiaojie.316@bytedance.com" +} diff --git a/examples/realtime-console/src/pages/main/header.tsx b/examples/realtime-console/src/pages/main/header.tsx index cf23d497..9679b83a 100644 --- a/examples/realtime-console/src/pages/main/header.tsx +++ b/examples/realtime-console/src/pages/main/header.tsx @@ -283,9 +283,14 @@ const Header: React.FC = ({ clientRef.current?.setAudioOutputDevice(value); }; - const handleVideoInputDeviceChange = (value: string) => { - setVideoInputDeviceId(value); - clientRef.current?.setVideoInputDevice(value); + const handleVideoInputDeviceChange = async (value: string) => { + try { + setVideoInputDeviceId(value); + await clientRef.current?.setVideoInputDevice(value); + } catch (error) { + message.error(`Failed to set video input device: ${error}`); + console.error(error); + } }; if (microphoneStatus === 'error') { diff --git a/packages/realtime-api/package.json b/packages/realtime-api/package.json index 71c5a6e4..c12c2930 100644 --- a/packages/realtime-api/package.json +++ b/packages/realtime-api/package.json @@ -1,6 +1,6 @@ { "name": "@coze/realtime-api", - "version": "1.0.3-beta.6", + "version": "1.0.3-beta.7", "description": "A powerful real-time communication SDK for voice interactions with Coze AI bots | 扣子官方实时通信 SDK,用于与 Coze AI bots 进行语音交互", "keywords": [ "coze", diff --git a/packages/realtime-api/src/client.ts b/packages/realtime-api/src/client.ts index cb232b66..61c8e999 100644 --- a/packages/realtime-api/src/client.ts +++ b/packages/realtime-api/src/client.ts @@ -7,6 +7,7 @@ import VERTC, { type onUserLeaveEvent, StreamIndex, type UserMessageEvent, + VideoSourceType, } from '@volcengine/rtc'; import { getAudioDevices, isScreenShareDevice } from './utils'; @@ -225,7 +226,12 @@ export class EngineClient extends RealtimeEventHandler { this.engine.setLocalVideoPlayer(StreamIndex.STREAM_INDEX_MAIN); } if (isAutoCapture) { + this.engine.setVideoSourceType( + StreamIndex.STREAM_INDEX_SCREEN, + VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL, + ); await this.engine.startScreenCapture(this._videoConfig?.screenConfig); + await this.engine.publishScreen(MediaType.VIDEO); } this._streamIndex = StreamIndex.STREAM_INDEX_SCREEN; } else { @@ -255,7 +261,7 @@ export class EngineClient extends RealtimeEventHandler { ); } - if (!devices.videoInputs.length) { + if (this._isSupportVideo && !devices.videoInputs.length) { throw new RealtimeAPIError( RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices', @@ -306,13 +312,19 @@ export class EngineClient extends RealtimeEventHandler { if (this._streamIndex === StreamIndex.STREAM_INDEX_MAIN) { await this.engine.startVideoCapture(); } else { + this.engine.setVideoSourceType( + StreamIndex.STREAM_INDEX_SCREEN, + VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL, + ); await this.engine.startScreenCapture(this._videoConfig?.screenConfig); + await this.engine.publishScreen(MediaType.VIDEO); } } else { if (this._streamIndex === StreamIndex.STREAM_INDEX_MAIN) { await this.engine.stopVideoCapture(); } else { await this.engine.stopScreenCapture(); + await this.engine.unpublishScreen(MediaType.VIDEO); } } } catch (e) { diff --git a/packages/realtime-api/test/client.spec.ts b/packages/realtime-api/test/client.spec.ts index 7e8936c1..6d97f7ac 100644 --- a/packages/realtime-api/test/client.spec.ts +++ b/packages/realtime-api/test/client.spec.ts @@ -28,6 +28,9 @@ const mockEngine = { registerExtension: vi.fn(), startAudioPlaybackDeviceTest: vi.fn(), stopAudioPlaybackDeviceTest: vi.fn(), + unpublishScreen: vi.fn(), + publishScreen: vi.fn(), + setVideoSourceType: vi.fn(), }; // Mock VERTC @@ -52,6 +55,9 @@ vi.mock('@volcengine/rtc', () => ({ MediaType: { AUDIO: 'audio', }, + VideoSourceType: { + VIDEO_SOURCE_TYPE_INTERNAL: 'internal', + }, })); // Mock RTCAIAnsExtension @@ -311,6 +317,7 @@ describe('EngineClient', () => { }); it('should throw error when no video devices available', async () => { + (client as any)._isSupportVideo = true; (utils.getAudioDevices as Mock).mockResolvedValueOnce({ audioInputs: [{ deviceId: 'audio-in-1' }], audioOutputs: [],