Group call experiment

This commit is contained in:
Ali
2022-02-18 20:13:43 +04:00
parent 738dbd2b7c
commit fabc273e16
8 changed files with 218 additions and 30 deletions

View File

@@ -1,5 +1,17 @@
import SwiftSignalKit
import Postbox
import TelegramApi
import MtProtoKit
public struct EngineCallStreamState {
public struct Channel {
public var id: Int32
public var scale: Int32
public var latestTimestamp: Int64
}
public var channels: [Channel]
}
public extension TelegramEngine {
final class Calls {
@@ -21,8 +33,8 @@ public extension TelegramEngine {
return _internal_getCurrentGroupCall(account: self.account, callId: callId, accessHash: accessHash, peerId: peerId)
}
public func createGroupCall(peerId: PeerId, title: String?, scheduleDate: Int32?) -> Signal<GroupCallInfo, CreateGroupCallError> {
return _internal_createGroupCall(account: self.account, peerId: peerId, title: title, scheduleDate: scheduleDate)
public func createGroupCall(peerId: PeerId, title: String?, scheduleDate: Int32?, isExternalStream: Bool) -> Signal<GroupCallInfo, CreateGroupCallError> {
return _internal_createGroupCall(account: self.account, peerId: peerId, title: title, scheduleDate: scheduleDate, isExternalStream: isExternalStream)
}
public func startScheduledGroupCall(peerId: PeerId, callId: Int64, accessHash: Int64) -> Signal<GroupCallInfo, StartScheduledGroupCallError> {
@@ -119,5 +131,28 @@ public extension TelegramEngine {
}
|> take(1)
}
public func requestStreamState(callId: Int64, accessHash: Int64) -> Signal<EngineCallStreamState?, NoError> {
return self.account.network.request(Api.functions.phone.getGroupCallStreamChannels(call: .inputGroupCall(id: callId, accessHash: accessHash)))
|> mapToSignal { result -> Signal<EngineCallStreamState?, MTRpcError> in
switch result {
case let .groupCallStreamChannels(channels):
let state = EngineCallStreamState(channels: channels.map { channel -> EngineCallStreamState.Channel in
switch channel {
case let .groupCallStreamChannel(channel, scale, lastTimestampMs):
return EngineCallStreamState.Channel(id: channel, scale: scale, latestTimestamp: lastTimestampMs)
}
})
/*if state.channels.isEmpty {
return .fail(MTRpcError(errorCode: 500, errorDescription: "Generated")) |> delay(10.0, queue: .mainQueue())
}*/
return .single(state)
}
}
//|> restartIfError
|> `catch` { _ -> Signal<EngineCallStreamState?, NoError> in
return .single(nil)
}
}
}
}