提问人:Vinayak Amirtharaj 提问时间:11/14/2023 最后编辑:Vinayak Amirtharaj 更新时间:11/17/2023 访问量:30
Flutter WebRTC:如何在应用后台执行过程中维护 WebRTC 调用?
Flutter WebRTC: How to Maintain WebRTC Call During App Background Execution?
问:
我正在开发一个 Flutter 应用程序,该应用程序集成了用于音频/视频通话的 WebRTC。当应用程序在前台时,WebRTC 调用运行良好,但是当应用程序进入后台时,我面临着维护呼叫的挑战,因为操作系统终止了应用程序内的操作并终止了 voip 实例
即使应用程序进入后台或终止状态,我如何使其工作?
示例代码:
class VoipApp with WidgetsBindingObserver implements WebRTCDelegate {
bool background = false;
final BuildContext context;
late final VoIP voIP;
bool _canHandleNewCall = true;
VoipApp(this.context) {
voIP = VoIP(locator<Client>(), this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState? state) {
background = (state == AppLifecycleState.detached ||
state == AppLifecycleState.paused);
}
@override
bool get canHandleNewCall => _canHandleNewCall;
@override
Future<webrtc_impl.RTCPeerConnection> createPeerConnection(
Map<String, dynamic> configuration,
[Map<String, dynamic> constraints = const {}]) {
return webrtc_impl.createPeerConnection(configuration, constraints);
}
@override
webrtc_impl.VideoRenderer createRenderer() {
return webrtc_impl.RTCVideoRenderer();
}
@override
Future<void> handleCallEnded(CallSession session) async {
_canHandleNewCall = true;
}
@override
Future<void> handleGroupCallEnded(GroupCall groupCall) async {
throw UnimplementedError();
}
@override
Future<void> handleMissedCall(CallSession session) async {
Logs().i("MISSED CALL");
}
@override
Future<void> handleNewCall(CallSession session) async {
_canHandleNewCall = true;
switch (session.direction) {
case CallDirection.kIncoming:
Logs().i("[VOIP] INCOMING CALL");
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => CallScreen(
callSession: session,
),
),
);
break;
case CallDirection.kOutgoing:
Logs().i("[VOIP] OUTGOING CALL");
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => CallScreen(
callSession: session,
),
),
);
break;
}
}
@override
Future<void> handleNewGroupCall(GroupCall groupCall) {
throw UnimplementedError();
}
@override
bool get isWeb => kIsWeb;
@override
webrtc_interface.MediaDevices get mediaDevices =>
webrtc_impl.navigator.mediaDevices;
@override
Future<void> playRingtone() async {
}
@override
Future<void> stopRingtone() async {}
}
答: 暂无答案
评论