ConnectyCube / connectycube-flutter-call-kit

A Flutter plugin for displaying call screen when the app in the background or terminated.
https://developers.connectycube.com/flutter
Apache License 2.0
55 stars 75 forks source link

Connectycube - flutter What's wrong with my code #89

Closed alito0697 closed 5 months ago

alito0697 commented 1 year ago

` videocaller()async{ Uuid uuid = Uuid(); SharedPreferences prefs = await SharedPreferences.getInstance(); dynamic username = prefs.getString("username"); CallEvent callEvent = CallEvent(sessionId: uuid.v4() ,callType: 0, callerId: 2, callerName: username, opponentsIds:{1234});

Future _onCallAccepted(CallEvent callEvent) async { _joinMeetingVideo(); }

Future _onCallRejected(callEvent) async {

} Future onCallRejectedWhenTerminated(CallEvent callEvent) async { print("reject call"); } Future onCallAcceptedWhenTerminated(CallEvent callEvent) async { _joinMeetingVideo(); } ConnectycubeFlutterCallKit.onCallRejectedWhenTerminated = onCallRejectedWhenTerminated; ConnectycubeFlutterCallKit.onCallAcceptedWhenTerminated = onCallAcceptedWhenTerminated; ConnectycubeFlutterCallKit.instance.init( onCallAccepted: _onCallAccepted, onCallRejected: _onCallRejected, ); ConnectycubeFlutterCallKit.showCallNotification(callEvent); ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: true); }`

accept button launches the app when the app is terminated instead of executing the method _joinMeetingVideo()

TatankaConCube commented 1 year ago

it is expected behavior for this plugin, the callback onCallAcceptedWhenTerminated will be called if the app is killed or is in the background, and then launched the app. If you found another behavior, please describe how we can reproduce it on our side and share the logs related to this issue. Also, you can try our P2P Calls sample where this plugin works well.

alito0697 commented 1 year ago

So i can't execute joinmeeting() method when the app is terminated ?? How can i do that ??

TatankaConCube commented 1 year ago

have you seen our example? we use the callback onCallRejectedWhenTerminated there which works well in our example. the method onCallRejectedWhenTerminated works in the same way as onCallAcceptedWhenTerminated inside the plugin and if you did it in the same way as in our example the callback onCallAcceptedWhenTerminated should work for you

alito0697 commented 1 year ago

please could you provide a code example or at least try to correct the issue in my code

TatankaConCube commented 1 year ago

some recommendations:

alito0697 commented 1 year ago

W/ConnectycubeFlutterBgPerformingService( 8370): A background message could not be handled in Dart as no onBackgroundMessage handler has been registered

TatankaConCube commented 1 year ago

according to the error, it looks like you haven't set onCallRejectedWhenTerminated or onCallAcceptedWhenTerminated before

alito0697 commented 1 year ago

I did as you see above but is it in the wrong place ?

TatankaConCube commented 1 year ago

could you please format your code? now is not understandable where ends the function videocaller and where it is placed

alito0697 commented 1 year ago

sorry it's little bit too long

` videocaller()async{

    Uuid uuid = Uuid();

    SharedPreferences prefs = await SharedPreferences.getInstance();

    dynamic username = prefs.getString("username");

    CallEvent callEvent = CallEvent(sessionId: uuid.v4() ,callType: 0, callerId: 2, callerName: username, opponentsIds:{1234});

Future _onCallAccepted(CallEvent callEvent) async { _joinMeetingVideo(); }

Future _onCallRejected(callEvent) async {

} Future onCallRejectedWhenTerminated(CallEvent callEvent) async { print("reject call"); } Future onCallAcceptedWhenTerminated(CallEvent callEvent) async { _joinMeetingVideo(); } ConnectycubeFlutterCallKit.onCallRejectedWhenTerminated = onCallRejectedWhenTerminated; ConnectycubeFlutterCallKit.onCallAcceptedWhenTerminated = onCallAcceptedWhenTerminated; ConnectycubeFlutterCallKit.instance.init( onCallAccepted: _onCallAccepted, onCallRejected: _onCallRejected, ); ConnectycubeFlutterCallKit.showCallNotification(callEvent); ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: true); }

onMessage() { var i =0; FirebaseMessaging.onMessage.listen((RemoteMessage message)async { RemoteNotification? notification = message.notification; var filter = message.data; var j = i++; if(filter["type"] == "message"){

AwesomeNotifications().createNotification(
content: NotificationContent(
  autoDismissible: true,
  wakeUpScreen: true,
    id: j,
    channelKey: 'basic_channel',
    title: "Hedylogos Call",
    body: notification?.body
));

} if(filter["type"] == "call"){ caller(); } if(filter["type"] == "videocall"){ videocaller();

} } ); }

Future main() async { var widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); // await BackgroundFetch.configure(BackgroundFetchConfig( // minimumFetchInterval: 0, // stopOnTerminate: false, // startOnBoot: true, // enableHeadless: true, // requiresBatteryNotLow: false, // requiresCharging: false, // requiresStorageNotLow: false, // requiresDeviceIdle: false, // ), _backgroundFetch // ).then((value) => print("working")).catchError((e){print(e);});

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.

// BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask);

AwesomeNotifications().initialize( // set the icon to null if you want to use the default app icon "", //'resource://drawable/res_app_icon', [ NotificationChannel( playSound: true, icon: null, channelGroupKey: 'basic_channel_group', channelKey: 'basic_channel', channelName: 'Basic notifications', channelDescription: 'Notification channel for basic tests', defaultColor: Color(0xFF9D50DD), ledColor: Colors.white) ], // Channel groups are only visual and are not required channelGroups: [ NotificationChannelGroup( channelGroupKey: 'basic_channel_group', channelGroupName: 'Basic group') ], debug: true);

FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

FirebaseMessaging _fcm = FirebaseMessaging.instance; permi(_fcm); checkprm(_fcm); FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); runApp(const MyApp()); }`

TatankaConCube commented 1 year ago

please read the markdown documentation and format it, use the Preview tab to see how your message will look after sending it

alito0697 commented 1 year ago

@TatankaConCube

final CallbackHandle userHandle = PluginUtilities.getCallbackHandle(handler)!;

I'm getting an error at this line of code in connectycube_flutter_callkit.dart file which is Null check operator used on a null value

alito0697 commented 1 year ago

can you at least help to change the code of the plugin to execute a specific method while the app is in the background or in terminated mode

TatankaConCube commented 1 year ago

@alito0697 the annotation @pragma('vm:entry-point') for your handlers may help you to resolve your issue, please try to mark your handlers with this annotation

TatankaConCube commented 5 months ago

no activity for a long time, closing