working to open video stream from service

merge-requests/759/head
mosazaid 5 years ago
parent 78338ebc64
commit 7fed1c58f3

@ -40,6 +40,9 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<service android:name = ".Service.VideoStreamContainerService"/>
<!-- <!--
Don't delete the meta-data below. Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java This is used by the Flutter tool to generate GeneratedPluginRegistrant.java

@ -1,14 +1,17 @@
package com.hmg.hmgDr package com.hmg.hmgDr
import android.app.Activity import android.app.Activity
import android.content.ComponentName
import android.content.Intent import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle import android.os.Bundle
import android.os.IBinder
import android.util.Log import android.util.Log
import android.widget.Toast
import androidx.annotation.NonNull import androidx.annotation.NonNull
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import com.hmg.hmgDr.Model.GetSessionStatusModel import com.hmg.hmgDr.Model.GetSessionStatusModel
import com.hmg.hmgDr.Model.SessionStatusModel import com.hmg.hmgDr.Model.SessionStatusModel
import com.hmg.hmgDr.Service.VideoStreamContainerService
import com.hmg.hmgDr.ui.VideoCallResponseListener import com.hmg.hmgDr.ui.VideoCallResponseListener
import com.hmg.hmgDr.ui.fragment.VideoCallFragment import com.hmg.hmgDr.ui.fragment.VideoCallFragment
import io.flutter.embedding.android.FlutterFragmentActivity import io.flutter.embedding.android.FlutterFragmentActivity
@ -26,6 +29,10 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
private var call: MethodCall? = null private var call: MethodCall? = null
private val LAUNCH_VIDEO: Int = 1 private val LAUNCH_VIDEO: Int = 1
private var serviceIntent: Intent? = null
private var videoStreamService: VideoStreamContainerService? = null
private var bound = false
private var dialogFragment: VideoCallFragment? = null private var dialogFragment: VideoCallFragment? = null
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
@ -74,15 +81,24 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
} }
private fun openVideoCall(apiKey: String?, sessionId: String?, token: String?, appLang: String?, baseUrl: String?, sessionStatusModel: GetSessionStatusModel) { private fun openVideoCall(apiKey: String?, sessionId: String?, token: String?, appLang: String?, baseUrl: String?, sessionStatusModel: GetSessionStatusModel) {
if (dialogFragment == null) { val arguments = Bundle()
val arguments = Bundle() arguments.putString("apiKey", apiKey)
arguments.putString("apiKey", apiKey) arguments.putString("sessionId", sessionId)
arguments.putString("sessionId", sessionId) arguments.putString("token", token)
arguments.putString("token", token) arguments.putString("appLang", appLang)
arguments.putString("appLang", appLang) arguments.putString("baseUrl", baseUrl)
arguments.putString("baseUrl", baseUrl) arguments.putParcelable("sessionStatusModel", sessionStatusModel)
arguments.putParcelable("sessionStatusModel", sessionStatusModel)
// start service
serviceIntent = Intent(this@MainActivity, VideoStreamContainerService::class.java)
serviceIntent?.run {
putExtras(arguments)
startService(this)
}
VideoStreamContainerService.videoCallResponseListener = this
if (dialogFragment == null) {
val transaction = supportFragmentManager.beginTransaction() val transaction = supportFragmentManager.beginTransaction()
dialogFragment = VideoCallFragment.newInstance(arguments) dialogFragment = VideoCallFragment.newInstance(arguments)
dialogFragment?.let { dialogFragment?.let {
@ -93,8 +109,6 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
}else { }else {
it.show(transaction, "dialog") it.show(transaction, "dialog")
} }
} }
} else if (!dialogFragment!!.isVisible) { } else if (!dialogFragment!!.isVisible) {
val transaction = supportFragmentManager.beginTransaction() val transaction = supportFragmentManager.beginTransaction()
@ -102,7 +116,6 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
} }
} }
/* override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { /* override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
var asd = ""; var asd = "";
@ -175,4 +188,40 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
super.onBackPressed() super.onBackPressed()
} }
override fun onStart() {
super.onStart()
bindService()
}
override fun onStop() {
super.onStop()
unbindService()
}
private fun bindService() {
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE)
}
private fun unbindService() {
if (bound) {
gpsService.registerCallBack(null) // unregister
unbindService(serviceConnection)
bound = false
}
}
private val serviceConnection: ServiceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
val binder: VideoStreamContainerService.GPSBinder = service as GPSService.GPSBinder
gpsService = binder.getService()
bound = true
gpsService.registerCallBack(this@YourActivity) // register
}
override fun onServiceDisconnected(name: ComponentName?) {
bound = false
}
}
} }

@ -0,0 +1,30 @@
package com.hmg.hmgDr.Service
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.widget.Toast
import com.hmg.hmgDr.ui.VideoCallResponseListener
object VideoStreamContainerService : Service() {
// https://stackoverflow.com/questions/2463175/how-to-have-android-service-communicate-with-activity
var videoCallResponseListener: VideoCallResponseListener? = null
override fun onBind(intent: Intent?): IBinder? {
return null
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent != null){
}
Toast.makeText(this, "Service started by user.", Toast.LENGTH_LONG).show()
return START_STICKY
}
override fun onDestroy() {
super.onDestroy()
Toast.makeText(this, "Service destroyed by user.", Toast.LENGTH_LONG).show()
}
}

@ -464,9 +464,25 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
}, 4000) }, 4000)
} }
override fun onVideoDisabled(subscriberKit: SubscriberKit?, s: String?) {} override fun onVideoDisabled(subscriberKit: SubscriberKit?, s: String?) {
Log.d(VideoCallFragment.TAG, "onVideoDisabled: Error ($s)")
override fun onVideoEnabled(subscriberKit: SubscriberKit?, s: String?) {} // if (isCircle) {
// videoCallContainer.background = ContextCompat.getDrawable(requireContext(), R.drawable.circle_shape)
// mSubscriberViewContainer.background = ContextCompat.getDrawable(requireContext(), R.drawable.circle_shape)
// } else {
// videoCallContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.text_color))
// mSubscriberViewContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.remoteBackground))
// }
}
override fun onVideoEnabled(subscriberKit: SubscriberKit?, s: String?) {
Log.d(VideoCallFragment.TAG, "onVideoEnabled: Error ($s)")
// if (mSubscriber != null) {
// (mSubscriber!!.renderer as DynamicVideoRenderer).enableThumbnailCircle(isCircle)
// }
}
override fun onVideoDisableWarning(subscriberKit: SubscriberKit?) {} override fun onVideoDisableWarning(subscriberKit: SubscriberKit?) {}
@ -562,9 +578,8 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
mSubscriberViewContainer.background = ContextCompat.getDrawable(requireContext(), R.drawable.circle_shape) mSubscriberViewContainer.background = ContextCompat.getDrawable(requireContext(), R.drawable.circle_shape)
} else { } else {
videoCallContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.text_color)) videoCallContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.text_color))
mSubscriberViewContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.text_color)) mSubscriberViewContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.remoteBackground))
} }
} }
if (isCircle) { if (isCircle) {
@ -688,7 +703,15 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
isCameraClicked = !isCameraClicked isCameraClicked = !isCameraClicked
mPublisher!!.publishVideo = !isCameraClicked mPublisher!!.publishVideo = !isCameraClicked
val res = if (isCameraClicked) R.drawable.video_disabled else R.drawable.video_enabled val res = if (isCameraClicked) R.drawable.video_disabled else R.drawable.video_enabled
mCameraBtn!!.setImageResource(res) mCameraBtn.setImageResource(res)
// if (!isCameraClicked) {
// videoCallContainer.background = ContextCompat.getDrawable(requireContext(), R.drawable.circle_shape)
// mSubscriberViewContainer.background = ContextCompat.getDrawable(requireContext(), R.drawable.circle_shape)
// } else {
// videoCallContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.text_color))
// mSubscriberViewContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.remoteBackground))
// }
} }
} }

@ -16,62 +16,81 @@ import '../../locator.dart';
import '../../routes.dart'; import '../../routes.dart';
import 'NavigationService.dart'; import 'NavigationService.dart';
class VideoCallService extends BaseService{ class VideoCallService extends BaseService {
StartCallRes startCallRes; StartCallRes startCallRes;
PatiantInformtion patient; PatiantInformtion patient;
LiveCarePatientServices _liveCarePatientServices = locator<LiveCarePatientServices>(); LiveCarePatientServices _liveCarePatientServices =
locator<LiveCarePatientServices>();
openVideo(StartCallRes startModel,PatiantInformtion patientModel,VoidCallback onCallConnected, VoidCallback onCallDisconnected)async{ openVideo(StartCallRes startModel, PatiantInformtion patientModel,
VoidCallback onCallConnected, VoidCallback onCallDisconnected) async {
this.startCallRes = startModel; this.startCallRes = startModel;
this.patient = patientModel; this.patient = patientModel;
DoctorProfileModel doctorProfile = await getDoctorProfile(isGetProfile: true); DoctorProfileModel doctorProfile =
await getDoctorProfile(isGetProfile: true);
await VideoChannel.openVideoCallScreen( await VideoChannel.openVideoCallScreen(
kToken: startCallRes.openTokenID,//"T1==cGFydG5lcl9pZD00NzI0Nzk1NCZzaWc9NGIyZDljOTY3YjFiNWU1YzUzNzFmMjIyNjJmNmEzY2Y5NzZjOTdlYzpzZXNzaW9uX2lkPTFfTVg0ME56STBOemsxTkg1LU1UWXlNekEyTlRRMU9EVXhObjVrVFRoMFlVdFJXaXRYTWpadFZGZHFhSGxZVGpOdE1UVi1mZyZjcmVhdGVfdGltZT0xNjIzMDY1NDk1Jm5vbmNlPTAuMjM2Mjk0NTIwMTkyOTA4OTcmcm9sZT1wdWJsaXNoZXImZXhwaXJlX3RpbWU9MTYyNTY1NzQ5NCZpbml0aWFsX2xheW91dF9jbGFzc19saXN0PQ==", kToken:
kSessionId:startCallRes.openSessionID,//1_MX40NzI0Nzk1NH5-MTYyMzA2NTQ1ODUxNn5kTTh0YUtRWitXMjZtVFdqaHlYTjNtMTV-fg "T1==cGFydG5lcl9pZD00NzI0Nzk1NCZzaWc9NGIyZDljOTY3YjFiNWU1YzUzNzFmMjIyNjJmNmEzY2Y5NzZjOTdlYzpzZXNzaW9uX2lkPTFfTVg0ME56STBOemsxTkg1LU1UWXlNekEyTlRRMU9EVXhObjVrVFRoMFlVdFJXaXRYTWpadFZGZHFhSGxZVGpOdE1UVi1mZyZjcmVhdGVfdGltZT0xNjIzMDY1NDk1Jm5vbmNlPTAuMjM2Mjk0NTIwMTkyOTA4OTcmcm9sZT1wdWJsaXNoZXImZXhwaXJlX3RpbWU9MTYyNTY1NzQ5NCZpbml0aWFsX2xheW91dF9jbGFzc19saXN0PQ==",
kApiKey: '46209962',//'47247954' // startCallRes.openTokenID,
kSessionId:
"1_MX40NzI0Nzk1NH5-MTYyMzA2NTQ1ODUxNn5kTTh0YUtRWitXMjZtVFdqaHlYTjNtMTV-fg",
//startCallRes.openSessionID,
kApiKey: '47247954',//'46209962'
vcId: patient.vcId, vcId: patient.vcId,
patientName: patient.fullName ?? (patient.firstName != null ? "${patient.firstName} ${patient.lastName}" : "-"), patientName: patient.fullName ??
(patient.firstName != null
? "${patient.firstName} ${patient.lastName}"
: "-"),
tokenID: await sharedPref.getString(TOKEN), tokenID: await sharedPref.getString(TOKEN),
generalId: GENERAL_ID, generalId: GENERAL_ID,
doctorId: doctorProfile.doctorID, doctorId: doctorProfile.doctorID,
onFailure: (String error) { onFailure: (String error) {
DrAppToastMsg.showErrorToast(error); DrAppToastMsg.showErrorToast(error);
},onCallConnected: onCallConnected, },
onCallConnected: onCallConnected,
onCallEnd: () { onCallEnd: () {
WidgetsBinding.instance.addPostFrameCallback((_) async { WidgetsBinding.instance.addPostFrameCallback((_) async {
GifLoaderDialogUtils.showMyDialog(locator<NavigationService>().navigatorKey.currentContext); GifLoaderDialogUtils.showMyDialog(
endCall(patient.vcId, false,).then((value) { locator<NavigationService>().navigatorKey.currentContext);
GifLoaderDialogUtils.hideDialog(locator<NavigationService>().navigatorKey.currentContext); endCall(
if (hasError) { patient.vcId,
DrAppToastMsg.showErrorToast(error); false,
}else ).then((value) {
locator<NavigationService>().navigateTo(PATIENTS_END_Call,arguments: { GifLoaderDialogUtils.hideDialog(
"patient": patient, locator<NavigationService>().navigatorKey.currentContext);
}); if (hasError) {
DrAppToastMsg.showErrorToast(error);
}); } else
locator<NavigationService>()
.navigateTo(PATIENTS_END_Call, arguments: {
"patient": patient,
});
});
}); });
}, },
onCallNotRespond: (SessionStatusModel sessionStatusModel) { onCallNotRespond: (SessionStatusModel sessionStatusModel) {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
GifLoaderDialogUtils.showMyDialog(locator<NavigationService>().navigatorKey.currentContext); GifLoaderDialogUtils.showMyDialog(
endCall(patient.vcId, sessionStatusModel.sessionStatus == 3,).then((value) { locator<NavigationService>().navigatorKey.currentContext);
GifLoaderDialogUtils.hideDialog(locator<NavigationService>().navigatorKey.currentContext); endCall(
patient.vcId,
sessionStatusModel.sessionStatus == 3,
).then((value) {
GifLoaderDialogUtils.hideDialog(
locator<NavigationService>().navigatorKey.currentContext);
if (hasError) { if (hasError) {
DrAppToastMsg.showErrorToast(error); DrAppToastMsg.showErrorToast(error);
} else { } else {
locator<NavigationService>().navigateTo(PATIENTS_END_Call,arguments: { locator<NavigationService>()
.navigateTo(PATIENTS_END_Call, arguments: {
"patient": patient, "patient": patient,
}); });
} }
}); });
});
});
}); });
} }
Future endCall(int vCID, bool isPatient) async { Future endCall(int vCID, bool isPatient) async {
hasError = false; hasError = false;
await getDoctorProfile(isGetProfile: true); await getDoctorProfile(isGetProfile: true);
@ -85,5 +104,4 @@ class VideoCallService extends BaseService{
error = _liveCarePatientServices.error; error = _liveCarePatientServices.error;
} }
} }
} }

@ -255,7 +255,7 @@ class AuthenticationViewModel extends BaseViewModel {
/// add  token to shared preferences in case of send activation code is success /// add  token to shared preferences in case of send activation code is success
setDataAfterSendActivationSuccess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { setDataAfterSendActivationSuccess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) {
print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode); print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode);
// DrAppToastMsg.showSuccesToast("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode); DrAppToastMsg.showSuccesToast("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode);
sharedPref.setString(VIDA_AUTH_TOKEN_ID, sharedPref.setString(VIDA_AUTH_TOKEN_ID,
sendActivationCodeForDoctorAppResponseModel.vidaAuthTokenID); sendActivationCodeForDoctorAppResponseModel.vidaAuthTokenID);
sharedPref.setString(VIDA_REFRESH_TOKEN_ID, sharedPref.setString(VIDA_REFRESH_TOKEN_ID,

@ -337,8 +337,12 @@ class _PatientProfileScreenState extends State<PatientProfileScreen>
// builder: (BuildContext context) => // builder: (BuildContext context) =>
// EndCallScreen(patient:patient))); // EndCallScreen(patient:patient)));
// TODO MOSA REMOVE THIS
AppPermissionsUtils.requestVideoCallPermission(context: context,onTapGrant: (){
locator<VideoCallService>().openVideo(model.startCallRes, patient, callConnected, callDisconnected);
});
if(isCallFinished) { /* if(isCallFinished) {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) => EndCallScreen(patient:patient))); builder: (BuildContext context) => EndCallScreen(patient:patient)));
} else { } else {
@ -357,11 +361,8 @@ class _PatientProfileScreenState extends State<PatientProfileScreen>
AppPermissionsUtils.requestVideoCallPermission(context: context,onTapGrant: (){ AppPermissionsUtils.requestVideoCallPermission(context: context,onTapGrant: (){
locator<VideoCallService>().openVideo(model.startCallRes, patient, callConnected, callDisconnected); locator<VideoCallService>().openVideo(model.startCallRes, patient, callConnected, callDisconnected);
}); });
} }
} }*/
}, },
), ),

Loading…
Cancel
Save