mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Use ssrc to request speaking peers
This commit is contained in:
@@ -57,7 +57,7 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext {
|
||||
groupCall: nil
|
||||
)))
|
||||
|
||||
self.disposable = (getGroupCallParticipants(account: account, callId: call.id, accessHash: call.accessHash, offset: "", peerIds: [], limit: 100)
|
||||
self.disposable = (getGroupCallParticipants(account: account, callId: call.id, accessHash: call.accessHash, offset: "", ssrcs: [], limit: 100)
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<GroupCallParticipantsContext.State?, NoError> in
|
||||
return .single(nil)
|
||||
@@ -228,13 +228,14 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
private let silentTimeout: Int32 = 2
|
||||
|
||||
struct Participant {
|
||||
let ssrc: UInt32
|
||||
let timestamp: Int32
|
||||
let level: Float
|
||||
}
|
||||
|
||||
private var participants: [PeerId: Participant] = [:]
|
||||
private let speakingParticipantsPromise = ValuePromise<Set<PeerId>>()
|
||||
private var speakingParticipants = Set<PeerId>() {
|
||||
private let speakingParticipantsPromise = ValuePromise<[PeerId: UInt32]>()
|
||||
private var speakingParticipants = [PeerId: UInt32]() {
|
||||
didSet {
|
||||
self.speakingParticipantsPromise.set(self.speakingParticipants)
|
||||
}
|
||||
@@ -245,17 +246,17 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
init() {
|
||||
}
|
||||
|
||||
func update(levels: [(PeerId, Float, Bool)]) {
|
||||
func update(levels: [(PeerId, UInt32, Float, Bool)]) {
|
||||
let timestamp = Int32(CFAbsoluteTimeGetCurrent())
|
||||
let currentParticipants: [PeerId: Participant] = self.participants
|
||||
|
||||
var validSpeakers: [PeerId: Participant] = [:]
|
||||
var silentParticipants = Set<PeerId>()
|
||||
var speakingParticipants = Set<PeerId>()
|
||||
for (peerId, level, hasVoice) in levels {
|
||||
var speakingParticipants = [PeerId: UInt32]()
|
||||
for (peerId, ssrc, level, hasVoice) in levels {
|
||||
if level > speakingLevelThreshold && hasVoice {
|
||||
validSpeakers[peerId] = Participant(timestamp: timestamp, level: level)
|
||||
speakingParticipants.insert(peerId)
|
||||
validSpeakers[peerId] = Participant(ssrc: ssrc, timestamp: timestamp, level: level)
|
||||
speakingParticipants[peerId] = ssrc
|
||||
} else {
|
||||
silentParticipants.insert(peerId)
|
||||
}
|
||||
@@ -268,17 +269,17 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
if silentParticipants.contains(peerId) {
|
||||
if delta < silentTimeout {
|
||||
validSpeakers[peerId] = participant
|
||||
speakingParticipants.insert(peerId)
|
||||
speakingParticipants[peerId] = participant.ssrc
|
||||
}
|
||||
} else if delta < cutoffTimeout {
|
||||
validSpeakers[peerId] = participant
|
||||
speakingParticipants.insert(peerId)
|
||||
speakingParticipants[peerId] = participant.ssrc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var audioLevels: [(PeerId, Float, Bool)] = []
|
||||
for (peerId, level, hasVoice) in levels {
|
||||
for (peerId, _, level, hasVoice) in levels {
|
||||
if level > 0.001 {
|
||||
audioLevels.append((peerId, level, hasVoice))
|
||||
}
|
||||
@@ -289,8 +290,8 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
self.audioLevelsPromise.set(.single(audioLevels))
|
||||
}
|
||||
|
||||
func get() -> Signal<Set<PeerId>, NoError> {
|
||||
return self.speakingParticipantsPromise.get() |> distinctUntilChanged
|
||||
func get() -> Signal<[PeerId: UInt32], NoError> {
|
||||
return self.speakingParticipantsPromise.get()
|
||||
}
|
||||
|
||||
func getAudioLevels() -> Signal<[(PeerId, Float, Bool)], NoError> {
|
||||
@@ -887,16 +888,19 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
var result: [(PeerId, Float, Bool)] = []
|
||||
var result: [(PeerId, UInt32, Float, Bool)] = []
|
||||
var myLevel: Float = 0.0
|
||||
var myLevelHasVoice: Bool = false
|
||||
for (ssrcKey, level, hasVoice) in levels {
|
||||
var peerId: PeerId?
|
||||
let ssrcValue: UInt32
|
||||
switch ssrcKey {
|
||||
case .local:
|
||||
peerId = strongSelf.accountContext.account.peerId
|
||||
ssrcValue = 0
|
||||
case let .source(ssrc):
|
||||
peerId = strongSelf.ssrcMapping[ssrc]
|
||||
ssrcValue = ssrc
|
||||
}
|
||||
if let peerId = peerId {
|
||||
if case .local = ssrcKey {
|
||||
@@ -905,7 +909,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
myLevelHasVoice = hasVoice
|
||||
}
|
||||
}
|
||||
result.append((peerId, level, hasVoice))
|
||||
result.append((peerId, ssrcValue, level, hasVoice))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,9 +989,9 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
|
||||
var topParticipants: [GroupCallParticipantsContext.Participant] = []
|
||||
|
||||
var reportSpeakingParticipants: [PeerId] = []
|
||||
var reportSpeakingParticipants: [PeerId: UInt32] = [:]
|
||||
let timestamp = CACurrentMediaTime()
|
||||
for peerId in speakingParticipants {
|
||||
for (peerId, ssrc) in speakingParticipants {
|
||||
let shouldReport: Bool
|
||||
if let previousTimestamp = strongSelf.speakingParticipantsReportTimestamp[peerId] {
|
||||
shouldReport = previousTimestamp + 1.0 < timestamp
|
||||
@@ -996,7 +1000,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
}
|
||||
if shouldReport {
|
||||
strongSelf.speakingParticipantsReportTimestamp[peerId] = timestamp
|
||||
reportSpeakingParticipants.append(peerId)
|
||||
reportSpeakingParticipants[peerId] = ssrc
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1008,7 +1012,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
|
||||
var members = PresentationGroupCallMembers(
|
||||
participants: [],
|
||||
speakingParticipants: speakingParticipants,
|
||||
speakingParticipants: Set(speakingParticipants.keys),
|
||||
totalCount: 0,
|
||||
loadMoreToken: nil
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user