From 4f60227429ae55e18ca1a8d2c48e2952278f8653 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 13 Apr 2026 19:01:03 +0300 Subject: [PATCH] LiveCare Video Call fixes --- lib/core/cache_consts.dart | 1 + lib/core/utils/push_notification_handler.dart | 2 + .../tele_consultation/zoom/call_screen.dart | 108 ++++++++---------- lib/splashPage.dart | 4 +- 4 files changed, 56 insertions(+), 59 deletions(-) diff --git a/lib/core/cache_consts.dart b/lib/core/cache_consts.dart index c1e06aa3..c829adbf 100644 --- a/lib/core/cache_consts.dart +++ b/lib/core/cache_consts.dart @@ -78,5 +78,6 @@ class CacheConst { static const String isMonthlyReportEnabled = 'is-monthly-report-enabled'; static const String zoomRoomID = 'zoom-room-id'; + static const String callTypeID = 'call-type-id'; static String isAppOpenedFromCall = "is_app_opened_from_call"; } diff --git a/lib/core/utils/push_notification_handler.dart b/lib/core/utils/push_notification_handler.dart index e2925c29..6fc248f9 100644 --- a/lib/core/utils/push_notification_handler.dart +++ b/lib/core/utils/push_notification_handler.dart @@ -46,11 +46,13 @@ _incomingCall(Map data) async { // LandingPage.isOpenCallPage = true; String roomID = data['session_id'] ?? ''; + String callTypeID = data['AppointmentNo'] ?? ''; // GetIt.instance().saveString(key: CacheConst.zoomRoomID, value: roomID); // GetIt.instance().saveBool(key: CacheConst.isAppOpenedFromCall, value: true); Utils.saveStringFromPrefs(CacheConst.zoomRoomID, roomID); + Utils.saveStringFromPrefs(CacheConst.callTypeID, callTypeID); Utils.saveBoolFromPrefs(CacheConst.isAppOpenedFromCall, true); WidgetsFlutterBinding.ensureInitialized(); diff --git a/lib/presentation/tele_consultation/zoom/call_screen.dart b/lib/presentation/tele_consultation/zoom/call_screen.dart index 21836a8a..a2721aba 100644 --- a/lib/presentation/tele_consultation/zoom/call_screen.dart +++ b/lib/presentation/tele_consultation/zoom/call_screen.dart @@ -84,6 +84,7 @@ class _CallScreenState extends State { Color chatTextColor = const Color(0xFFAAAAAA); Widget changeNamePopup; final args = ModalRoute.of(context)!.settings.arguments as CallArguments; + var isFrontCamera = useState(true); useEffect(() { Future.microtask(() async { @@ -93,8 +94,11 @@ class _CallScreenState extends State { try { Map SDKaudioOptions = {"connect": true, "mute": false, "autoAdjustSpeakerVolume": false}; + // Map SDKvideoOptions = { + // "localVideoOn": true, + // }; Map SDKvideoOptions = { - "localVideoOn": true, + "localVideoOn": args.callType == 1 ? true : false, }; JoinSessionConfig joinSession = JoinSessionConfig( sessionName: args.sessionName, @@ -302,6 +306,19 @@ class _CallScreenState extends State { List? remoteUserList = await zoom.session.getRemoteUsers(); var leftUserListJson = jsonDecode(data['leftUsers']) as List; List leftUserLis = leftUserListJson.map((userJson) => ZoomVideoSdkUser.fromJson(userJson)).toList(); + + // If no remote users remain, the other participant has left — end the session + if (remoteUserList == null || remoteUserList.isEmpty) { + await zoom.leaveSession(true); + Navigator.pushAndRemoveUntil( + context, + CustomPageRoute( + page: LandingNavigation(), + ), + (r) => false); + return; + } + if (fullScreenUser.value != null) { for (var user in leftUserLis) { { @@ -313,8 +330,8 @@ class _CallScreenState extends State { } else { fullScreenUser.value = mySelf; } - remoteUserList?.add(mySelf!); - users.value = remoteUserList!; + remoteUserList.add(mySelf!); + users.value = remoteUserList; }); final userNameChangedListener = eventListener.addListener(EventType.onUserNameChanged, (data) async { @@ -817,63 +834,38 @@ class _CallScreenState extends State { } void onPressCameraList() async { - List options = []; List cameraList = await zoom.videoHelper.getCameraList(); - for (var camera in cameraList) { - options.add( - ListTile( - title: Text( - camera.deviceName, - style: const TextStyle( - fontSize: 14, - fontWeight: FontWeight.normal, - color: Colors.black, - ), - ), - onTap: () async => { - await zoom.videoHelper.switchCamera(camera.deviceId), - Navigator.of(context).pop(), - }, - ), - ); + if (cameraList.isEmpty) return; + + // Find the target camera by toggling between front and back + ZoomVideoSdkCameraDevice? targetCamera; + try { + if (isFrontCamera.value) { + // Currently front, switch to back + targetCamera = cameraList.firstWhere( + (c) => c.deviceName.toLowerCase().contains('back') || c.deviceName.toLowerCase().contains('rear'), + ); + } else { + // Currently back, switch to front + targetCamera = cameraList.firstWhere( + (c) => c.deviceName.toLowerCase().contains('front') || c.deviceName.toLowerCase().contains('facing'), + ); + } + } catch (_) { + targetCamera = null; + } + + // Fallback: if we can't identify by name, just pick the other camera + if (targetCamera == null && cameraList.length >= 2) { + final currentIndex = isFrontCamera.value ? 0 : 1; + final nextIndex = (currentIndex + 1) % cameraList.length; + targetCamera = cameraList[nextIndex]; + } + + if (targetCamera != null) { + await zoom.videoHelper.switchCamera(targetCamera.deviceId); + isFrontCamera.value = !isFrontCamera.value; } - options.add( - ListTile( - title: Text( - "Cancel", - style: const TextStyle( - fontSize: 14, - fontWeight: FontWeight.normal, - color: Colors.black, - ), - ), - onTap: () async => { - Navigator.of(context).pop(), - }, - ), - ); - showDialog( - context: context, - builder: (context) { - return Dialog( - elevation: 0.0, - insetPadding: const EdgeInsets.symmetric(horizontal: 40), - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), - child: SizedBox( - height: options.length * 60, - child: Scrollbar( - child: ListView( - shrinkWrap: true, - scrollDirection: Axis.vertical, - children: ListTile.divideTiles( - context: context, - tiles: options, - ).toList(), - ), - ), - ), - ); - }); } // Future onPressMore() async { diff --git a/lib/splashPage.dart b/lib/splashPage.dart index 64518f30..f17d8bc3 100644 --- a/lib/splashPage.dart +++ b/lib/splashPage.dart @@ -80,7 +80,9 @@ class _SplashScreenState extends State { navigateToTeleConsult() async { String roomID = await Utils.getStringFromPrefs(CacheConst.zoomRoomID); + String callTypeID = await Utils.getStringFromPrefs(CacheConst.callTypeID); print('RoomID: $roomID'); + print('callTypeID: $callTypeID'); // GetIt.instance().remove(key: CacheConst.isAppOpenedFromCall); Utils.removeFromPrefs(CacheConst.isAppOpenedFromCall); @@ -92,7 +94,7 @@ class _SplashScreenState extends State { GetIt.instance().navigatorKey.currentContext!, AppRoutes.zoomCallPage, // arguments: CallArguments(appointmentID, "111", "Patient", "40", "1", true, 1), - arguments: CallArguments(roomID, "123", "Patient", "40", "0", true, 1), + arguments: CallArguments(roomID, "123", "Patient", "40", "0", true, int.parse(callTypeID)), // arguments: CallArguments("SmallDailyStandup9875", "123", "Patient", "40", "0", false, int.parse(widget.incomingCallData!.appointmentNo!)), ); } -- 2.30.2