Skip to content

Commit 54625af

Browse files
committed
Merge branch 'beta' into gift-resale
2 parents 1f051f7 + 62e53f8 commit 54625af

27 files changed

+711
-7279
lines changed

submodules/AccountContext/Sources/PresentationCallManager.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,10 @@ public extension GroupCallParticipantsContext.Participant {
389389
guard let videoDescription = self.videoDescription else {
390390
return nil
391391
}
392-
return PresentationGroupCallRequestedVideo(audioSsrc: audioSsrc, peerId: self.peer.id.id._internalGetInt64Value(), endpointId: videoDescription.endpointId, ssrcGroups: videoDescription.ssrcGroups.map { group in
392+
guard let peer = self.peer else {
393+
return nil
394+
}
395+
return PresentationGroupCallRequestedVideo(audioSsrc: audioSsrc, peerId: peer.id.id._internalGetInt64Value(), endpointId: videoDescription.endpointId, ssrcGroups: videoDescription.ssrcGroups.map { group in
393396
PresentationGroupCallRequestedVideo.SsrcGroup(semantics: group.semantics, ssrcs: group.ssrcs)
394397
}, minQuality: minQuality, maxQuality: maxQuality)
395398
}
@@ -401,7 +404,10 @@ public extension GroupCallParticipantsContext.Participant {
401404
guard let presentationDescription = self.presentationDescription else {
402405
return nil
403406
}
404-
return PresentationGroupCallRequestedVideo(audioSsrc: audioSsrc, peerId: self.peer.id.id._internalGetInt64Value(), endpointId: presentationDescription.endpointId, ssrcGroups: presentationDescription.ssrcGroups.map { group in
407+
guard let peer = self.peer else {
408+
return nil
409+
}
410+
return PresentationGroupCallRequestedVideo(audioSsrc: audioSsrc, peerId: peer.id.id._internalGetInt64Value(), endpointId: presentationDescription.endpointId, ssrcGroups: presentationDescription.ssrcGroups.map { group in
405411
PresentationGroupCallRequestedVideo.SsrcGroup(semantics: group.semantics, ssrcs: group.ssrcs)
406412
}, minQuality: minQuality, maxQuality: maxQuality)
407413
}

submodules/TelegramCallsUI/Sources/AccountGroupCallContextImpl.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext {
5757
id: call.id,
5858
reference: .id(id: call.id, accessHash: call.accessHash),
5959
state: state,
60-
previousServiceState: nil
60+
previousServiceState: nil,
61+
e2eContext: nil
6162
)
6263

6364
self.participantsContext = context

submodules/TelegramCallsUI/Sources/CallStatusBarNode.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ public class CallStatusBarNodeImpl: CallStatusBarNode {
425425
if let members = currentMembers {
426426
var speakingPeers: [Peer] = []
427427
for member in members.participants {
428-
if members.speakingParticipants.contains(member.peer.id) {
429-
speakingPeers.append(member.peer)
428+
if let memberPeer = member.peer, members.speakingParticipants.contains(memberPeer.id) {
429+
speakingPeers.append(memberPeer._asPeer())
430430
}
431431
}
432432
speakingPeer = speakingPeers.first

submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
395395
if data.info.isStream {
396396
self.avatarsContent = self.avatarsContext.update(peers: [], animated: false)
397397
} else {
398-
self.avatarsContent = self.avatarsContext.update(peers: data.topParticipants.map { EnginePeer($0.peer) }, animated: false)
398+
self.avatarsContent = self.avatarsContext.update(peers: data.topParticipants.compactMap { $0.peer }, animated: false)
399399

400400
if let imageDisposable = self.imageDisposable {
401401
self.imageDisposable = nil
@@ -430,7 +430,7 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
430430
if let info = summaryState.info, info.isStream {
431431
strongSelf.avatarsContent = strongSelf.avatarsContext.update(peers: [], animated: false)
432432
} else {
433-
strongSelf.avatarsContent = strongSelf.avatarsContext.update(peers: summaryState.topParticipants.map { EnginePeer($0.peer) }, animated: false)
433+
strongSelf.avatarsContent = strongSelf.avatarsContext.update(peers: summaryState.topParticipants.compactMap { $0.peer }, animated: false)
434434
}
435435

436436
if let (size, leftInset, rightInset, isHidden) = strongSelf.validLayout {
@@ -513,7 +513,7 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
513513
if data.info.isStream {
514514
self.avatarsContent = self.avatarsContext.update(peers: [], animated: false)
515515
} else {
516-
self.avatarsContent = self.avatarsContext.update(peers: data.topParticipants.map { EnginePeer($0.peer) }, animated: false)
516+
self.avatarsContent = self.avatarsContext.update(peers: data.topParticipants.compactMap { $0.peer }, animated: false)
517517
}
518518

519519
updateAudioLevels = true

submodules/TelegramCallsUI/Sources/PresentationCall.swift

Lines changed: 4 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -15,216 +15,6 @@ import AccountContext
1515
import DeviceProximity
1616
import PhoneNumberFormat
1717

18-
public final class SharedCallAudioContext {
19-
let audioDevice: OngoingCallContext.AudioDevice?
20-
let callKitIntegration: CallKitIntegration?
21-
22-
private let defaultToSpeaker: Bool
23-
24-
private var audioSessionDisposable: Disposable?
25-
private var audioSessionShouldBeActiveDisposable: Disposable?
26-
private var isAudioSessionActiveDisposable: Disposable?
27-
private var audioOutputStateDisposable: Disposable?
28-
29-
private(set) var audioSessionControl: ManagedAudioSessionControl?
30-
31-
private let isAudioSessionActivePromise = Promise<Bool>(false)
32-
private var isAudioSessionActive: Signal<Bool, NoError> {
33-
return self.isAudioSessionActivePromise.get()
34-
}
35-
36-
private let audioOutputStatePromise = Promise<([AudioSessionOutput], AudioSessionOutput?)>(([], nil))
37-
private var audioOutputStateValue: ([AudioSessionOutput], AudioSessionOutput?) = ([], nil)
38-
public private(set) var currentAudioOutputValue: AudioSessionOutput = .builtin
39-
private var didSetCurrentAudioOutputValue: Bool = false
40-
var audioOutputState: Signal<([AudioSessionOutput], AudioSessionOutput?), NoError> {
41-
return self.audioOutputStatePromise.get()
42-
}
43-
44-
private let audioSessionShouldBeActive = Promise<Bool>(true)
45-
private var initialSetupTimer: Foundation.Timer?
46-
47-
init(audioSession: ManagedAudioSession, callKitIntegration: CallKitIntegration?, defaultToSpeaker: Bool = false) {
48-
self.callKitIntegration = callKitIntegration
49-
self.audioDevice = OngoingCallContext.AudioDevice.create(enableSystemMute: false)
50-
self.defaultToSpeaker = defaultToSpeaker
51-
52-
if defaultToSpeaker {
53-
self.didSetCurrentAudioOutputValue = true
54-
self.currentAudioOutputValue = .speaker
55-
}
56-
57-
var didReceiveAudioOutputs = false
58-
self.audioSessionDisposable = audioSession.push(audioSessionType: .voiceCall, manualActivate: { [weak self] control in
59-
Queue.mainQueue().async {
60-
guard let self else {
61-
return
62-
}
63-
let previousControl = self.audioSessionControl
64-
self.audioSessionControl = control
65-
66-
if previousControl == nil, let audioSessionControl = self.audioSessionControl {
67-
if let callKitIntegration = self.callKitIntegration {
68-
if self.didSetCurrentAudioOutputValue {
69-
callKitIntegration.applyVoiceChatOutputMode(outputMode: .custom(self.currentAudioOutputValue))
70-
}
71-
} else {
72-
audioSessionControl.setOutputMode(.custom(self.currentAudioOutputValue))
73-
audioSessionControl.setup(synchronous: true)
74-
}
75-
76-
let audioSessionActive: Signal<Bool, NoError>
77-
if let callKitIntegration = self.callKitIntegration {
78-
audioSessionActive = callKitIntegration.audioSessionActive
79-
} else {
80-
audioSessionControl.activate({ _ in })
81-
audioSessionActive = .single(true)
82-
}
83-
self.isAudioSessionActivePromise.set(audioSessionActive)
84-
85-
self.initialSetupTimer?.invalidate()
86-
self.initialSetupTimer = Foundation.Timer(timeInterval: 0.5, repeats: false, block: { [weak self] _ in
87-
guard let self else {
88-
return
89-
}
90-
91-
if self.defaultToSpeaker, let audioSessionControl = self.audioSessionControl {
92-
self.currentAudioOutputValue = .speaker
93-
self.didSetCurrentAudioOutputValue = true
94-
95-
if let callKitIntegration = self.callKitIntegration {
96-
if self.didSetCurrentAudioOutputValue {
97-
callKitIntegration.applyVoiceChatOutputMode(outputMode: .custom(self.currentAudioOutputValue))
98-
}
99-
} else {
100-
audioSessionControl.setOutputMode(.custom(self.currentAudioOutputValue))
101-
audioSessionControl.setup(synchronous: true)
102-
}
103-
}
104-
})
105-
}
106-
}
107-
}, deactivate: { [weak self] _ in
108-
return Signal { subscriber in
109-
Queue.mainQueue().async {
110-
if let self {
111-
self.isAudioSessionActivePromise.set(.single(false))
112-
self.audioSessionControl = nil
113-
}
114-
subscriber.putCompletion()
115-
}
116-
return EmptyDisposable
117-
}
118-
}, availableOutputsChanged: { [weak self] availableOutputs, currentOutput in
119-
Queue.mainQueue().async {
120-
guard let self else {
121-
return
122-
}
123-
self.audioOutputStateValue = (availableOutputs, currentOutput)
124-
if let currentOutput = currentOutput {
125-
self.currentAudioOutputValue = currentOutput
126-
self.didSetCurrentAudioOutputValue = true
127-
}
128-
129-
var signal: Signal<([AudioSessionOutput], AudioSessionOutput?), NoError> = .single((availableOutputs, currentOutput))
130-
if !didReceiveAudioOutputs {
131-
didReceiveAudioOutputs = true
132-
if currentOutput == .speaker {
133-
signal = .single((availableOutputs, .builtin))
134-
|> then(
135-
signal
136-
|> delay(1.0, queue: Queue.mainQueue())
137-
)
138-
}
139-
}
140-
self.audioOutputStatePromise.set(signal)
141-
}
142-
})
143-
144-
self.audioSessionShouldBeActive.set(.single(true))
145-
self.audioSessionShouldBeActiveDisposable = (self.audioSessionShouldBeActive.get()
146-
|> deliverOnMainQueue).start(next: { [weak self] value in
147-
guard let self else {
148-
return
149-
}
150-
if value {
151-
if let audioSessionControl = self.audioSessionControl {
152-
let audioSessionActive: Signal<Bool, NoError>
153-
if let callKitIntegration = self.callKitIntegration {
154-
audioSessionActive = callKitIntegration.audioSessionActive
155-
} else {
156-
audioSessionControl.activate({ _ in })
157-
audioSessionActive = .single(true)
158-
}
159-
self.isAudioSessionActivePromise.set(audioSessionActive)
160-
} else {
161-
self.isAudioSessionActivePromise.set(.single(false))
162-
}
163-
} else {
164-
self.isAudioSessionActivePromise.set(.single(false))
165-
}
166-
})
167-
168-
self.isAudioSessionActiveDisposable = (self.isAudioSessionActive
169-
|> deliverOnMainQueue).start(next: { [weak self] value in
170-
guard let self else {
171-
return
172-
}
173-
self.audioDevice?.setIsAudioSessionActive(value)
174-
})
175-
176-
self.audioOutputStateDisposable = (self.audioOutputStatePromise.get()
177-
|> deliverOnMainQueue).start(next: { [weak self] value in
178-
guard let self else {
179-
return
180-
}
181-
self.audioOutputStateValue = value
182-
if let currentOutput = value.1 {
183-
self.currentAudioOutputValue = currentOutput
184-
}
185-
})
186-
}
187-
188-
deinit {
189-
self.audioSessionDisposable?.dispose()
190-
self.audioSessionShouldBeActiveDisposable?.dispose()
191-
self.isAudioSessionActiveDisposable?.dispose()
192-
self.audioOutputStateDisposable?.dispose()
193-
self.initialSetupTimer?.invalidate()
194-
}
195-
196-
func setCurrentAudioOutput(_ output: AudioSessionOutput) {
197-
self.initialSetupTimer?.invalidate()
198-
self.initialSetupTimer = nil
199-
200-
guard self.currentAudioOutputValue != output else {
201-
return
202-
}
203-
self.currentAudioOutputValue = output
204-
self.didSetCurrentAudioOutputValue = true
205-
206-
self.audioOutputStatePromise.set(.single((self.audioOutputStateValue.0, output))
207-
|> then(
208-
.single(self.audioOutputStateValue)
209-
|> delay(1.0, queue: Queue.mainQueue())
210-
))
211-
212-
if let audioSessionControl = self.audioSessionControl {
213-
if let callKitIntegration = self.callKitIntegration {
214-
callKitIntegration.applyVoiceChatOutputMode(outputMode: .custom(self.currentAudioOutputValue))
215-
} else {
216-
audioSessionControl.setOutputMode(.custom(output))
217-
}
218-
}
219-
}
220-
221-
public func switchToSpeakerIfBuiltin() {
222-
if case .builtin = self.currentAudioOutputValue {
223-
self.setCurrentAudioOutput(.speaker)
224-
}
225-
}
226-
}
227-
22818
public final class PresentationCallImpl: PresentationCall {
22919
public let context: AccountContext
23020
private let audioSession: ManagedAudioSession
@@ -556,7 +346,7 @@ public final class PresentationCallImpl: PresentationCall {
556346
if let data = context.currentAppConfiguration.with({ $0 }).data, let _ = data["ios_killswitch_disable_call_device"] {
557347
self.sharedAudioContext = nil
558348
} else {
559-
self.sharedAudioContext = SharedCallAudioContext(audioSession: audioSession, callKitIntegration: callKitIntegration, defaultToSpeaker: startWithVideo || initialState?.type == .video)
349+
self.sharedAudioContext = SharedCallAudioContext.get(audioSession: audioSession, callKitIntegration: callKitIntegration, defaultToSpeaker: startWithVideo || initialState?.type == .video)
560350
}
561351

562352
if let _ = self.sharedAudioContext {
@@ -1118,7 +908,7 @@ public final class PresentationCallImpl: PresentationCall {
1118908
var found = false
1119909
if let members {
1120910
for participant in members.participants {
1121-
if participant.peer.id == waitForRemotePeerId {
911+
if participant.id == .peer(waitForRemotePeerId) {
1122912
found = true
1123913
break
1124914
}
@@ -1131,7 +921,7 @@ public final class PresentationCallImpl: PresentationCall {
1131921
if waitForLocalVideo {
1132922
if let members {
1133923
for participant in members.participants {
1134-
if participant.peer.id == state.myPeerId {
924+
if participant.id == .peer(state.myPeerId) {
1135925
if participant.videoDescription == nil {
1136926
return false
1137927
}
@@ -1142,7 +932,7 @@ public final class PresentationCallImpl: PresentationCall {
1142932
if let waitForRemoteVideo {
1143933
if let members {
1144934
for participant in members.participants {
1145-
if participant.peer.id == waitForRemoteVideo {
935+
if participant.id == .peer(waitForRemoteVideo) {
1146936
if participant.videoDescription == nil {
1147937
return false
1148938
}

0 commit comments

Comments
 (0)