@@ -15,13 +15,14 @@ import AccountContext
15
15
import DeviceProximity
16
16
import PhoneNumberFormat
17
17
18
- final class SharedCallAudioContext {
18
+ public final class SharedCallAudioContext {
19
19
let audioDevice : OngoingCallContext . AudioDevice ?
20
20
let callKitIntegration : CallKitIntegration ?
21
21
22
22
private var audioSessionDisposable : Disposable ?
23
23
private var audioSessionShouldBeActiveDisposable : Disposable ?
24
24
private var isAudioSessionActiveDisposable : Disposable ?
25
+ private var audioOutputStateDisposable : Disposable ?
25
26
26
27
private( set) var audioSessionControl : ManagedAudioSessionControl ?
27
28
@@ -32,7 +33,7 @@ final class SharedCallAudioContext {
32
33
33
34
private let audioOutputStatePromise = Promise < ( [ AudioSessionOutput ] , AudioSessionOutput ? ) > ( ( [ ] , nil ) )
34
35
private var audioOutputStateValue : ( [ AudioSessionOutput ] , AudioSessionOutput ? ) = ( [ ] , nil )
35
- private var currentAudioOutputValue : AudioSessionOutput = . builtin
36
+ public private( set ) var currentAudioOutputValue : AudioSessionOutput = . builtin
36
37
private var didSetCurrentAudioOutputValue : Bool = false
37
38
var audioOutputState : Signal < ( [ AudioSessionOutput ] , AudioSessionOutput ? ) , NoError > {
38
39
return self . audioOutputStatePromise. get ( )
@@ -141,12 +142,24 @@ final class SharedCallAudioContext {
141
142
}
142
143
self . audioDevice? . setIsAudioSessionActive ( value)
143
144
} )
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
+ } )
144
156
}
145
157
146
158
deinit {
147
159
self . audioSessionDisposable? . dispose ( )
148
160
self . audioSessionShouldBeActiveDisposable? . dispose ( )
149
161
self . isAudioSessionActiveDisposable? . dispose ( )
162
+ self . audioOutputStateDisposable? . dispose ( )
150
163
}
151
164
152
165
func setCurrentAudioOutput( _ output: AudioSessionOutput ) {
@@ -201,7 +214,7 @@ public final class PresentationCallImpl: PresentationCall {
201
214
private let currentNetworkType : NetworkType
202
215
private let updatedNetworkType : Signal < NetworkType , NoError >
203
216
204
- private var sharedAudioContext : SharedCallAudioContext ?
217
+ public private( set ) var sharedAudioContext : SharedCallAudioContext ?
205
218
206
219
private var sessionState : CallSession ?
207
220
private var callContextState : OngoingCallContextState ?
@@ -1610,6 +1623,29 @@ public final class PresentationCallImpl: PresentationCall {
1610
1623
self . useFrontCamera = !self . useFrontCamera
1611
1624
self . videoCapturer? . switchVideoInput ( isFront: self . useFrontCamera)
1612
1625
}
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
+ }
1613
1649
}
1614
1650
1615
1651
func sampleBufferFromPixelBuffer( pixelBuffer: CVPixelBuffer ) -> CMSampleBuffer ? {
0 commit comments