Skip to content

Commit d9a8b62

Browse files
authored
[Enhancement]Allow configuring CallKit supported call types (#420)
1 parent 63cfc36 commit d9a8b62

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

55
# Upcoming
66

7-
### 🔄 Changed
7+
### ✅ Added
8+
- In `CallKitService` you can now configure if calls support Video. Depending on the value `CallKit` will suffix either the word `Audio` (when false) or `Video` when true, next to the application's name. [#420](https://github.com/GetStream/stream-video-swift/pull/420)
89

910
# [1.0.5](https://github.com/GetStream/stream-video-swift/releases/tag/1.0.5)
1011
_May 28, 2024_
@@ -15,7 +16,7 @@ _May 28, 2024_
1516
_May 27, 2024_
1617

1718
### 🔄 Changed
18-
- `CallKitAdapter` will dispatch voIP notification reporting to the MainActor. [#41](https://github.com/GetStream/stream-video-swift/pull/41)
19+
- `CallKitAdapter` will dispatch voIP notification reporting to the MainActor. [#411](https://github.com/GetStream/stream-video-swift/pull/411)
1920

2021
# [1.0.3](https://github.com/GetStream/stream-video-swift/releases/tag/1.0.3)
2122
_May 22, 2024_

DocumentationTests/DocumentationTests/DocumentationTests/06-advanced/03-callkit-integration.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,16 @@ fileprivate func content() {
138138
}
139139
}
140140
}
141+
142+
container {
143+
@Injected(\.callKitService) var callKitService
144+
145+
// Setting the `supportsVideo` property to `true` will
146+
// make the subtitle's format be: `<Application's name> Video`
147+
callKitService.supportsVideo = true
148+
149+
// Setting the `supportsVideo` property to `false` will
150+
// make the subtitle's format be: `<Application's name> Audio`
151+
callKitService.supportsVideo = false
152+
}
141153
}

Sources/StreamVideo/CallKit/CallKitService.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ open class CallKitService: NSObject, CXProviderDelegate, @unchecked Sendable {
5252
/// Whether the call can be held on its own or swapped with another call.
5353
/// - Important: Holding a call isn't supported yet!
5454
open var supportsHolding: Bool = false
55+
/// Whether the service supports Video in addition to Audio calls. If set to true, CallKit push notification
56+
/// title, will be suffixed with the word `Video` next to the application's name. Otherwise, it will be
57+
/// suffixed with the word `Audio`.
58+
/// - Note: defaults to `false`.
59+
open var supportsVideo: Bool = false
5560

5661
/// The call controller used for managing calls.
5762
open internal(set) lazy var callController = CXCallController()
@@ -412,7 +417,6 @@ open class CallKitService: NSObject, CXProviderDelegate, @unchecked Sendable {
412417
}
413418

414419
private func buildProvider(
415-
supportsVideo: Bool = true,
416420
supportedHandleTypes: Set<CXHandle.HandleType> = [.generic]
417421
) -> CXProvider {
418422
let configuration = {
@@ -452,7 +456,7 @@ open class CallKitService: NSObject, CXProviderDelegate, @unchecked Sendable {
452456

453457
update.localizedCallerName = localizedCallerName
454458
update.remoteHandle = CXHandle(type: .generic, value: callerId)
455-
update.hasVideo = true
459+
update.hasVideo = supportsVideo
456460
update.supportsDTMF = false
457461

458462
if supportsHolding {

StreamVideoTests/CallKit/CallKitServiceTests.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,46 @@ final class CallKitServiceTests: XCTestCase, @unchecked Sendable {
5656

5757
// MARK: - reportIncomingCall
5858

59+
@MainActor
60+
func test_reportIncomingCall_supportsVideo_callUpdateWasConfiguredCorrectly() throws {
61+
subject.supportsVideo = true
62+
63+
subject.reportIncomingCall(
64+
cid,
65+
localizedCallerName: localizedCallerName,
66+
callerId: callerId
67+
) { _ in }
68+
69+
let invocation = try XCTUnwrap(callProvider.invocations.first)
70+
71+
switch invocation {
72+
case let .reportNewIncomingCall(_, update, _):
73+
XCTAssertTrue(update.hasVideo)
74+
default:
75+
XCTFail()
76+
}
77+
}
78+
79+
@MainActor
80+
func test_reportIncomingCall_doesNotSupportVideo_callUpdateWasConfiguredCorrectly() throws {
81+
subject.supportsVideo = false
82+
83+
subject.reportIncomingCall(
84+
cid,
85+
localizedCallerName: localizedCallerName,
86+
callerId: callerId
87+
) { _ in }
88+
89+
let invocation = try XCTUnwrap(callProvider.invocations.first)
90+
91+
switch invocation {
92+
case let .reportNewIncomingCall(_, update, _):
93+
XCTAssertFalse(update.hasVideo)
94+
default:
95+
XCTFail()
96+
}
97+
}
98+
5999
@MainActor
60100
func test_reportIncomingCall_callProviderWasCalledWithExpectedValues() {
61101
// Given

docusaurus/docs/iOS/06-advanced/03-callkit-integration.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ If none of the fields above are being set, the property will be an empty string.
161161
- **created_by_display_name**
162162
The property is always set and contains the name of the user who created the call.
163163

164+
#### Call's type suffix
165+
166+
Depending on the `Call` type `CallKit` adds a suffix in the push notification's subtitle (which contains the application name). That suffix can either be `Audio` or `Video`. `CallKitService` allows you to configure what the supported call types are, by setting the `CallKitService.supportsVideo` property like below:
167+
168+
```swift
169+
@Injected(\.callKitService) var callKitService
170+
171+
// Setting the `supportsVideo` property to `true` will
172+
// make the subtitle's format be: `<Application's name> Video`
173+
callKitService.supportsVideo = true
174+
175+
// Setting the `supportsVideo` property to `false` will
176+
// make the subtitle's format be: `<Application's name> Audio`
177+
callKitService.supportsVideo = false
178+
```
179+
180+
`CallKitService.supportsVideo` default value is `false`.
181+
164182
### Registering for VoIP Push Notifications
165183

166184
Even though using the `CallKitAdapter` abstracts most of the `CallKit` & `PushKit` complexity from you, there is still a need for you to register/unregister the deviceToken.

0 commit comments

Comments
 (0)