Handle notifications properly when a call is happening. (#3276)

This commit is contained in:
Doug
2024-09-13 15:50:29 +01:00
committed by GitHub
parent ce83aec760
commit 93daaf554f
6 changed files with 52 additions and 12 deletions
@@ -128,6 +128,7 @@ private struct CallView: UIViewRepresentable {
contentViewController: pictureInPictureViewController))
pictureInPictureController.delegate = self
self.pictureInPictureController = pictureInPictureController
viewModelContext.send(viewAction: .pictureInPictureIsAvailable(pictureInPictureController))
}
}
@@ -222,6 +223,18 @@ private struct CallView: UIViewRepresentable {
}
}
nonisolated func pictureInPictureControllerDidStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
Task { @MainActor in
// Double check that the controller is definitely showing a page that supports picture in picture.
// This is necessary as it doesn't get checked when backgrounding the app or tapping a notification.
guard case .success(true) = await webViewCanEnterPictureInPicture() else {
MXLog.error("Picture in picture started on a webpage that doesn't support it. Ending the call.")
viewModelContext?.send(viewAction: .endCall)
return
}
}
}
nonisolated func pictureInPictureControllerWillStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
Task { await viewModelContext?.send(viewAction: .pictureInPictureWillStop) }
}