This commit is contained in:
Hamza-Ayed
2024-02-18 13:44:35 +03:00
parent 4d9e76697b
commit 9d839f02ae
17 changed files with 521 additions and 30 deletions

View File

@@ -0,0 +1,127 @@
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 '../../../../main.dart';
class CallController extends GetxController {
String channelName =
'sefer300'; //Get.find<MapDriverController>().passengerId;
String token =
"00612994c6e707543e68d5638894d04f989IAA9fx7yHezOOXPq1l4MwrNgPVOxWj7VnirB9Ks6X37jS6MLiA8AAAAAEABXi+nQ7GjSZQEAAQAAAAAA";
// 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();
// 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('uid is $uid');
// await fetchToken();
// Set up an instance of Agora engine
setupVoiceSDKEngine();
}
@override
void onClose() {
agoraEngine.leaveChannel();
super.onClose();
}
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(const RtcEngineContext(appId: AK.agoraAppId));
print('eeeeeeeeeeeeeeeeeeee');
print(agoraEngine);
// 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 = '${box.read(BoxName.nameDriver) ?? box.read(BoxName.name)}'
' 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,
);
await agoraEngine.joinChannel(
token: token,
channelId: channelName,
options: options,
uid: uid,
);
}
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();
}
fetchToken() async {
var res = await CRUD().getAgora(
channelName: 'sefer22'); //Get.find<MapDriverController>().rideId);
print('hhhhhhhhhhhhhhhhhhhhhhh');
print(res);
channelName = 'sefer22';
token = res['token'];
print('token is $token');
update();
}
}

View File

@@ -0,0 +1,173 @@
import 'dart:async';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/main.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
import '../../../../constant/api_key.dart';
const String appId = AK.agoraAppId;
class DriverCallPage extends StatefulWidget {
const DriverCallPage({super.key});
@override
State<DriverCallPage> createState() => _DriverCallPageState();
}
class _DriverCallPageState extends State<DriverCallPage> {
String channelName = 'sefer300';
String token =
"00612994c6e707543e68d5638894d04f989IAACchY2SBwRcuw2mt+BocxbF+fmFKvjOS/hekkirRWfuqMLiA8AAAAAEADs3TvfbjrSZQEAAQAAAAAA";
// 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
late RtcEngine agoraEngine; // Agora engine instance
final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey =
GlobalKey<ScaffoldMessengerState>(); // Global key to access the scaffold
showMessage(String message) {
scaffoldMessengerKey.currentState?.showSnackBar(SnackBar(
content: Text(message),
));
}
@override
void initState() {
super.initState();
_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('uid is $uid');
// Set up an instance of Agora engine
setupVoiceSDKEngine();
}
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(const RtcEngineContext(appId: AK.agoraAppId));
print('eeeeeeeeeeeeeeeeeeee');
print(agoraEngine);
// Register the event handler
agoraEngine.registerEventHandler(
RtcEngineEventHandler(
onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
showMessage(
"Local user uid:${connection.localUid} joined the channel");
setState(() {
_isJoined = true;
});
},
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
showMessage("Remote user uid:$remoteUid joined the channel");
setState(() {
_remoteUid = remoteUid;
});
},
onUserOffline: (RtcConnection connection, int remoteUid,
UserOfflineReasonType reason) {
showMessage("Remote user uid:$remoteUid left the channel");
setState(() {
_remoteUid = null;
});
},
),
);
}
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,
);
}
//https://console.agora.io/invite?sign=5e9e22d06f22caeeada9954c9e908572%253A5ba8aed978a35eab5a5113742502ded2a41478b2a81cb19c71a30776e125b58a
void leave() {
setState(() {
_isJoined = false;
_remoteUid = null;
});
agoraEngine.leaveChannel();
}
// Clean up the resources when you leave
@override
void dispose() async {
await agoraEngine.leaveChannel();
super.dispose();
}
// Build UI
@override
Widget build(BuildContext context) {
return MaterialApp(
scaffoldMessengerKey: scaffoldMessengerKey,
home: Scaffold(
appBar: AppBar(
title: const Text('Get started with Voice Calling'),
),
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
children: [
// Status text
Container(height: 40, child: Center(child: _status())),
// Button Row
Row(
children: <Widget>[
Expanded(
child: ElevatedButton(
child: const Text("Join"),
onPressed: () => {join()},
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
child: const Text("Leave"),
onPressed: () => {leave()},
),
),
],
),
],
)),
);
}
Widget _status() {
String statusText;
if (!_isJoined)
statusText = 'Join a channel';
else if (_remoteUid == null)
statusText = 'Waiting for a remote user to join...';
else
statusText = 'Connected to remote user, uid:$_remoteUid';
return Text(
statusText,
);
}
}

