AgoraUiKIt First Call / joining Video Call leads to bugs Flutter

38 Views Asked by At

So i tried to implement a 1to1 Video Call in flutter and used the agorauikit for that. But it seems buggy or i did something wrong.

import 'package:flutter/material.dart';
import 'package:agora_uikit/agora_uikit.dart';
import 'package:flutter_login_screen/constants.dart';
import 'package:fluttertoast/fluttertoast.dart';

// Global variables to store the state
bool globalVideoDisabled = true;
bool globalAudioMuted = true;

class CallScreen extends StatefulWidget {
  const CallScreen({super.key});

  @override
  State createState() {
    return _CallScreenState();
  }
}

class _CallScreenState extends State<CallScreen> {
  final AgoraClient _client = AgoraClient(
    agoraConnectionData: AgoraConnectionData(
      appId: agoraId,
      channelName: 'test',
      tempToken: "",
    ),
    enabledPermission: [
      Permission.camera,
      Permission.microphone,
    ],
    agoraEventHandlers: AgoraRtcEventHandlers (
      onUserJoined: ((connection, remoteUid, elapsed) => Fluttertoast.showToast(msg: "You joined the Video Call")),
      onUserOffline: (connection, remoteUid, reason) { if (reason == UserOfflineReasonType.userOfflineQuit) { Fluttertoast.showToast(msg: "User with ID $remoteUid left the video call."); }},
      // onNetworkQuality: (connection, remoteUid, txQuality, rxQuality) { Fluttertoast.showToast(msg: "Network Quality: $txQuality, $rxQuality"); },
      onUserMuteAudio: (connection, remoteUid, muted) { if(muted==true){ Fluttertoast.showToast(msg: "User with ID $remoteUid muted their audio.");}},
      onUserMuteVideo: (connection, remoteUid, muted) { if(muted==true){ Fluttertoast.showToast(msg: "User with ID $remoteUid disabled their video.");}},
      
    ),
  );

  @override
  void initState() {
    super.initState();
    _initAgora();
  }

  @override
  void dispose() {
    globalVideoDisabled = _client.sessionController.value.isLocalVideoDisabled;
    globalAudioMuted = _client.sessionController.value.isLocalUserMuted;
    super.dispose();
  }


  Future<void> _initAgora() async {
    await _client.initialize();

    // Set the initial state based on the global variables
    Fluttertoast.showToast(msg: "Global Video Disabled: $globalVideoDisabled");
    Fluttertoast.showToast(msg: "Global Audio Muted: $globalAudioMuted");
    if (globalVideoDisabled) {
      _client.sessionController.updateUserVideo(
          uid: _client.agoraConnectionData.uid ?? 0, videoDisabled: true);
    }
    if (globalAudioMuted) {
       _client.sessionController.updateUserAudio(
          uid: _client.agoraConnectionData.uid ?? 0, muted: true);
    }

    // _client.sessionController.value.copyWith(
    //     isLocalVideoDisabled:
    //         !(_client.sessionController.value.isLocalVideoDisabled));
    // await _client.sessionController.value.engine?.muteLocalVideoStream(
    //     _client.sessionController.value.isLocalVideoDisabled);
  }

  @override
  Widget build(BuildContext context) {
    return PopScope(
      onPopInvoked: (bool isPopInvoked) => false,
      child: Scaffold(
        body: SafeArea(
          child: Stack(
            children: [
              AgoraVideoViewer(
                client: _client,
                layoutType: Layout.oneToOne,
                showAVState: true,
                disabledVideoWidget: Container(
                  color: Colors.black,
                  child: const Center(
                    child: Text(
                      "Video Disabled",
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
              ),
              AgoraVideoButtons(
                client: _client,
                autoHideButtonTime: 10,
                autoHideButtons: true,
                extraButtons: [
                  IconButton(
                    icon: const Icon(Icons.chat_bubble),
                    onPressed: () {
                      Fluttertoast.showToast(msg: "Chat not yet implemented");
                    },
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

this is my code für the connection

when i try to join the first call by using a button which leads to the call_screen to freeze the video, the app doesnt react anymore or black screen. When i close the app (otherwise nothing is possible anymore, i can start the video call normally. So what could be the problem with the first call that is leads to this bugs.

Second, i used global var to define, that the first time the user enters the video call, the video and audio should be muted/disabled.

But when rejoin the videocall or join it at first, the video and audio is visible for the remote user, even when the buttons for mute and video are disabled! I also logged that with the toast, and even though the vidoDisabled and muted are true, when a user joins the channel, the video and audio is visible for the remote users, even when on client side, the buttons are deactived...

SO the questions are:

  1. Why does the app freeze,blackscreen on the first video call joining
  2. Why does the mute, disable video not working when joining the session but afterwards, when i click the buttons, its normally working
0

There are 0 best solutions below