Flutter Agora.io calling screen
Asked Answered
B

3

8

I want to add in-app (video) calling like Messenger (Facebook) does. It works when one party creates channel and another one joins.

But is there a way to create calling screen where party B can accept or reject call? I am looking in Agora.io documentation but cannot find anything suitable for this.

This is my code though...

 Future<void> initialize() async {
    if (APP_ID.isEmpty) {
      setState(() {
        _infoStrings.add(
          'APP_ID missing, please provide your APP_ID in settings.dart',
        );
        _infoStrings.add('Agora Engine is not starting');
      });
      return;
    }

    await _initAgoraRtcEngine();
    _addAgoraEventHandlers();
    await AgoraRtcEngine.enableWebSdkInteroperability(true);
    await AgoraRtcEngine.setParameters('''
{\"che.video.lowBitRateStreamParameter\":{\"width\":320,\"height\":180,\"frameRate\":15,\"bitRate\":140}}''');
    await AgoraRtcEngine.joinChannel(null, 'Test', null, 0);
  }

  Future<void> _initAgoraRtcEngine() async {
    AgoraRtcEngine.create(APP_ID);
    AgoraRtcEngine.enableVideo();
  }

  void _addAgoraEventHandlers() {
    AgoraRtcEngine.onError = (dynamic code) {
      setState(() {
        final info = 'onError: $code';
        _infoStrings.add(info);
      });
    };

    AgoraRtcEngine.onJoinChannelSuccess = (
      String channel,
      int uid,
      int elapsed,
    ) {
      setState(() {
        final info = 'onJoinChannel: $channel, uid: $uid';
        _infoStrings.add(info);
      });
    };

    AgoraRtcEngine.onLeaveChannel = () {
      setState(() {
        _infoStrings.add('onLeaveChannel');
        _users.clear();
      });
    };

    AgoraRtcEngine.onUserJoined = (int uid, int elapsed) {
      setState(() {
        final info = 'userJoined: $uid';
        _infoStrings.add(info);
        _users.add(uid);
      });
    };

    AgoraRtcEngine.onUserOffline = (int uid, int reason) {
      setState(() {
        final info = 'userOffline: $uid';
        _infoStrings.add(info);
        _users.remove(uid);
      });
    };

    AgoraRtcEngine.onFirstRemoteVideoFrame = (
      int uid,
      int width,
      int height,
      int elapsed,
    ) {
      setState(() {
        final info = 'firstRemoteVideo: $uid ${width}x $height';
        _infoStrings.add(info);
      });
    };
  } 
Bohman answered 15/12, 2019 at 12:39 Comment(2)
Were you able to find a solution to this? If so, could you add some code to point me in the right direction?Deadwood
There is only solution for iOS so far github.com/peerwaya/flutter_voip_push_notificationBohman
S
4

You will need to push channelId to other user mobile in this case. The CS Guy has created very useful video on you tube to implement this step as well as calling screen.

https://www.youtube.com/watch?v=v9ngriCV0J0

Slurp answered 20/4, 2020 at 13:19 Comment(0)
G
1

You need to use Native ConnectionService for Android and Callkit of iOS.

You can find the official Agora samples for the above feature here: https://github.com/AgoraIO/Advanced-Video/tree/master/Calling-Interface, but I don't think Agora has call-interface sample in Flutter, you have to write the wrapper on your own for now.

Gravelly answered 16/12, 2019 at 10:6 Comment(1)
Updated URL: github.com/AgoraIO-Usecase/Video-CallingZora
G
0

widget.chatRoomId is the id specified for both of the users when you create a chatroom for them.

Future<void> onJoin() async {
// update input validation

  if (widget.chatRoomId.isNotEmpty) {
    // await for camera and mic permissions before pushing video page
    await _handleCameraAndMic();
    // push video page with given channel name
    await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => CallPage(
          channelName: widget.chatRoomId,
          // TODO: set to _role
          role: ClientRole.Broadcaster,
        ),
      ),
    );
  }
}
Giffie answered 14/8, 2020 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.