View File

@@ -1,3 +1,4 @@
import 'package:SEFER/views/home/Captin/home_captain/driver_call_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
@@ -12,8 +13,10 @@ import '../../../../constant/table_names.dart';
import '../../../../controller/functions/location_controller.dart';
import '../../../../controller/home/captin/home_captain_controller.dart';
import '../../../../controller/home/captin/order_request_controller.dart';
import '../../../../controller/home/captin/widget/call_page.dart';
import '../../../../controller/home/captin/widget/connect.dart';
import '../../../../controller/home/captin/widget/left_menu_map_captain.dart';
import '../../../../controller/home/payment/captain_wallet_controller.dart';
import '../../../../controller/local/local_controller.dart';
import '../../../../main.dart';
import '../../../widgets/circle_container.dart';
@@ -27,7 +30,7 @@ class HomeCaptain extends StatelessWidget {
Widget build(BuildContext context) {
Get.put(OrderRequestController());
Get.put(HomeCaptainController());
Get.put(LocationController());
// Get.put(LocationController());
print('local is ${Get.find<LocaleController>().language!.countryCode}');
return Scaffold(
appBar: AppBar(
@@ -143,12 +146,18 @@ class HomeCaptain extends StatelessWidget {
color: AppColor.yellowColor,
),
Text(
' You Have in ${AppInformation.appName} '.tr +
' You Have in'.tr +
' ${AppInformation.appName} '.tr +
homeCaptainController.totalMoneyInSEFER,
style: AppStyle.title,
),
],
),
Text(
'Total points is '.tr +
Get.find<CaptainWalletController>().totalPoints,
style: AppStyle.title,
),
],
))),
),
@@ -187,15 +196,29 @@ class HomeCaptain extends StatelessWidget {
borderRadius: BorderRadius.circular(15)),
child: IconButton(
onPressed: () {
// Get.to(
// () => CameraWidgetCardId(),
// );
Get.to(
() => const DriverCallPage(),
);
},
icon: const Icon(Fontisto.history),
icon: const Icon(Fontisto.phone),
),
),
),
leftMainMenuCaptainIcons(),
// callPage(),
Positioned(
top: Get.height * .2,
// left: 20,
// right: 20,
bottom: Get.height * .4,
child: IconButton(
onPressed: () {
Get.to(() => const CallPage());
},
icon: const Icon(Icons.call),
),
),
],
),
);

View File

@@ -234,6 +234,22 @@ class PassengerInfoWindow extends StatelessWidget {
controller
.isArrivedSend =
false;
} else {
Get.defaultDialog(
title:
'You are not in near to passenger location'
.tr,
middleText:
'please go to picker location exactly'
.tr,
confirm:
MyElevatedButton(
title:
'Ok'.tr,
onPressed:
() {
Get.back();
}));
}
})
: const SizedBox()

View File

@@ -10,7 +10,7 @@ import '../../../constant/colors.dart';
import '../../../controller/firebase/local_notification.dart';
import '../../../controller/functions/tts.dart';
import '../../../controller/home/map_passenger_controller.dart';
import '../Captin/orderCaptin/call.dart';
import '../Captin/home_captain/driver_call_page.dart';
GetBuilder<MapPassengerController> leftMainMenuIcons() {
final textToSpeechController = Get.put(TextToSpeechController());
@@ -110,9 +110,9 @@ GetBuilder<MapPassengerController> leftMainMenuIcons() {
borderRadius: BorderRadius.circular(15)),
child: IconButton(
onPressed: () {
NotificationController()
.showNotification('Order', 'hi this is', 'tone1');
// Get.to(() => CallPage(callID: '111'));
// NotificationController()
// .showNotification('Order', 'hi this is', 'tone1');
Get.to(() => DriverCallPage());
// Get.to(() => CallPage(callID: controller.rideId));
},
icon: const Icon(