modified: android/app/build.gradle

modified:   android/app/src/main/AndroidManifest.xml
	modified:   lib/controller/firebase/firbase_messge.dart
	modified:   lib/controller/functions/call_controller.dart
	modified:   lib/controller/functions/crud.dart
	modified:   lib/views/home/map_widget.dart/call_passenger_page.dart
	modified:   macos/Flutter/GeneratedPluginRegistrant.swift
	modified:   pubspec.lock
	modified:   pubspec.yaml
	modified:   windows/flutter/generated_plugin_registrant.cc
	modified:   windows/flutter/generated_plugins.cmake
This commit is contained in:
Hamza-Ayed
2024-07-07 13:51:39 +03:00
parent 51d96c93cd
commit 67b5a20058
11 changed files with 407 additions and 448 deletions

View File

@@ -1,134 +1,134 @@
import 'package:SEFER/constant/api_key.dart';
import 'package:SEFER/controller/functions/crud.dart';
import 'package:SEFER/controller/home/map_passenger_controller.dart';
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
// import 'package:SEFER/constant/api_key.dart';
// import 'package:SEFER/controller/functions/crud.dart';
// import 'package:SEFER/controller/home/map_passenger_controller.dart';
// import 'package:agora_rtc_engine/agora_rtc_engine.dart';
// import 'package:get/get.dart';
// import 'package:permission_handler/permission_handler.dart';
import '../../constant/box_name.dart';
import '../firebase/firbase_messge.dart';
import '../../main.dart';
// import '../../constant/box_name.dart';
// import '../firebase/firbase_messge.dart';
// import '../../main.dart';
class CallController extends GetxController {
String channelName = ''; // Get.find<MapDriverController>().rideId;
String token = '';
// int uid = int.parse(box.read(BoxName.phoneDriver)); // uid of the local user
int uid = 0;
int? remoteUid; // uid of the remote user
bool _isJoined = false; // Indicates if the local user has joined the channel
String status = '';
late RtcEngine agoraEngine; // Agora engine instance
// class CallController extends GetxController {
// String channelName = ''; // Get.find<MapDriverController>().rideId;
// String token = '';
// // int uid = int.parse(box.read(BoxName.phoneDriver)); // uid of the local user
// int uid = 0;
// int? remoteUid; // uid of the remote user
// bool _isJoined = false; // Indicates if the local user has joined the channel
// String status = '';
// late RtcEngine agoraEngine; // Agora engine instance
@override
void onInit() {
super.onInit();
// if (box.read(BoxName.passengerID) != null) {
channelName = Get.find<MapPassengerController>().rideId; // 'sefer300'; //
remoteUid = int.parse(Get.find<MapPassengerController>().driverPhone);
uid = int.parse(box.read(BoxName.phone));
// } else {
// channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
// remoteUid = int.parse(Get.find<MapDriverController>().passengerPhone);
// uid = int.parse(box.read(BoxName.phoneDriver));
// }
// @override
// void onInit() {
// super.onInit();
// // if (box.read(BoxName.passengerID) != null) {
// channelName = Get.find<MapPassengerController>().rideId; // 'sefer300'; //
// remoteUid = int.parse(Get.find<MapPassengerController>().driverPhone);
// uid = int.parse(box.read(BoxName.phone));
// // } else {
// // channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
// // remoteUid = int.parse(Get.find<MapDriverController>().passengerPhone);
// // uid = int.parse(box.read(BoxName.phoneDriver));
// // }
initAgoraFull();
}
// initAgoraFull();
// }
initAgoraFull() async {
await fetchToken();
// Set up an instance of Agora engine
setupVoiceSDKEngine();
// join();
FirebaseMessagesController().sendNotificationToPassengerToken(
'Call Income from Passenger',
'${'You have call from Passenger'.tr} ${box.read(BoxName.name)}',
Get.find<MapPassengerController>().driverToken,
[
token,
channelName,
uid.toString(),
remoteUid.toString(),
],
'iphone_ringtone.wav',
);
join();
}
// initAgoraFull() async {
// await fetchToken();
// // Set up an instance of Agora engine
// setupVoiceSDKEngine();
// // join();
// FirebaseMessagesController().sendNotificationToPassengerToken(
// 'Call Income from Passenger',
// '${'You have call from Passenger'.tr} ${box.read(BoxName.name)}',
// Get.find<MapPassengerController>().driverToken,
// [
// token,
// channelName,
// uid.toString(),
// remoteUid.toString(),
// ],
// 'iphone_ringtone.wav',
// );
// join();
// }
@override
void onClose() {
agoraEngine.leaveChannel();
super.onClose();
}
// @override
// void onClose() {
// agoraEngine.leaveChannel();
// super.onClose();
// }
Future<void> setupVoiceSDKEngine() async {
// retrieve or request microphone permission
await [Permission.microphone].request();
// Future<void> setupVoiceSDKEngine() async {
// // retrieve or request microphone permission
// await [Permission.microphone].request();
//create an instance of the Agora engine
agoraEngine = createAgoraRtcEngine();
await agoraEngine.initialize(RtcEngineContext(appId: AK.agoraAppId));
// Register the event handler
agoraEngine.registerEventHandler(
RtcEngineEventHandler(
onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
// Get.snackbar(
// "Local user uid:${connection.localUid} joined the channel", '');
status = 'joined'.tr;
_isJoined = true;
update();
},
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
// Get.snackbar("Remote user uid:$remoteUid joined the channel", '');
status = Get.find<MapPassengerController>().driverName.toString();
' joined'.tr;
remoteUid = remoteUid;
update();
},
onUserOffline: (RtcConnection connection, int? remoteUid,
UserOfflineReasonType reason) {
// Get.snackbar("Remote user uid:$remoteUid left the channel", '');
status = 'Call left'.tr;
remoteUid = null;
update();
},
),
);
}
// //create an instance of the Agora engine
// agoraEngine = createAgoraRtcEngine();
// await agoraEngine.initialize(RtcEngineContext(appId: AK.agoraAppId));
// // Register the event handler
// agoraEngine.registerEventHandler(
// RtcEngineEventHandler(
// onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
// // Get.snackbar(
// // "Local user uid:${connection.localUid} joined the channel", '');
// status = 'joined'.tr;
// _isJoined = true;
// update();
// },
// onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
// // Get.snackbar("Remote user uid:$remoteUid joined the channel", '');
// status = Get.find<MapPassengerController>().driverName.toString();
// ' joined'.tr;
// remoteUid = remoteUid;
// update();
// },
// onUserOffline: (RtcConnection connection, int? remoteUid,
// UserOfflineReasonType reason) {
// // Get.snackbar("Remote user uid:$remoteUid left the channel", '');
// status = 'Call left'.tr;
// remoteUid = null;
// update();
// },
// ),
// );
// }
void join() async {
// Set channel options including the client role and channel profile
ChannelMediaOptions options = const ChannelMediaOptions(
clientRoleType: ClientRoleType.clientRoleBroadcaster,
channelProfile: ChannelProfileType.channelProfileCommunication,
);
// void join() async {
// // Set channel options including the client role and channel profile
// ChannelMediaOptions options = const ChannelMediaOptions(
// clientRoleType: ClientRoleType.clientRoleBroadcaster,
// channelProfile: ChannelProfileType.channelProfileCommunication,
// );
await agoraEngine.joinChannel(
token: token,
channelId: channelName,
options: options,
uid: uid,
);
}
// await agoraEngine.joinChannel(
// token: token,
// channelId: channelName,
// options: options,
// uid: uid,
// );
// }
void leave() {
_isJoined = false;
remoteUid = null;
update();
agoraEngine.leaveChannel();
}
// void leave() {
// _isJoined = false;
// remoteUid = null;
// update();
// agoraEngine.leaveChannel();
// }
// Clean up the resources when you leave
@override
void dispose() async {
await agoraEngine.leaveChannel();
super.dispose();
}
// // Clean up the resources when you leave
// @override
// void dispose() async {
// await agoraEngine.leaveChannel();
// super.dispose();
// }
fetchToken() async {
var res = await CRUD()
.getAgoraToken(channelName: channelName, uid: uid.toString());
token = res;
update();
}
}
// fetchToken() async {
// var res = await CRUD()
// .getAgoraToken(channelName: channelName, uid: uid.toString());
// token = res;
// update();
// }
// }