while developing agora video call app the application is getting stuck on clicking call end button
- This is where I am getting the breakpoint
/// Function to dispose the RTC and RTM engine.
Future<void> endCall({required SessionController sessionController}) async {
await sessionController.value.engine?.leaveChannel();
if (sessionController.value.connectionData!.rtmEnabled)//This is where its getting breakpoint {
await sessionController.value.agoraRtmChannel?.leave();
await sessionController.value.agoraRtmClient?.logout();
}
await sessionController.value.engine?.destroy();
}
The code is
import 'dart:convert';
import 'package:agora_uikit/agora_uikit.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
class VedioCall extends StatefulWidget {
String channelName = "test";
VedioCall({required this.channelName});
@override
State<VedioCall> createState() => _VedioCallState();
}
class _VedioCallState extends State<VedioCall> {
late final AgoraClient _client;
bool _loading = true;
String tempToken = "";
@override
void initState() {
getToken();
super.initState();
}
Future<void> getToken() async {
String link =
"https://Agora-Node-TokenServer.vinaym4.repl.co/access_token?channelName=${widget.channelName}";
Response _response = await get(Uri.parse(link));
Map data = jsonDecode(_response.body);
setState(() {
tempToken = data["token"];
});
_client = AgoraClient(
agoraEventHandlers: AgoraRtcEventHandlers(
leaveChannel: (State)=>Navigator.pop(context),
),
agoraConnectionData: AgoraConnectionData(
appId: "5a4c1108a1af4a76924c9461d120dc47",
tempToken: tempToken,
channelName: widget.channelName,
),
enabledPermission: [Permission.camera, Permission.microphone]);
Future.delayed(Duration(seconds: 1)).then(
(value) => setState(() => _loading = false),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: _loading
? Center(
child: CircularProgressIndicator(),
)
: Stack(
children: [
AgoraVideoViewer(
client: _client,
),
AgoraVideoButtons(client: _client)
],
),
),
);
;
}
}
in the debug console section
- E/flutter (28049): #0 endCall
- E/flutter (28049): #1 _AgoraVideoButtonsState._onCallEnd
Plz anyone help me to get rid of the failure
CodePudding user response:
Check that sessionController.value.connectionData is not null:
Future<void> endCall({required SessionController sessionController}) async {
await sessionController.value.engine?.leaveChannel();
if (sessionController.value.connectionData != null && sessionController.value.connectionData!.rtmEnabled) {
await sessionController.value.agoraRtmChannel?.leave();
await sessionController.value.agoraRtmClient?.logout();
}
await sessionController.value.engine?.destroy();
}