From 2c5218457fcdbd2920d431d5212ce59c0882a8c4 Mon Sep 17 00:00:00 2001 From: Ilias Pavlidakis Date: Fri, 3 Jan 2025 10:51:33 +0200 Subject: [PATCH] [CallKit]Custom ringtone support (#628) --- CHANGELOG.md | 1 + .../StreamVideo/CallKit/CallKitAdapter.swift | 6 ++++ .../StreamVideo/CallKit/CallKitService.swift | 3 ++ .../CallKit/CallKitServiceTests.swift | 28 +++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index edf71027f..2da3c9161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### ✅ Added - CallKit availability policies allows you to control wether `Callkit` should be enabled/disabled based on different rules [#611](https://github.com/GetStream/stream-video-swift/pull/611) +- Support for setting a ringtone for CallKit calls [#628](https://github.com/GetStream/stream-video-swift/pull/628) ### 🐞 Fixed - By observing the `CallKitPushNotificationAdapter.deviceToken` you will be notified with an empty `deviceToken` value, once the object unregister push notifications. [#608](https://github.com/GetStream/stream-video-swift/pull/608) diff --git a/Sources/StreamVideo/CallKit/CallKitAdapter.swift b/Sources/StreamVideo/CallKit/CallKitAdapter.swift index b9dbd4fe9..ec217e5d2 100644 --- a/Sources/StreamVideo/CallKit/CallKitAdapter.swift +++ b/Sources/StreamVideo/CallKit/CallKitAdapter.swift @@ -20,6 +20,12 @@ open class CallKitAdapter { set { callKitService.iconTemplateImageData = newValue } } + /// The ringtone sound to use for CallKit ringing calls. + open var ringtoneSound: String? { + get { callKitService.ringtoneSound } + set { callKitService.ringtoneSound = newValue } + } + /// The callSettings to use when joining a call (after accepting it on CallKit) /// default: nil open var callSettings: CallSettings? { diff --git a/Sources/StreamVideo/CallKit/CallKitService.swift b/Sources/StreamVideo/CallKit/CallKitService.swift index ea84c7c1a..507462912 100644 --- a/Sources/StreamVideo/CallKit/CallKitService.swift +++ b/Sources/StreamVideo/CallKit/CallKitService.swift @@ -64,6 +64,8 @@ open class CallKitService: NSObject, CXProviderDelegate, @unchecked Sendable { /// The icon data for the call template. open var iconTemplateImageData: Data? + /// The ringtone sound to use for CallKit ringing calls. + open var ringtoneSound: String? /// Whether the call can be held on its own or swapped with another call. /// - Important: Holding a call isn't supported yet! open var supportsHolding: Bool = false @@ -554,6 +556,7 @@ open class CallKitService: NSObject, CXProviderDelegate, @unchecked Sendable { configuration.supportsVideo = supportsVideo configuration.supportedHandleTypes = supportedHandleTypes configuration.iconTemplateImageData = iconTemplateImageData + configuration.ringtoneSound = ringtoneSound if supportsHolding { // Holding a call isn't supported yet. diff --git a/StreamVideoTests/CallKit/CallKitServiceTests.swift b/StreamVideoTests/CallKit/CallKitServiceTests.swift index aef5bb052..8f68ce4a4 100644 --- a/StreamVideoTests/CallKit/CallKitServiceTests.swift +++ b/StreamVideoTests/CallKit/CallKitServiceTests.swift @@ -96,6 +96,34 @@ final class CallKitServiceTests: XCTestCase, @unchecked Sendable { } } + @MainActor + func test_reportIncomingCall_withIconTemplateImageData_callUpdateWasConfiguredCorrectly() throws { + subject = .init() + let expectedData = String.unique.data(using: .utf8) + subject.iconTemplateImageData = expectedData + + subject.reportIncomingCall( + cid, + localizedCallerName: localizedCallerName, + callerId: callerId + ) { _ in } + + XCTAssertEqual(subject.callProvider.configuration.iconTemplateImageData, expectedData) + } + + @MainActor + func test_reportIncomingCall_withoutIconTemplateImageData_callUpdateWasConfiguredCorrectly() throws { + subject = .init() + + subject.reportIncomingCall( + cid, + localizedCallerName: localizedCallerName, + callerId: callerId + ) { _ in } + + XCTAssertNil(subject.callProvider.configuration.iconTemplateImageData) + } + @MainActor func test_reportIncomingCall_callProviderWasCalledWithExpectedValues() { // Given