video call improvement.

merge-requests/545/head
Sikander Saleem 4 years ago
parent 998614cfe7
commit 4518a26ff1

@ -2,14 +2,33 @@ package io.flutter.plugins.firebasemessaging;
import android.content.Intent;
import java.util.concurrent.TimeUnit;
import com.google.firebase.messaging.RemoteMessage;
//public class CustomFlutterFirebaseMessagingService extends FlutterFirebaseMessagingService {
// @Override
// public void onMessageReceived(RemoteMessage remoteMessage) {
// if (remoteMessage.getData().containsKey("is_call")) {
// Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
// startActivity(intent);
// super.onMessageReceived(remoteMessage);
// } else
// super.onMessageReceived(remoteMessage);
// }
//}
public class CustomFlutterFirebaseMessagingService extends FlutterFirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData().containsKey("is_call")) {
Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
try {
TimeUnit.SECONDS.sleep(5);
} catch (Exception e) {
}
super.onMessageReceived(remoteMessage);
} else
super.onMessageReceived(remoteMessage);

@ -13,6 +13,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
@ -29,7 +30,7 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<!-- Detect Reboot Permission -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<queries>
@ -41,6 +42,8 @@
android:name=".Application"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"
android:showOnLockScreen="true"
android:screenOrientation="sensorPortrait"
android:label="Dr. Alhabib">
<activity
android:name=".MainActivity"

@ -1,6 +1,8 @@
package com.ejada.hmg
import android.os.Bundle
import android.util.Log
import android.os.Build
import android.view.WindowManager
import androidx.annotation.NonNull;
import com.ejada.hmg.utils.*
import io.flutter.embedding.android.FlutterFragmentActivity
@ -12,6 +14,9 @@ class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
// Create Flutter Platform Bridge
this.window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON)
PlatformBridge(flutterEngine, this).create()
OpenTokPlatformBridge(flutterEngine, this).create()

