如何使用Agora.io请求用户加入频道以启动呼叫



我在我的react原生项目中使用Agora.io进行视频通话,我想知道什么时候我会给tom某人打电话,我会加入频道,但我如何在接收手机的应用程序中显示来电UI。这样他也可以加入频道开始通话。如果你有任何资源,请告诉我。感谢

这是初始化agro-sdk的代码

init = async () => {
const {appId} = this.state;
this._engine = await RtcEngine.create(appId);
await this._engine.enableVideo();
this.startCall();
this._engine.addListener('Warning', (warn) => {
console.log('Warning', warn);
});
this._engine.addListener('Error', (err) => {
console.log('Error', err);
});
this._engine.addListener('UserJoined', (uid, elapsed) => {
console.log('UserJoined', uid, elapsed);
// Get current peer IDs
const {peerIds} = this.state;
// If new user
if (peerIds.indexOf(uid) === -1) {
this.setState({
// Add peer ID to state array
peerIds: [...peerIds, uid],
});
}
});
this._engine.addListener('UserOffline', (uid, reason) => {
console.log('UserOffline', uid, reason);
const {peerIds} = this.state;
this.setState({
// Remove peer ID from state array
peerIds: peerIds.filter((id) => id !== uid),
});
});
// If Local user joins RTC channel
this._engine.addListener('JoinChannelSuccess', (channel, uid, elapsed) => {
console.log('JoinChannelSuccess', channel, uid, elapsed);
// Set state variable to true
this.setState({
joinSucceed: true,
});
});
};

这是开始呼叫的代码

startCall = async () => {
// Join Channel using null token and channel name
await this._engine?.joinChannel(
this.state.token,
this.state.channelName,
null,
0,
);
};

接收机如何接收呼叫

Agora SDK没有任何内置功能。react-native-callkeep是一个非常棒的库。

https://github.com/react-native-webrtc/react-native-callkeep

从本质上讲,当有人试图打电话给你时,这个库将帮助你绘制用户界面。它使用firebase推送通知来通知被调用者。

相关内容

  • 没有找到相关文章

最新更新