Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(realtime-api): feat: add getRtcEngine method to expose RTC engine #83

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/realtime-api",
"comment": "feat: add getRtcEngine method to expose RTC engine instance",
"type": "minor"
}
],
"packageName": "@coze/realtime-api",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/realtime-api",
"comment": "add test code",
"type": "patch"
}
],
"packageName": "@coze/realtime-api",
"email": "[email protected]"
}
4 changes: 3 additions & 1 deletion packages/realtime-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ const operations = {
disconnect: () => client.disconnect(),
interrupt: () => client.interrupt(),
toggleMicrophone: (enabled: boolean) => client.setAudioEnable(enabled),
checkConnection: () => client.isConnected
checkConnection: () => client.isConnected,
// get rtc engine instance, for detail visit https://www.volcengine.com/docs/6348/104478#rtcengine
getRtcEngine: () => client.getRtcEngine(),
};

// Event Handling
Expand Down
4 changes: 3 additions & 1 deletion packages/realtime-api/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ const operations = {
disconnect: () => client.disconnect(),
interrupt: () => client.interrupt(),
toggleMicrophone: (enabled: boolean) => client.setAudioEnable(enabled),
checkConnection: () => client.isConnected
checkConnection: () => client.isConnected,
// 获取 RTC 引擎实例,详情请访问 https://www.volcengine.com/docs/6348/104478#rtcengine
getRtcEngine: () => client.getRtcEngine(),
};

// 事件处理
Expand Down
4 changes: 2 additions & 2 deletions packages/realtime-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coze/realtime-api",
"version": "1.0.4",
"version": "1.0.4-beta.2",
"description": "A powerful real-time communication SDK for voice interactions with Coze AI bots | 扣子官方实时通信 SDK,用于与 Coze AI bots 进行语音交互",
"keywords": [
"coze",
Expand Down Expand Up @@ -74,4 +74,4 @@
"module": "dist/esm/index.js",
"typings": "dist/types/index.d.ts"
}
}
}
4 changes: 4 additions & 0 deletions packages/realtime-api/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,8 @@ export class EngineClient extends RealtimeEventHandler {
throw e;
}
}

getRtcEngine() {
return this.engine;
}
}
15 changes: 14 additions & 1 deletion packages/realtime-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { type ScreenConfig, type AudioPropertiesConfig } from '@volcengine/rtc';
import {
type ScreenConfig,
type AudioPropertiesConfig,
type IRTCEngine,
} from '@volcengine/rtc';
import { CozeAPI, type CreateRoomData, type GetToken } from '@coze/api';

import * as RealtimeUtils from './utils';
Expand Down Expand Up @@ -309,6 +313,15 @@ class RealtimeClient extends RealtimeEventHandler {
await this._client?.setVideoInputDevice(deviceId);
this.dispatch(EventNames.VIDEO_INPUT_DEVICE_CHANGED, { deviceId });
}

/**
* en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
*
* zh: 获取 RTC 引擎实例,详情请访问 https://www.volcengine.com/docs/6348/104481
*/
getRtcEngine(): IRTCEngine | undefined {
return this._client?.getRtcEngine();
}
}

export {
Expand Down
7 changes: 7 additions & 0 deletions packages/realtime-api/test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,11 @@ describe('EngineClient', () => {
);
});
});

describe('getRtcEngine', () => {
it('should get rtc engine', () => {
const engine = client.getRtcEngine();
expect(engine).toBeDefined();
});
});
});
9 changes: 9 additions & 0 deletions packages/realtime-api/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('RealtimeClient', () => {
initAIAnsExtension: vi.fn(),
changeAIAnsExtension: vi.fn(),
sendMessage: vi.fn(),
getRtcEngine: vi.fn(),
dispatch: vi.fn(),
} as any;
(EngineClient as vi.Mock).mockImplementation(() => mockEngineClient);
Expand Down Expand Up @@ -332,4 +333,12 @@ describe('RealtimeClient', () => {
});
});
});

describe('getRtcEngine', () => {
it('should return rtc engine instance', async () => {
await client.connect();
client.getRtcEngine();
expect(mockEngineClient.getRtcEngine).toHaveBeenCalled();
});
});
});