Skip to content

Commit 9efef8d

Browse files
author
Isaac
committed
Call improvements
1 parent dc4ea3e commit 9efef8d

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

‎submodules/TelegramCallsUI/Sources/CallControllerNodeV2.swift

+6
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ final class CallControllerNodeV2: ViewControllerTracingNode, CallControllerNodeP
528528
}
529529

530530
if var callScreenState = self.callScreenState {
531+
if callScreenState.remoteVideo == nil && self.remoteVideo != nil {
532+
if let call = self.call as? PresentationCallImpl, let sharedAudioContext = call.sharedAudioContext, case .builtin = sharedAudioContext.currentAudioOutputValue {
533+
call.playRemoteCameraTone()
534+
}
535+
}
536+
531537
callScreenState.lifecycleState = mappedLifecycleState
532538
callScreenState.remoteVideo = self.remoteVideo
533539
callScreenState.localVideo = self.localVideo

‎submodules/TelegramCallsUI/Sources/PresentationCall.swift

+39-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import AccountContext
1515
import DeviceProximity
1616
import PhoneNumberFormat
1717

18-
final class SharedCallAudioContext {
18+
public final class SharedCallAudioContext {
1919
let audioDevice: OngoingCallContext.AudioDevice?
2020
let callKitIntegration: CallKitIntegration?
2121

2222
private var audioSessionDisposable: Disposable?
2323
private var audioSessionShouldBeActiveDisposable: Disposable?
2424
private var isAudioSessionActiveDisposable: Disposable?
25+
private var audioOutputStateDisposable: Disposable?
2526

2627
private(set) var audioSessionControl: ManagedAudioSessionControl?
2728

@@ -32,7 +33,7 @@ final class SharedCallAudioContext {
3233

3334
private let audioOutputStatePromise = Promise<([AudioSessionOutput], AudioSessionOutput?)>(([], nil))
3435
private var audioOutputStateValue: ([AudioSessionOutput], AudioSessionOutput?) = ([], nil)
35-
private var currentAudioOutputValue: AudioSessionOutput = .builtin
36+
public private(set) var currentAudioOutputValue: AudioSessionOutput = .builtin
3637
private var didSetCurrentAudioOutputValue: Bool = false
3738
var audioOutputState: Signal<([AudioSessionOutput], AudioSessionOutput?), NoError> {
3839
return self.audioOutputStatePromise.get()
@@ -141,12 +142,24 @@ final class SharedCallAudioContext {
141142
}
142143
self.audioDevice?.setIsAudioSessionActive(value)
143144
})
145+
146+
self.audioOutputStateDisposable = (self.audioOutputStatePromise.get()
147+
|> deliverOnMainQueue).start(next: { [weak self] value in
148+
guard let self else {
149+
return
150+
}
151+
self.audioOutputStateValue = value
152+
if let currentOutput = value.1 {
153+
self.currentAudioOutputValue = currentOutput
154+
}
155+
})
144156
}
145157

146158
deinit {
147159
self.audioSessionDisposable?.dispose()
148160
self.audioSessionShouldBeActiveDisposable?.dispose()
149161
self.isAudioSessionActiveDisposable?.dispose()
162+
self.audioOutputStateDisposable?.dispose()
150163
}
151164

152165
func setCurrentAudioOutput(_ output: AudioSessionOutput) {
@@ -201,7 +214,7 @@ public final class PresentationCallImpl: PresentationCall {
201214
private let currentNetworkType: NetworkType
202215
private let updatedNetworkType: Signal<NetworkType, NoError>
203216

204-
private var sharedAudioContext: SharedCallAudioContext?
217+
public private(set) var sharedAudioContext: SharedCallAudioContext?
205218

206219
private var sessionState: CallSession?
207220
private var callContextState: OngoingCallContextState?
@@ -1610,6 +1623,29 @@ public final class PresentationCallImpl: PresentationCall {
16101623
self.useFrontCamera = !self.useFrontCamera
16111624
self.videoCapturer?.switchVideoInput(isFront: self.useFrontCamera)
16121625
}
1626+
1627+
public func playRemoteCameraTone() {
1628+
let name: String
1629+
name = "voip_group_recording_started.mp3"
1630+
1631+
self.beginTone(tone: .custom(name: name, loopCount: 1))
1632+
}
1633+
1634+
private func beginTone(tone: PresentationCallTone?) {
1635+
if let tone, let toneData = presentationCallToneData(tone) {
1636+
if let sharedAudioContext = self.sharedAudioContext {
1637+
sharedAudioContext.audioDevice?.setTone(tone: OngoingCallContext.Tone(
1638+
samples: toneData,
1639+
sampleRate: 48000,
1640+
loopCount: tone.loopCount ?? 100000
1641+
))
1642+
}
1643+
} else {
1644+
if let sharedAudioContext = self.sharedAudioContext {
1645+
sharedAudioContext.audioDevice?.setTone(tone: nil)
1646+
}
1647+
}
1648+
}
16131649
}
16141650

16151651
func sampleBufferFromPixelBuffer(pixelBuffer: CVPixelBuffer) -> CMSampleBuffer? {

‎submodules/TelegramUI/Components/Calls/CallScreen/Sources/PrivateCallScreen.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ public final class PrivateCallScreen: OverlayMaskContainerView, AVPictureInPictu
613613
if let previousParams = self.params, case .active = params.state.lifecycleState {
614614
switch previousParams.state.lifecycleState {
615615
case .requesting, .ringing, .connecting, .reconnecting:
616-
if self.hideEmojiTooltipTimer == nil && !self.areControlsHidden {
616+
if self.hideEmojiTooltipTimer == nil && !self.areControlsHidden && self.activeRemoteVideoSource == nil && self.activeLocalVideoSource == nil {
617617
self.displayEmojiTooltip = true
618618

619619
self.hideEmojiTooltipTimer = Foundation.Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false, block: { [weak self] _ in

0 commit comments

Comments
 (0)