7/6/5
This commit is contained in:
@@ -1,129 +1,129 @@
|
||||
import 'package:SEFER/constant/api_key.dart';
|
||||
import 'package:SEFER/controller/functions/crud.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: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 '../home/captin/map_driver_controller.dart';
|
||||
import '../../main.dart';
|
||||
// import '../../constant/box_name.dart';
|
||||
// import '../firebase/firbase_messge.dart';
|
||||
// import '../home/captin/map_driver_controller.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();
|
||||
// @override
|
||||
// void onInit() {
|
||||
// super.onInit();
|
||||
|
||||
channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
|
||||
remoteUid = int.parse(Get.find<MapDriverController>().passengerPhone);
|
||||
uid = int.parse(box.read(BoxName.phoneDriver));
|
||||
// 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().sendNotificationToPassengerTokenCALL(
|
||||
'Call Income',
|
||||
'${'You have call from driver'.tr} ${box.read(BoxName.nameDriver)}',
|
||||
Get.find<MapDriverController>().tokenPassenger,
|
||||
[
|
||||
token,
|
||||
channelName,
|
||||
uid.toString(),
|
||||
remoteUid.toString(),
|
||||
],
|
||||
);
|
||||
join();
|
||||
}
|
||||
// initAgoraFull() async {
|
||||
// await fetchToken();
|
||||
// // Set up an instance of Agora engine
|
||||
// setupVoiceSDKEngine();
|
||||
// // join();
|
||||
// FirebaseMessagesController().sendNotificationToPassengerTokenCALL(
|
||||
// 'Call Income',
|
||||
// '${'You have call from driver'.tr} ${box.read(BoxName.nameDriver)}',
|
||||
// Get.find<MapDriverController>().tokenPassenger,
|
||||
// [
|
||||
// token,
|
||||
// channelName,
|
||||
// uid.toString(),
|
||||
// remoteUid.toString(),
|
||||
// ],
|
||||
// );
|
||||
// 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<MapDriverController>().passengerName} '
|
||||
'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<MapDriverController>().passengerName} '
|
||||
// // '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();
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -388,7 +388,7 @@ class AI extends GetxController {
|
||||
'displacement': responseIdCardDriverEgyptBack['engine'].toString(),
|
||||
'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
|
||||
'registration_date':
|
||||
'${responseIdCardDriverEgyptBack['inspection_date']}-01-01',
|
||||
'${responseIdCardDriverEgyptBack['inspection_date']}',
|
||||
});
|
||||
isLoading = false;
|
||||
update();
|
||||
|
||||
@@ -113,4 +113,100 @@ class ImageController extends GetxController {
|
||||
'Failed to upload image: ${res.statusCode} - ${res.body}');
|
||||
}
|
||||
}
|
||||
|
||||
choosImagePicture(String link, String imageType) async {
|
||||
final pickedImage = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
// preferredCameraDevice: CameraDevice.rear,
|
||||
// maxHeight: Get.height * .3,
|
||||
// maxWidth: Get.width * .9,
|
||||
// imageQuality: 100,
|
||||
);
|
||||
image = File(pickedImage!.path);
|
||||
|
||||
croppedFile = await ImageCropper().cropImage(
|
||||
sourcePath: image!.path,
|
||||
aspectRatioPresets: [
|
||||
CropAspectRatioPreset.square,
|
||||
CropAspectRatioPreset.ratio3x2,
|
||||
CropAspectRatioPreset.original,
|
||||
CropAspectRatioPreset.ratio4x3,
|
||||
CropAspectRatioPreset.ratio16x9
|
||||
],
|
||||
uiSettings: [
|
||||
AndroidUiSettings(
|
||||
toolbarTitle: 'Cropper'.tr,
|
||||
toolbarColor: AppColor.blueColor,
|
||||
toolbarWidgetColor: AppColor.yellowColor,
|
||||
initAspectRatio: CropAspectRatioPreset.original,
|
||||
lockAspectRatio: false),
|
||||
IOSUiSettings(
|
||||
title: 'Cropper'.tr,
|
||||
),
|
||||
],
|
||||
);
|
||||
myImage = File(pickedImage.path);
|
||||
isloading = true;
|
||||
update();
|
||||
// Save the cropped image
|
||||
File savedCroppedImage = File(croppedFile!.path);
|
||||
print('link =$link');
|
||||
try {
|
||||
await uploadImage(
|
||||
savedCroppedImage,
|
||||
{
|
||||
'driverID':
|
||||
box.read(BoxName.driverID) ?? box.read(BoxName.passengerID),
|
||||
'imageType': imageType
|
||||
},
|
||||
link,
|
||||
);
|
||||
} catch (e) {
|
||||
Get.snackbar('Image Upload Failed'.tr, e.toString(),
|
||||
backgroundColor: AppColor.redColor);
|
||||
} finally {
|
||||
isloading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
uploadImagePicture(File file, Map data, String link) async {
|
||||
var request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse(link), //'https://ride.mobile-app.store/uploadImage1.php'
|
||||
);
|
||||
|
||||
var length = await file.length();
|
||||
var stream = http.ByteStream(file.openRead());
|
||||
var multipartFile = http.MultipartFile(
|
||||
'image',
|
||||
stream,
|
||||
length,
|
||||
filename: basename(file.path),
|
||||
);
|
||||
request.headers.addAll({
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
|
||||
});
|
||||
// Set the file name to the driverID
|
||||
request.files.add(
|
||||
http.MultipartFile(
|
||||
'image',
|
||||
stream,
|
||||
length,
|
||||
filename: '${box.read(BoxName.driverID)}.jpg',
|
||||
),
|
||||
);
|
||||
data.forEach((key, value) {
|
||||
request.fields[key] = value;
|
||||
});
|
||||
var myrequest = await request.send();
|
||||
var res = await http.Response.fromStream(myrequest);
|
||||
if (res.statusCode == 200) {
|
||||
return jsonDecode(res.body);
|
||||
} else {
|
||||
throw Exception(
|
||||
'Failed to upload image: ${res.statusCode} - ${res.body}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user