This commit is contained in:
Hamza-Ayed
2024-02-22 16:19:45 +03:00
parent 9d839f02ae
commit a9f557ca83
85 changed files with 9196 additions and 494 deletions

View File

@@ -5,17 +5,16 @@ import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import '../../../../constant/box_name.dart';
import '../../../../controller/firebase/firbase_messge.dart';
import '../../../../controller/home/captin/map_driver_controller.dart';
import '../../../../main.dart';
class CallController extends GetxController {
String channelName =
'sefer300'; //Get.find<MapDriverController>().passengerId;
String token =
"00612994c6e707543e68d5638894d04f989IAA9fx7yHezOOXPq1l4MwrNgPVOxWj7VnirB9Ks6X37jS6MLiA8AAAAAEABXi+nQ7GjSZQEAAQAAAAAA";
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
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
@@ -23,21 +22,31 @@ class CallController extends GetxController {
@override
void onInit() {
super.onInit();
channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
remoteUid = int.parse(Get.find<MapDriverController>().phone);
uid = int.parse(box.read(BoxName.phoneDriver));
// initAgoraFull();
}
initAgoraFull() async {
_remoteUid = box.read(BoxName.phone) != null
? int.parse(box.read(BoxName.phone))
: int.parse(box.read(BoxName.phoneDriver));
uid = box.read(BoxName.phoneDriver) != null
? int.parse(box.read(BoxName.phoneDriver))
: int.parse(box.read(BoxName.phone));
print('remoteid is $_remoteUid');
print('remoteid is $remoteUid');
print('uid is $uid');
// await fetchToken();
await fetchToken();
// Set up an instance of Agora engine
setupVoiceSDKEngine();
join();
FirebaseMessagesController().sendNotificationToPassengerToken(
'Call Income'.tr,
'${'You have call from driver'.tr} ${box.read(BoxName.nameDriver)}',
Get.find<MapDriverController>().tokenPassenger,
[
token,
channelName,
uid.toString(),
remoteUid.toString(),
],
);
join();
}
@override
@@ -59,25 +68,26 @@ class CallController extends GetxController {
agoraEngine.registerEventHandler(
RtcEngineEventHandler(
onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
Get.snackbar(
"Local user uid:${connection.localUid} joined the channel", '');
// 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 = '${box.read(BoxName.nameDriver) ?? box.read(BoxName.name)}'
// Get.snackbar("Remote user uid:$remoteUid joined the channel", '');
status = '${Get.find<MapDriverController>().name}'
' joined'
.tr
.tr;
_remoteUid = remoteUid;
remoteUid = remoteUid;
update();
},
onUserOffline: (RtcConnection connection, int remoteUid,
onUserOffline: (RtcConnection connection, int? remoteUid,
UserOfflineReasonType reason) {
Get.snackbar("Remote user uid:$remoteUid left the channel", '');
// Get.snackbar("Remote user uid:$remoteUid left the channel", '');
status = 'Call left'.tr;
_remoteUid = null;
remoteUid = null;
update();
},
),
@@ -101,7 +111,7 @@ class CallController extends GetxController {
void leave() {
_isJoined = false;
_remoteUid = null;
remoteUid = null;
update();
agoraEngine.leaveChannel();
}
@@ -114,13 +124,9 @@ class CallController extends GetxController {
}
fetchToken() async {
var res = await CRUD().getAgora(
channelName: 'sefer22'); //Get.find<MapDriverController>().rideId);
print('hhhhhhhhhhhhhhhhhhhhhhh');
print(res);
channelName = 'sefer22';
token = res['token'];
var res = await CRUD()
.getAgoraToken(channelName: channelName, uid: uid.toString());
token = res;
print('token is $token');
update();
}