mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
@@ -27,7 +27,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
private enum InternalState {
|
||||
case requesting
|
||||
case active(GroupCallInfo)
|
||||
case estabilished(GroupCallInfo, String, UInt32, [UInt32], [UInt32: PeerId])
|
||||
case estabilished(info: GroupCallInfo, clientParams: String, localSsrc: UInt32, initialState: GroupCallParticipantsContext.State)
|
||||
|
||||
var callInfo: GroupCallInfo? {
|
||||
switch self {
|
||||
@@ -35,7 +35,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
return nil
|
||||
case let .active(info):
|
||||
return info
|
||||
case let .estabilished(info, _, _, _, _):
|
||||
case let .estabilished(info, _, _, _):
|
||||
return info
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,9 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
}
|
||||
private var audioLevelsDisposable = MetaDisposable()
|
||||
|
||||
private var participantsContextStateDisposable = MetaDisposable()
|
||||
private var participantsContext: GroupCallParticipantsContext?
|
||||
|
||||
private let myAudioLevelPipe = ValuePipe<Float>()
|
||||
public var myAudioLevel: Signal<Float, NoError> {
|
||||
return self.myAudioLevelPipe.signal()
|
||||
@@ -124,6 +127,18 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
return self.membersPromise.get()
|
||||
}
|
||||
|
||||
private var invitedPeersValue: Set<PeerId> = Set() {
|
||||
didSet {
|
||||
if self.invitedPeersValue != oldValue {
|
||||
self.inivitedPeersPromise.set(self.invitedPeersValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
private let inivitedPeersPromise = ValuePromise<Set<PeerId>>(Set())
|
||||
public var invitedPeers: Signal<Set<PeerId>, NoError> {
|
||||
return self.inivitedPeersPromise.get()
|
||||
}
|
||||
|
||||
private let requestDisposable = MetaDisposable()
|
||||
private var groupCallParticipantUpdatesDisposable: Disposable?
|
||||
|
||||
@@ -237,26 +252,20 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
if case let .estabilished(callInfo, _, _, _, _) = strongSelf.internalState {
|
||||
var addedSsrc: [UInt32] = []
|
||||
var removedSsrc: [UInt32] = []
|
||||
for (callId, peerId, ssrc, isAdded) in updates {
|
||||
if case let .estabilished(callInfo, _, _, _) = strongSelf.internalState {
|
||||
/*var addedSsrc: [UInt32] = []
|
||||
var removedSsrc: [UInt32] = []*/
|
||||
for (callId, update) in updates {
|
||||
if callId == callInfo.id {
|
||||
let mappedSsrc = UInt32(bitPattern: ssrc)
|
||||
if isAdded {
|
||||
addedSsrc.append(mappedSsrc)
|
||||
strongSelf.ssrcMapping[mappedSsrc] = peerId
|
||||
} else {
|
||||
removedSsrc.append(mappedSsrc)
|
||||
}
|
||||
strongSelf.participantsContext?.addUpdates(updates: [update])
|
||||
}
|
||||
}
|
||||
if !addedSsrc.isEmpty {
|
||||
/*if !addedSsrc.isEmpty {
|
||||
strongSelf.callContext?.addSsrcs(ssrcs: addedSsrc)
|
||||
}
|
||||
if !removedSsrc.isEmpty {
|
||||
strongSelf.callContext?.removeSsrcs(ssrcs: removedSsrc)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
})
|
||||
|
||||
@@ -276,6 +285,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
self.networkStateDisposable.dispose()
|
||||
self.checkCallDisposable?.dispose()
|
||||
self.audioLevelsDisposable.dispose()
|
||||
self.participantsContextStateDisposable.dispose()
|
||||
self.myAudioLevelDisposable.dispose()
|
||||
}
|
||||
|
||||
@@ -326,7 +336,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
return
|
||||
}
|
||||
if let clientParams = joinCallResult.callInfo.clientParams {
|
||||
strongSelf.updateSessionState(internalState: .estabilished(joinCallResult.callInfo, clientParams, ssrc, joinCallResult.ssrcs, joinCallResult.ssrcMapping), audioSessionControl: strongSelf.audioSessionControl)
|
||||
strongSelf.updateSessionState(internalState: .estabilished(info: joinCallResult.callInfo, clientParams: clientParams, localSsrc: ssrc, initialState: joinCallResult.state), audioSessionControl: strongSelf.audioSessionControl)
|
||||
}
|
||||
}))
|
||||
}))
|
||||
@@ -368,23 +378,6 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
}
|
||||
}))
|
||||
|
||||
self.memberStatesDisposable.set((callContext.memberStates
|
||||
|> deliverOnMainQueue).start(next: { [weak self] memberStates in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
var result: [PeerId: PresentationGroupCallMemberState] = [:]
|
||||
for (ssrc, _) in memberStates {
|
||||
if let peerId = strongSelf.ssrcMapping[ssrc] {
|
||||
result[peerId] = PresentationGroupCallMemberState(
|
||||
ssrc: ssrc,
|
||||
isSpeaking: false
|
||||
)
|
||||
}
|
||||
}
|
||||
strongSelf.membersValue = result
|
||||
}))
|
||||
|
||||
self.audioLevelsDisposable.set((callContext.audioLevels
|
||||
|> deliverOnMainQueue).start(next: { [weak self] levels in
|
||||
guard let strongSelf = self else {
|
||||
@@ -415,9 +408,40 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
case .estabilished:
|
||||
break
|
||||
default:
|
||||
if case let .estabilished(_, clientParams, _, ssrcs, ssrcMapping) = internalState {
|
||||
self.ssrcMapping = ssrcMapping
|
||||
if case let .estabilished(callInfo, clientParams, _, initialState) = internalState {
|
||||
self.ssrcMapping.removeAll()
|
||||
var ssrcs: [UInt32] = []
|
||||
for participant in initialState.participants {
|
||||
self.ssrcMapping[participant.ssrc] = participant.peer.id
|
||||
ssrcs.append(participant.ssrc)
|
||||
}
|
||||
self.callContext?.setJoinResponse(payload: clientParams, ssrcs: ssrcs)
|
||||
|
||||
let participantsContext = GroupCallParticipantsContext(
|
||||
account: self.accountContext.account,
|
||||
id: callInfo.id,
|
||||
accessHash: callInfo.accessHash,
|
||||
state: initialState
|
||||
)
|
||||
self.participantsContext = participantsContext
|
||||
self.participantsContextStateDisposable.set((participantsContext.state
|
||||
|> deliverOnMainQueue).start(next: { [weak self] state in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
|
||||
var memberStates: [PeerId: PresentationGroupCallMemberState] = [:]
|
||||
for participant in state.participants {
|
||||
strongSelf.ssrcMapping[participant.ssrc] = participant.peer.id
|
||||
|
||||
memberStates[participant.peer.id] = PresentationGroupCallMemberState(
|
||||
ssrc: participant.ssrc,
|
||||
muteState: participant.muteState
|
||||
)
|
||||
}
|
||||
strongSelf.membersValue = memberStates
|
||||
}))
|
||||
|
||||
if let isCurrentlyConnecting = self.isCurrentlyConnecting, isCurrentlyConnecting {
|
||||
self.startCheckingCallIfNeeded()
|
||||
}
|
||||
@@ -429,7 +453,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
if self.checkCallDisposable != nil {
|
||||
return
|
||||
}
|
||||
if case let .estabilished(callInfo, _, ssrc, _, _) = self.internalState {
|
||||
if case let .estabilished(callInfo, _, ssrc, _) = self.internalState {
|
||||
let checkSignal = checkGroupCall(account: self.account, callId: callInfo.id, accessHash: callInfo.accessHash, ssrc: Int32(bitPattern: ssrc))
|
||||
|
||||
self.checkCallDisposable = ((
|
||||
@@ -463,7 +487,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
}
|
||||
|
||||
public func leave() -> Signal<Bool, NoError> {
|
||||
if case let .estabilished(callInfo, _, _, _, _) = self.internalState {
|
||||
if case let .estabilished(callInfo, _, _, _) = self.internalState {
|
||||
self.leaveDisposable.set((leaveGroupCall(account: self.account, callId: callInfo.id, accessHash: callInfo.accessHash)
|
||||
|> deliverOnMainQueue).start(completed: { [weak self] in
|
||||
self?._canBeRemoved.set(.single(true))
|
||||
@@ -500,6 +524,10 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
}
|
||||
}
|
||||
|
||||
public func updateMuteState(peerId: PeerId, isMuted: Bool) {
|
||||
self.participantsContext?.updateMuteState(peerId: peerId, muteState: isMuted ? GroupCallParticipantsContext.Participant.MuteState(canUnmute: peerId == self.accountContext.account.peerId) : nil)
|
||||
}
|
||||
|
||||
private func requestCall() {
|
||||
self.callContext?.stop()
|
||||
self.callContext = nil
|
||||
@@ -531,7 +559,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
}
|
||||
}
|
||||
|
||||
let restartedCall = currentOrRequestedCall
|
||||
/*let restartedCall = currentOrRequestedCall
|
||||
|> mapToSignal { value -> Signal<GroupCallInfo, CallError> in
|
||||
let stopped: Signal<GroupCallInfo, CallError> = stopGroupCall(account: account, callId: value.id, accessHash: value.accessHash)
|
||||
|> mapError { _ -> CallError in
|
||||
@@ -542,7 +570,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
|
||||
return stopped
|
||||
|> then(currentOrRequestedCall)
|
||||
}
|
||||
}*/
|
||||
|
||||
self.requestDisposable.set((currentOrRequestedCall
|
||||
|> deliverOnMainQueue).start(next: { [weak self] value in
|
||||
@@ -554,9 +582,13 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
||||
}
|
||||
|
||||
public func invitePeer(_ peerId: PeerId) {
|
||||
guard case let .estabilished(callInfo, _, _, _, _) = self.internalState else {
|
||||
guard case let .estabilished(callInfo, _, _, _) = self.internalState, !self.invitedPeersValue.contains(peerId) else {
|
||||
return
|
||||
}
|
||||
|
||||
var updatedInvitedPeers = self.invitedPeersValue
|
||||
updatedInvitedPeers.insert(peerId)
|
||||
self.invitedPeersValue = updatedInvitedPeers
|
||||
|
||||
let _ = inviteToGroupCall(account: self.account, callId: callInfo.id, accessHash: callInfo.accessHash, peerId: peerId).start()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user