@@ -15,13 +15,14 @@ import AccountContext
1515import DeviceProximity
1616import 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
16151651func sampleBufferFromPixelBuffer( pixelBuffer: CVPixelBuffer ) -> CMSampleBuffer ? {
0 commit comments