【问题标题】:How to ask user to join channel to start a call using Agora.io如何使用 Agora.io 要求用户加入频道开始通话
【发布时间】:2021-01-06 10:11:14
【问题描述】:

我在我的 React Native 项目中使用 Agora.io 进行视频通话,我想知道我什么时候会给某人打电话,我会加入频道,但是我如何才能在应用程序中显示来电 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,
    );
  };

接收方如何接听电话

【问题讨论】:

    标签: react-native webrtc agora.io videocall


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多