FCM Background Message Handler and isolates

280 views
Skip to first unread message

gavin...@gmail.com

unread,
Nov 3, 2020, 10:23:26 AM11/3/20
to Flutter Development (flutter-dev)

Hi all,

I know FCM background messages run in their own isolate. I have them all working, but I'm using CallKeep and it also then runs in its own isolate, so I can share anything across into it when state changes.

I've spawned an isolate from my CallKeep class and can reach it from the other places I need to and am sending data to it, but it doesn't like complicated data.

What are others doing with this type of scenario?

I'm using IsolateNameServer.lookupPortByName("CallKeepIsolate").send() and that's working OK with basic types, but I'm trying to do:

@override
void callStateChanged(Call call, CallState callState) {
_logger.d("callStateChanged: ${callState.state}");
_logger.d("call direction is: ${call.direction}");
_logger.d("call state is: ${call.state}");

Get.find<ActiveCallController>().activeCall = call;
_logger.d("Sending call to CallKeepIsolate");
IsolateNameServer.lookupPortByName("CallKeepIsolate").send(call);

//if (callState.state == CallStateEnum.CALL_INITIATION) {
if (callState.state == CallStateEnum.CALL_INITIATION &&
outboundCall.value) {
_logger.d("Going to /callscreen with argument: $call");
Get.toNamed("/callscreen", arguments: call);
}
}


So this fails IsolateNameServer.lookupPortByName("CallKeepIsolate").send(call);


I/flutter (11233): │ #0 CallController.callStateChanged (package:SureVoIPTalk/src/controller/call.dart:239:13) I/flutter (11233): │ #1 SIPUAHelper._notifyCallStateListeners.<anonymous closure> (package:sip_ua/src/sip_ua_helper.dart:348:16) I/flutter (11233): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ I/flutter (11233): │ 15:13:05.143 (+0:00:05.827269) I/flutter (11233): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ I/flutter (11233): │ 🐛 Sending call to CallKeepIsolate I/flutter (11233): └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── I/flutter (11233): [38;5;196m[2020-11-03 15:13:05.143] Level.error event_manager.dart:110 ::: Invalid argument(s): Illegal argument in isolate message : (object is a closure - Function '_receiveRequest@1671109630':.) [0m I/flutter (11233): [38;5;196m#0 _SendPortImpl._sendInternal (dart:isolate-patch/isolate_patch.dart:219:70) I/flutter (11233): #1 _SendPortImpl.send (dart:isolate-patch/isolate_patch.dart:203:5)

So I can't share the current phone call state across to another isolate as https://pub.dev/packages/callkeep runs separate memory from what's in my background message handler.

Does my question make sense? When the app is in the foreground, all is OK and I don't need the separate isolate.

Thanks,
Gavin.

gavin...@gmail.com

unread,
Nov 3, 2020, 10:27:59 AM11/3/20
to Flutter Development (flutter-dev)
Sorry, that should say "so I can not share anything across into it when state changes."

gavin...@gmail.com

unread,
Nov 3, 2020, 12:27:18 PM11/3/20
to Flutter Development (flutter-dev)
Sorted. I've switched round where I'm sending messages to, so sending simple data types to where the callstate lives and controlling there. Needed a walk and then it hit me.
Reply all
Reply to author
Forward
0 new messages