跳转到正文

快速入门

GitHub

你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:

终端窗口
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

然后使用以下 prompt:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-stream-call` plugin in my project.

如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:

终端窗口
bun add @capgo/capacitor-stream-call
bunx cap sync
import { StreamCall } from '@capgo/capacitor-stream-call';
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.login({
token: 'your-token',
userId: 'user-123',
name: 'John Doe',
apiKey: 'your-api-key'
});
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.logout();
import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.call({
userId: 'user-456',
type: 'video',
ring: true
});
  • 监听器: 在页面卸载时移除句柄。
  • 原生同步:运行 bunx cap sync 在插件升级后。
  • 唯一可信来源:信任 src/definitions.ts 在 GitHub 仓库中。

登录 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'
});

退出 Stream Video 服务

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.logout();

发起对另一用户的通话

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.call({
userId: 'user-456',
type: 'video',
ring: true
});

结束当前通话

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.endCall();

加入现有通话

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.joinCall({ callId: 'call001', callType: 'default' });

启用或禁用麦克风

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.setMicrophoneEnabled({ enabled: false });

启用或禁用摄像头

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.setCameraEnabled({ enabled: false });

启用蓝牙音频

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.enableBluetooth();

接听来电

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.acceptCall();

拒绝来电

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.rejectCall();

检查摄像头是否已启用

import { StreamCall } from '@capgo/capacitor-stream-call';
const isCameraEnabled = await StreamCall.isCameraEnabled();
console.log(isCameraEnabled);

获取当前通话状态

import { StreamCall } from '@capgo/capacitor-stream-call';
const callStatus = await StreamCall.getCallStatus();
console.log(callStatus);

获取当前的振铃通话

import { StreamCall } from '@capgo/capacitor-stream-call';
const ringingCall = await StreamCall.getRingingCall();
console.log(ringingCall);

循环切换可用的视频布局

import { StreamCall } from '@capgo/capacitor-stream-call';
const { newLayout } = await StreamCall.toggleViews();
console.log(`Layout switched to ${newLayout}`);

开启扬声器

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.setSpeaker({ name: 'speaker' });

切换摄像头

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.switchCamera({ camera: 'back' });

获取当前通话的详细信息,包括呼叫方详情

import { StreamCall } from '@capgo/capacitor-stream-call';
const result = await StreamCall.getCallInfo({ callId: 'call-id-123' });
console.log(result);

setDynamicStreamVideoApikey

“setDynamicStreamVideoApikey” 章节

设置动态 Stream Video API key,用于覆盖静态 key

import { StreamCall } from '@capgo/capacitor-stream-call';
await StreamCall.setDynamicStreamVideoApikey({ apiKey: 'new-api-key' });

getDynamicStreamVideoApikey

“getDynamicStreamVideoApikey” 章节

获取当前设置的 Stream Video API 动态 key

import { StreamCall } from '@capgo/capacitor-stream-call';
const result = await StreamCall.getDynamicStreamVideoApikey();
if (result.hasDynamicKey) {
console.log('Dynamic API key:', result.apiKey);
} else {
console.log('Using static API key from resources');
}

获取当前用户信息

import { StreamCall } from '@capgo/capacitor-stream-call';
const currentUser = await StreamCall.getCurrentUser();
console.log(currentUser);
export interface LoginOptions {
/** Stream Video API token */
token: string;
/** User ID for the current user */
userId: string;
/** Display name for the current user */
name: string;
/** Optional avatar URL for the current user */
imageURL?: string;
/** Stream Video API key */
apiKey: string;
/** ID of the HTML element where the video will be rendered */
magicDivId?: string;
pushNotificationsConfig?: PushNotificationsConfig;
}
export interface SuccessResponse {
/** Whether the operation was successful */
success: boolean;
callId?: string;
}
export interface CallOptions {
/** User ID of the person to call */
userIds: string[];
/** Type of call, defaults to 'default' */
type?: CallType;
/** Whether to ring the other user, defaults to true */
ring?: boolean;
/** Team name to call */
team?: string;
/** Whether to start the call with video enabled, defaults to false */
video?: boolean;
/** Custom data to be passed to the call */
custom?: Record<
string,
| string
| boolean
| number
| null
| Record<string, string | boolean | number | null>
| string[]
| boolean[]
| number[]
>;
}
export interface CallEvent {
/** ID of the call */
callId: string;
/** Current state of the call */
state: CallState;
/** User ID of the participant in the call who triggered the event */
userId?: string;
/** Reason for the call state change, if applicable */
reason?: string;
/** Information about the caller (for incoming calls) */
caller?: CallMember;
/** List of call members */
members?: CallMember[];
custom?: Record<
string,
| string
| boolean
| number
| null
| Record<string, string | boolean | number | null>
| string[]
| boolean[]
| number[]
>;
count?: number;
}
export interface IncomingCallPayload {
/** Full call CID (e.g. default:123) */
cid: string;
/** Event type (currently always "incoming") */
type: 'incoming';
/** Information about the caller */
caller?: CallMember;
/** Custom data to be passed to the call */
custom?: Record<
string,
| string
| boolean
| number
| null
| Record<string, string | boolean | number | null>
| string[]
| boolean[]
| number[]
>;
/**
* Get the native Capacitor plugin version
*
* @returns {Promise<{ id: string }>} an Promise with version for this device
* @throws An error if the something went wrong
*/
getPluginVersion(): Promise<{ version: string }>;
}
export interface CameraEnabledResponse {
enabled: boolean;
}
export type StreamCallLayout = 'grid' | 'spotlight' | 'dynamic' | 'fullScreen' | 'fullscreen';
export interface DynamicApiKeyResponse {
/** The dynamic API key if set, null if not */
apiKey: string | null;
/** Whether a dynamic key is currently set */
hasDynamicKey: boolean;
}
export interface CurrentUserResponse {
/** User ID of the current user */
userId: string;
/** Display name of the current user */
name: string;
/** Avatar URL of the current user */
imageURL?: string;
/** Whether the user is currently logged in */
isLoggedIn: boolean;
}
export interface PushNotificationsConfig {
pushProviderName: string;
voipProviderName: string;
}
export type CallType = 'default' | 'audio' | 'audio_room' | 'livestream' | 'development';
export type CallState =
// User-facing states
| 'idle'
| 'ringing'
| 'joining'
| 'reconnecting'
| 'joined'
| 'leaving'
| 'left'
// Event-specific states
| 'created'
| 'session_started'
| 'rejected'
| 'participant_counts'
| 'missed'
| 'accepted'
| 'ended'
| 'camera_enabled'
| 'camera_disabled'
| 'speaker_enabled'
| 'speaker_disabled'
| 'microphone_enabled'
| 'microphone_disabled'
| 'outgoing_call_ended'
| 'unknown';

本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。

如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-stream-call 针对使用 @capgo/capacitor-stream-call 时的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。