@ -1,6 +1,14 @@
package com.ejada.hmg.utils
import android.content.Context
import android.content.Intent
import android.content.Intent.getIntent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.widget.Toast
import androidx.core.app.ActivityCompat.startActivityForResult
import android.net.wifi.WifiManager
import android.util.Log
import com.ejada.hmg.MainActivity
@ -24,48 +32,56 @@ class PlatformBridge(private var flutterEngine: FlutterEngine, private var mainA
private const val ENABLE_WIFI_IF_NOT = "enableWifiIfNot"
private const val REGISTER_HMG_GEOFENCES = "registerHmgGeofences"
private const val UN_REGISTER_HMG_GEOFENCES = "unRegisterHmgGeofences"
private const val IS_DRAW_OVER_APPS_PERMISSION_ALLOWED = "isDrawOverAppsPermissionAllowed"
private const val ASK_DRAW_OVER_APPS_PERMISSION = "askDrawOverAppsPermission"
private const val GET_INTENT = "getIntent"
}
fun create(){
fun create() {
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
HMGUtils.setPlatformChannel(channel)
channel.setMethodCallHandler { methodCall: MethodCall, result: MethodChannel.Result ->
if (methodCall.method == HMG_INTERNET_WIFI_CONNECT_METHOD) {
connectHMGInternetWifi(methodCall,result)
}else if (methodCall.method == HMG_GUEST_WIFI_CONNECT_METHOD) {
connectHMGGuestWifi(methodCall,result)
}else if (methodCall.method == ENABLE_WIFI_IF_NOT) {
enableWifiIfNot(methodCall,result)
}else if (methodCall.method == REGISTER_HMG_GEOFENCES) {
registerHmgGeofences(methodCall,result)
}else if (methodCall.method == UN_REGISTER_HMG_GEOFENCES) {
unRegisterHmgGeofences(methodCall,result)
}else{
connectHMGInternetWifi(methodCall, result)
} else if (methodCall.method == HMG_GUEST_WIFI_CONNECT_METHOD) {
connectHMGGuestWifi(methodCall, result)
} else if (methodCall.method == ENABLE_WIFI_IF_NOT) {
enableWifiIfNot(methodCall, result)
} else if (methodCall.method == REGISTER_HMG_GEOFENCES) {
registerHmgGeofences(methodCall, result)
} else if (methodCall.method == UN_REGISTER_HMG_GEOFENCES) {
unRegisterHmgGeofences(methodCall, result)
} else if (methodCall.method == IS_DRAW_OVER_APPS_PERMISSION_ALLOWED) {
isDrawOverAppsPermissionAllowed(methodCall, result)
} else if (methodCall.method == ASK_DRAW_OVER_APPS_PERMISSION) {
askDrawOverAppsPermission(methodCall, result)
} else if (methodCall.method == GET_INTENT) {
getIntentData(methodCall, result)
} else {
result.notImplemented()
}
}
val res = channel.invokeMethod("localizedValue","errorConnectingHmgNetwork")
val res = channel.invokeMethod("localizedValue", "errorConnectingHmgNetwork")
}
private fun connectHMGInternetWifi(methodCall: MethodCall, result: MethodChannel.Result){
private fun connectHMGInternetWifi(methodCall: MethodCall, result: MethodChannel.Result) {
(methodCall.arguments as ArrayList<*>).let {
require(it.size > 0 && (it[0] is String),lazyMessage = {
require(it.size > 0 && (it[0] is String), lazyMessage = {
"Missing or invalid arguments (Must have one argument 'String at 0'"
})
val patientId = it[0].toString()
HMG_Internet(mainActivity)
.connectToHMGGuestNetwork(patientId){ status, message ->
.connectToHMGGuestNetwork(patientId) { status, message ->
mainActivity.runOnUiThread {
result.success(if(status) 1 else 0)
result.success(if (status) 1 else 0)
HMGUtils.popFlutterText(mainActivity, message)
Log.v(this.javaClass.simpleName, "$status | $message")
@ -76,10 +92,10 @@ class PlatformBridge(private var flutterEngine: FlutterEngine, private var mainA
}
private fun connectHMGGuestWifi(methodCall: MethodCall, result: MethodChannel.Result){
private fun connectHMGGuestWifi(methodCall: MethodCall, result: MethodChannel.Result) {
HMG_Guest(mainActivity).connectToHMGGuestNetwork { status, message ->
mainActivity.runOnUiThread {
result.success(if(status) 1 else 0)
result.success(if (status) 1 else 0)
HMGUtils.popFlutterText(mainActivity, message)
Log.v(this.javaClass.simpleName, "$status | $message")
@ -89,38 +105,76 @@ class PlatformBridge(private var flutterEngine: FlutterEngine, private var mainA
private fun enableWifiIfNot(methodCall: MethodCall, result: MethodChannel.Result) {
val wm = mainActivity.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager?
if (wm != null){
if (wm != null) {
if (!wm.isWifiEnabled)
wm.isWifiEnabled = true
result.success(true)
}else
result.error("101","Error while opening wifi, Please try to open wifi yourself and try again","'WifiManager' service failed");
} else
result.error("101", "Error while opening wifi, Please try to open wifi yourself and try again", "'WifiManager' service failed");
}
private fun registerHmgGeofences(methodCall: MethodCall, result: MethodChannel.Result) {
channel.invokeMethod("getGeoZones",null, object : MethodChannel.Result{
channel.invokeMethod("getGeoZones", null, object : MethodChannel.Result {
override fun success(result: Any?) {
if(result is String) {
if (result is String) {
val geoZones = GeoZoneModel().listFrom(result)
HMG_Geofence.shared(mainActivity).register(){ s, e -> }
HMG_Geofence.shared(mainActivity).register() { s, e -> }
}
}
override fun error(errorCode: String?, errorMessage: String?, errorDetails: Any?) { }
override fun notImplemented() { }
override fun error(errorCode: String?, errorMessage: String?, errorDetails: Any?) {}
override fun notImplemented() {}
})
}
private fun unRegisterHmgGeofences(methodCall: MethodCall, result: MethodChannel.Result) {
HMG_Geofence.shared(mainActivity).unRegisterAll { status, exception ->
if(status)
if (status)
result.success(true)
else
result.error("101", exception?.localizedMessage, exception);
}
}
private fun isDrawOverAppsPermissionAllowed(methodCall: MethodCall, result: MethodChannel.Result) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (
Settings.canDrawOverlays(mainActivity)
) {
result.success(true)
} else {
result.success(false)
}
} else {
result.success(false)
}
}
private fun askDrawOverAppsPermission(methodCall: MethodCall, result: MethodChannel.Result) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
val uri = Uri.parse("package:" + mainActivity.getPackageName())
intent.setData(uri)
startActivityForResult(mainActivity, intent, 102, null)
result.success(true)
} else {
result.success(false)
}
}
private fun getIntentData(methodCall: MethodCall, result: MethodChannel.Result) {
val bundle: Bundle? = getIntent("").extras
if (bundle != null) {
val message = bundle.getString("notification") // 1
System.out.println("BundleExtra:" + message)
Toast.makeText(this.mainActivity, message + "", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this.mainActivity, "Bundle Null", Toast.LENGTH_SHORT).show();
}
result.success(true);
}
}

@ -9,6 +9,7 @@ import 'package:diplomaticquarterapp/routes.dart';
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/PlatformBridge.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
@ -21,6 +22,7 @@ import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'book_reminder_page.dart';
@ -240,6 +242,44 @@ class _BookConfirmState extends State<BookConfirm> {
);
}
Future<bool> askVideoCallPermission() async {
if (!(await Permission.camera.request().isGranted) || !(await Permission.microphone.request().isGranted)) {
return false;
}
if (!(await PlatformBridge.shared().isDrawOverAppsPermissionAllowed())) {
await drawOverAppsMessageDialog(context);
return false;
}
return true;
}
Future drawOverAppsMessageDialog(BuildContext context) async {
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text("Please select 'Diplomatic Quarter' from the list and allow draw over app permission to use live care."),
contentPadding: EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 0.0),
actions: [
FlatButton(
child: Text("Cancel"),
onPressed: () {
Navigator.pop(context);
},
),
FlatButton(
child: Text("Go to Settings"),
onPressed: () async {
await PlatformBridge.shared().askDrawOverAppsPermission();
Navigator.pop(context);
},
)
],
);
},
);
}
cancelAppointment(DoctorList docObject, AppoitmentAllHistoryResultList appo, BuildContext context) {
ConfirmDialog.closeAlertDialog(context);
GifLoaderDialogUtils.showMyDialog(context);

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:diplomaticquarterapp/models/LiveCare/room_model.dart';
import 'package:diplomaticquarterapp/pages/conference/conference_button_bar.dart';
import 'package:diplomaticquarterapp/pages/conference/conference_room.dart';
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
import 'package:diplomaticquarterapp/pages/conference/draggable_publisher.dart';
import 'package:diplomaticquarterapp/pages/conference/participant_widget.dart';
import 'package:diplomaticquarterapp/pages/conference/widgets/noise_box.dart';
@ -152,6 +153,7 @@ class _ConferencePageState extends State<ConferencePage> {
Future<void> _onHangup() async {
print('onHangup');
await _conferenceRoom.disconnect();
LandingPage.isOpenCallPage = false;
Navigator.of(context).pop();
}

@ -204,10 +204,15 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
AppGlobal.context = context;
if (state == AppLifecycleState.resumed) {
if (LandingPage.isOpenCallPage) {
if (Platform.isAndroid) {
return;
}
if (!isPageNavigated) {
isPageNavigated = true;
Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: LandingPage.incomingCallData))).then((value) {
isPageNavigated = false;
Future.delayed(Duration(seconds: 5), () {
isPageNavigated = false;
});
});
}
}
@ -329,12 +334,17 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
Map<String, dynamic> myMap = new Map<String, dynamic>.from(message['data']);
print(myMap);
if (LandingPage.isOpenCallPage) {
return;
}
LandingPage.isOpenCallPage = true;
LandingPage.incomingCallData = IncomingCallData.fromJson(myMap);
if (!isPageNavigated) {
isPageNavigated = true;
Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: LandingPage.incomingCallData))).then((value) {
isPageNavigated = false;
Future.delayed(Duration(seconds: 5), () {
isPageNavigated = false;
});
});
}
} else {

@ -3,6 +3,7 @@ import 'package:diplomaticquarterapp/models/LiveCare/room_model.dart';
import 'package:diplomaticquarterapp/pages/conference/conference_page.dart';
import 'package:diplomaticquarterapp/pages/conference/web_rtc/call_home_page.dart';
import 'package:diplomaticquarterapp/pages/conference/widgets/platform_exception_alert_dialog.dart';
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
@ -135,6 +136,7 @@ class _IncomingCallState extends State<IncomingCall> with SingleTickerProviderSt
Container(
child: RawMaterialButton(
onPressed: () {
LandingPage.isOpenCallPage = false;
backToHome();
},
elevation: 2.0,

@ -1,4 +1,3 @@
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/localized_values.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
@ -89,6 +88,9 @@ class PlatformBridge {
static const show_loading_method = "loading";
static const register_Hmg_Geofences = "registerHmgGeofences";
static const un_register_Hmg_Geofences = "unRegisterHmgGeofences";
static const IS_DRAW_OVER_APPS_PERMISSION_ALLOWED = "isDrawOverAppsPermissionAllowed";
static const ASK_DRAW_OVER_APPS_PERMISSION = "askDrawOverAppsPermission";
static const GET_INTENT = "getIntent";
Future<Object> connectHMGInternetWifi(String patientId) {
try {
@ -142,4 +144,19 @@ class PlatformBridge {
void unRegisterHmgGeofences() async {
var result = await platform.invokeMethod(un_register_Hmg_Geofences);
}
Future<bool> isDrawOverAppsPermissionAllowed() async {
var result = await platform.invokeMethod(IS_DRAW_OVER_APPS_PERMISSION_ALLOWED);
return result as bool;
}
Future<bool> askDrawOverAppsPermission() async {
var result = await platform.invokeMethod(ASK_DRAW_OVER_APPS_PERMISSION);
return result as bool;
}
Future<bool> getIntentData() async {
var result = await platform.invokeMethod(GET_INTENT);
return result as bool;
}
}

Loading…
Cancel
Save