Reputation: 37
I have a problem when I try to pass my sip service in the background.
I'm using the flutter_background_service: ^5.0.10 plugin, I've followed the documentation scrupulously for the implementation of the service. However, I have the impression that my sip listener is garbage collected by flutter.
Here's the code for my service. I've created a service exit condition and listener with callbacks to trigger functions.
void onStart(ServiceInstance service) async {
if (service is AndroidServiceInstance) {
service.setForegroundNotificationInfo(
title: "SmartDiese",
content: "Service SIP actif",
);
service.setAsForegroundService();
}
final sipService = SipService();
SharedPreferences preferences = await SharedPreferences.getInstance();
String? userString = preferences.getString('user');
if (userString != null) {
Utilisateur user =
Utilisateur.fromJson(jsonDecode(userString) as Map<String, dynamic>);
UaSettings settings =
getSettings(user: user, helper: sipService.helper, listener: sipService.listener);
sipService.helper.start(settings);
sipService.helper.listeners.clear();
sipService.helper.addSipUaHelperListener(sipService.listener);
}
service.on('stop').listen((event) {
service.stopSelf();
});
service.on('call_service').listen(
(event) {
String? command = event?['command'];
if (command == "get_current_call_state") {
CallState? state = (sipService.listener as SipListener).getCallState();
service.invoke("current_call_state", {
"call": state == null ? "empty" : state.state.toString(),
});
} else if (command == "get_identity") {
Call? call = (sipService.listener as SipListener).getCall();
service.invoke("call_service", {
"command": "current_call_identity",
"call": call == null ? "empty" : call.remote_identity.toString(),
});
}
},
);
}
When I launch the application, I get the notification that my service has been launched. Calls to services also work correctly.
Here is the code for my sip listener:
class SipListener implements SipUaHelperListener {
Call? call;
CallState? state;
Call? getCall() {
return call;
}
CallState? getCallState() {
return state;
}
@override
void registrationStateChanged(RegistrationState state) {}
@override
void callStateChanged(Call tmpCall, CallState tmpState) async {
call = tmpCall;
state = tmpState;
}
@override
void onNewMessage(SIPMessageRequest msg) {}
@override
void transportStateChanged(TransportState state) {}
@override
void onNewNotify(Notify ntf) {}
@override
void onNewReinvite(ReInvite event) {}
}
My problem is that the callStateChanged method is never triggered when an incoming call arrives on the application.
Thank you in advance for your help,
Upvotes: 0
Views: 30