mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Group call experiment
This commit is contained in:
@@ -143,7 +143,7 @@ public enum CreateGroupCallError {
|
||||
case scheduledTooLate
|
||||
}
|
||||
|
||||
func _internal_createGroupCall(account: Account, peerId: PeerId, title: String?, scheduleDate: Int32?) -> Signal<GroupCallInfo, CreateGroupCallError> {
|
||||
func _internal_createGroupCall(account: Account, peerId: PeerId, title: String?, scheduleDate: Int32?, isExternalStream: Bool) -> Signal<GroupCallInfo, CreateGroupCallError> {
|
||||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||
let callPeer = transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
return callPeer
|
||||
@@ -160,6 +160,9 @@ func _internal_createGroupCall(account: Account, peerId: PeerId, title: String?,
|
||||
if let _ = scheduleDate {
|
||||
flags |= (1 << 1)
|
||||
}
|
||||
if isExternalStream {
|
||||
flags |= (1 << 2)
|
||||
}
|
||||
return account.network.request(Api.functions.phone.createGroupCall(flags: flags, peer: inputPeer, randomId: Int32.random(in: Int32.min ... Int32.max), title: title, scheduleDate: scheduleDate))
|
||||
|> mapError { error -> CreateGroupCallError in
|
||||
if error.errorDescription == "ANONYMOUS_CALLS_DISABLED" {
|
||||
@@ -433,7 +436,7 @@ public enum JoinGroupCallError {
|
||||
public struct JoinGroupCallResult {
|
||||
public enum ConnectionMode {
|
||||
case rtc
|
||||
case broadcast
|
||||
case broadcast(isExternalStream: Bool)
|
||||
}
|
||||
|
||||
public var callInfo: GroupCallInfo
|
||||
@@ -589,12 +592,16 @@ func _internal_joinGroupCall(account: Account, peerId: PeerId, joinAs: PeerId?,
|
||||
let connectionMode: JoinGroupCallResult.ConnectionMode
|
||||
if let clientParamsData = parsedClientParams.data(using: .utf8), let dict = (try? JSONSerialization.jsonObject(with: clientParamsData, options: [])) as? [String: Any] {
|
||||
if let stream = dict["stream"] as? Bool, stream {
|
||||
connectionMode = .broadcast
|
||||
var isExternalStream = false
|
||||
if let rtmp = dict["rtmp"] as? Bool, rtmp {
|
||||
isExternalStream = true
|
||||
}
|
||||
connectionMode = .broadcast(isExternalStream: isExternalStream)
|
||||
} else {
|
||||
connectionMode = .rtc
|
||||
}
|
||||
} else {
|
||||
connectionMode = .broadcast
|
||||
connectionMode = .broadcast(isExternalStream: false)
|
||||
}
|
||||
|
||||
return account.postbox.transaction { transaction -> JoinGroupCallResult in
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user