指南
如何在 Capacitor 中使用 Streamcall
使用 @capgo/capacitor-stream-call
使用 https://getstream.io/ 在 Capacitor 中使用 SDK 实现通话功能。
安装
bun add @capgo/capacitor-stream-call
bunx cap sync
bunx cap sync 将插件的原生 code 复制到你的原生项目中。每次升级插件后都要重新运行。
导入
import { StreamCall } from '@capgo/capacitor-stream-call';
API 概览
| 方法 | 描述 |
|---|---|
login |
登录 Stream Video 服务。 |
logout |
退出 Stream Video 服务。 |
call |
发起对另一用户的通话。 |
endCall |
结束当前通话。 |
joinCall |
加入现有通话。 |
setMicrophoneEnabled |
启用或禁用麦克风。 |
setCameraEnabled |
启用或禁用摄像头。 |
enableBluetooth |
启用蓝牙音频。 |
acceptCall |
接听呼入电话。 |
rejectCall |
拒接呼入电话。 |
isCameraEnabled |
检查摄像头是否已启用。 |
getCallStatus |
获取当前通话状态。 |
getRingingCall |
获取当前正在响铃的通话。 |
toggleViews |
循环切换可用的视频布局。 |
setSpeaker |
开启扬声器。 |
switchCamera |
切换摄像头。 |
getCallInfo |
获取当前通话的详细信息,包括呼叫者详情。 |
setDynamicStreamVideoApikey |
设置动态 Stream Video API key,以覆盖静态 key。 |
getDynamicStreamVideoApikey |
获取当前设置的动态 Stream Video API key。 |
getCurrentUser |
获取当前用户信息。 |
示例
login()
登录 Stream Video 服务。
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.login({
token: 'your-token',
userId: 'user-123',
name: 'John Doe',
apiKey: 'your-api-key'
});
logout()
退出 Stream Video 服务。
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.logout();
call()
发起对另一用户的通话。
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.call({
userId: 'user-456',
type: 'video',
ring: true
});
endCall()
结束当前通话。
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.endCall();
joinCall()
加入现有通话。
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.joinCall({ callId: 'call001', callType: 'default' });
setMicrophoneEnabled()
启用或禁用麦克风。
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.setMicrophoneEnabled({ enabled: false });
上表列出了 20 个核心方法。监听器、版本辅助函数以及每个方法的完整契约,请参阅 GitHub 仓库.
监听事件
addListener 会返回一个句柄。调用 handle.remove() 在屏幕卸载时,或者调用 StreamCall.removeAllListeners() 以清除所有监听器。
完整参考文档
继续使用 @capgo/capacitor-stream-call
如果你正在使用 使用 @capgo/capacitor-stream-call 要规划原生插件工作,请将其与 @capgo/capacitor-stream-call 有关 @capgo/capacitor-stream-call 的实现细节, 快速入门 有关“入门指南”中的实现细节, Capgo 插件目录 查看 Capgo 插件目录中的产品工作流, Capgo 提供的 Capacitor 插件 有关 Capgo 开发的 Capacitor 插件的实现细节,以及 添加或更新插件 有关添加或更新插件的实现细节。