Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElementCall unable to access media on ongoing CallKit session. #3077

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private struct WebView: UIViewRepresentable {
webView = WKWebView(frame: .zero, configuration: configuration)
webView.uiDelegate = self
webView.navigationDelegate = self
webView.isInspectable = true

// https://stackoverflow.com/a/77963877/730924
webView.allowsLinkPreview = true
Expand Down
20 changes: 20 additions & 0 deletions ElementX/Sources/Services/ElementCall/ElementCallService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
if let incomingCallID {
// Fixes broken videos on EC web when a CallKit session is established.
//
// Reporting an ongoing call through `reportNewIncomingCall` + `CXAnswerCallAction`
// or `reportOutgoingCall:connectedAt:` will give exclusive access for media to the
// ongoing process, which is different than the WKWebKit is running on, making EC
// unable to aquire media streams.
// Reporting the call as ended imediately after answering it works around that
// as EC gets access to media again and EX builds the right UI in `setupCallSession`
//
// https://github.com/element-hq/element-x-ios/issues/3041
// https://forums.developer.apple.com/forums/thread/685268
// https://stackoverflow.com/questions/71483732/webrtc-running-from-wkwebview-avaudiosession-development-roadblock
provider.reportCall(with: incomingCallID.callKitID, endedAt: nil, reason: .answeredElsewhere)

actionsSubject.send(.startCall(roomID: incomingCallID.roomID))
endUnansweredCallTask?.cancel()
} else {
Expand All @@ -210,6 +224,12 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
}

func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
#if targetEnvironment(simulator)
// This gets called for no reason on simulators, where CallKit
// isn't even supported. Ignore
return
#endif

if let ongoingCallID {
actionsSubject.send(.endCall(roomID: ongoingCallID.roomID))
}
Expand Down
Loading