Skip to content

Commit

Permalink
Fixes #3041 - ElementCall unable to access media on ongoing CallKit s…
Browse files Browse the repository at this point in the history
…ession.
  • Loading branch information
stefanceriu committed Jul 22, 2024
1 parent 5cb44ee commit b135940
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions ElementX/Sources/Screens/CallScreen/View/CallScreen.swift
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

0 comments on commit b135940

Please sign in to comment.