mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Voice chat UI changes
This commit is contained in:
@@ -27,7 +27,7 @@ public final class GroupCallPanelData {
|
||||
public let info: GroupCallInfo
|
||||
public let topParticipants: [GroupCallParticipantsContext.Participant]
|
||||
public let participantCount: Int
|
||||
public let numberOfActiveSpeakers: Int
|
||||
public let activeSpeakers: Set<PeerId>
|
||||
public let groupCall: PresentationGroupCall?
|
||||
|
||||
public init(
|
||||
@@ -35,18 +35,44 @@ public final class GroupCallPanelData {
|
||||
info: GroupCallInfo,
|
||||
topParticipants: [GroupCallParticipantsContext.Participant],
|
||||
participantCount: Int,
|
||||
numberOfActiveSpeakers: Int,
|
||||
activeSpeakers: Set<PeerId>,
|
||||
groupCall: PresentationGroupCall?
|
||||
) {
|
||||
self.peerId = peerId
|
||||
self.info = info
|
||||
self.topParticipants = topParticipants
|
||||
self.participantCount = participantCount
|
||||
self.numberOfActiveSpeakers = numberOfActiveSpeakers
|
||||
self.activeSpeakers = activeSpeakers
|
||||
self.groupCall = groupCall
|
||||
}
|
||||
}
|
||||
|
||||
private final class FakeAudioLevelGenerator {
|
||||
private var previousTarget: Float = 0.0
|
||||
private var nextTarget: Float = 0.0
|
||||
private var nextTargetProgress: Float = 1.0
|
||||
private var nextTargetProgressNorm: Float = 1.0
|
||||
|
||||
func get() -> Float {
|
||||
self.nextTargetProgress *= 0.82
|
||||
if self.nextTargetProgress <= 0.01 {
|
||||
self.previousTarget = self.nextTarget
|
||||
if Int.random(in: 0 ... 4) <= 1 {
|
||||
self.nextTarget = 0.0
|
||||
self.nextTargetProgressNorm = Float.random(in: 0.1 ..< 0.3)
|
||||
} else {
|
||||
self.nextTarget = Float.random(in: 0.0 ..< 20.0)
|
||||
self.nextTargetProgressNorm = Float.random(in: 0.2 ..< 0.7)
|
||||
}
|
||||
self.nextTargetProgress = self.nextTargetProgressNorm
|
||||
return self.nextTarget
|
||||
} else {
|
||||
let value = self.nextTarget * max(0.0, self.nextTargetProgress / self.nextTargetProgressNorm)
|
||||
return value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
|
||||
private let context: AccountContext
|
||||
private var theme: PresentationTheme
|
||||
@@ -77,6 +103,8 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
|
||||
private let avatarsContext: AnimatedAvatarSetContext
|
||||
private var avatarsContent: AnimatedAvatarSetContext.Content?
|
||||
private let avatarsNode: AnimatedAvatarSetNode
|
||||
private var audioLevelGenerators: [PeerId: FakeAudioLevelGenerator] = [:]
|
||||
private var audioLevelGeneratorTimer: SwiftSignalKit.Timer?
|
||||
|
||||
private let separatorNode: ASDisplayNode
|
||||
|
||||
@@ -167,6 +195,7 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
|
||||
deinit {
|
||||
self.membersDisposable.dispose()
|
||||
self.isMutedDisposable.dispose()
|
||||
self.audioLevelGeneratorTimer?.invalidate()
|
||||
}
|
||||
|
||||
public override func didLoad() {
|
||||
@@ -255,6 +284,8 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
|
||||
let previousData = self.currentData
|
||||
self.currentData = data
|
||||
|
||||
var updateAudioLevels = false
|
||||
|
||||
if previousData?.groupCall !== data.groupCall {
|
||||
let membersText: String
|
||||
if data.participantCount == 0 {
|
||||
@@ -382,11 +413,50 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
|
||||
self.textNode.attributedText = NSAttributedString(string: membersText, font: Font.regular(13.0), textColor: membersTextIsActive ? self.theme.chat.inputPanel.panelControlAccentColor : self.theme.chat.inputPanel.secondaryTextColor)
|
||||
|
||||
self.avatarsContent = self.avatarsContext.update(peers: data.topParticipants.map { $0.peer }, animated: false)
|
||||
|
||||
updateAudioLevels = true
|
||||
}
|
||||
|
||||
if let (size, leftInset, rightInset) = self.validLayout {
|
||||
self.updateLayout(size: size, leftInset: leftInset, rightInset: rightInset, transition: .immediate)
|
||||
}
|
||||
|
||||
if updateAudioLevels {
|
||||
for peerId in data.activeSpeakers {
|
||||
if self.audioLevelGenerators[peerId] == nil {
|
||||
self.audioLevelGenerators[peerId] = FakeAudioLevelGenerator()
|
||||
}
|
||||
}
|
||||
var removeGenerators: [PeerId] = []
|
||||
for peerId in self.audioLevelGenerators.keys {
|
||||
if !data.activeSpeakers.contains(peerId) {
|
||||
removeGenerators.append(peerId)
|
||||
}
|
||||
}
|
||||
for peerId in removeGenerators {
|
||||
self.audioLevelGenerators.removeValue(forKey: peerId)
|
||||
}
|
||||
|
||||
if self.audioLevelGenerators.isEmpty {
|
||||
self.audioLevelGeneratorTimer?.invalidate()
|
||||
self.audioLevelGeneratorTimer = nil
|
||||
self.avatarsNode.updateAudioLevels(color: self.theme.chat.inputPanel.actionControlFillColor, levels: [:])
|
||||
} else if self.audioLevelGeneratorTimer == nil {
|
||||
let audioLevelGeneratorTimer = SwiftSignalKit.Timer(timeout: 1.0 / 30.0, repeat: true, completion: { [weak self] in
|
||||
self?.sampleAudioGenerators()
|
||||
}, queue: .mainQueue())
|
||||
self.audioLevelGeneratorTimer = audioLevelGeneratorTimer
|
||||
audioLevelGeneratorTimer.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func sampleAudioGenerators() {
|
||||
var levels: [PeerId: Float] = [:]
|
||||
for (peerId, generator) in self.audioLevelGenerators {
|
||||
levels[peerId] = generator.get()
|
||||
}
|
||||
self.avatarsNode.updateAudioLevels(color: self.theme.chat.inputPanel.actionControlFillColor, levels: levels)
|
||||
}
|
||||
|
||||
public func updateLayout(size: CGSize, leftInset: CGFloat, rightInset: CGFloat, transition: ContainedViewLayoutTransition) {
|
||||
|
||||
Reference in New Issue
Block a user