Merge branch 'develop' into phlpro/voicebroadcast-display-playback-duration

This commit is contained in:
Phl-Pro
2022-11-28 09:12:03 +01:00
committed by GitHub
28 changed files with 191 additions and 70 deletions
@@ -33,7 +33,7 @@ public protocol VoiceBroadcastAggregatorDelegate: AnyObject {
func voiceBroadcastAggregatorDidEndLoading(_ aggregator: VoiceBroadcastAggregator)
func voiceBroadcastAggregator(_ aggregator: VoiceBroadcastAggregator, didFailWithError: Error)
func voiceBroadcastAggregator(_ aggregator: VoiceBroadcastAggregator, didReceiveChunk: VoiceBroadcastChunk)
func voiceBroadcastAggregator(_ aggregator: VoiceBroadcastAggregator, didReceiveState: VoiceBroadcastInfo.State)
func voiceBroadcastAggregator(_ aggregator: VoiceBroadcastAggregator, didReceiveState: VoiceBroadcastInfoState)
func voiceBroadcastAggregatorDidUpdateData(_ aggregator: VoiceBroadcastAggregator)
}
@@ -64,7 +64,7 @@ public class VoiceBroadcastAggregator {
}
private(set) var launchState: VoiceBroadcastAggregatorLaunchState = .idle
public private(set) var voiceBroadcastState: VoiceBroadcastInfo.State
public private(set) var voiceBroadcastState: VoiceBroadcastInfoState
public var delegate: VoiceBroadcastAggregatorDelegate?
deinit {
@@ -73,7 +73,7 @@ public class VoiceBroadcastAggregator {
}
}
public init(session: MXSession, room: MXRoom, voiceBroadcastStartEventId: String, voiceBroadcastState: VoiceBroadcastInfo.State) throws {
public init(session: MXSession, room: MXRoom, voiceBroadcastStartEventId: String, voiceBroadcastState: VoiceBroadcastInfoState) throws {
self.session = session
self.room = room
self.voiceBroadcastStartEventId = voiceBroadcastStartEventId
@@ -118,7 +118,7 @@ public class VoiceBroadcastAggregator {
event.stateKey == self.voiceBroadcastSenderId,
let voiceBroadcastInfo = VoiceBroadcastInfo(fromJSON: event.content),
(event.eventId == self.voiceBroadcastStartEventId || voiceBroadcastInfo.voiceBroadcastId == self.voiceBroadcastStartEventId),
let state = VoiceBroadcastInfo.State(rawValue: voiceBroadcastInfo.state) else {
let state = VoiceBroadcastInfoState(rawValue: voiceBroadcastInfo.state) else {
return
}
@@ -19,36 +19,29 @@ import Foundation
extension VoiceBroadcastInfo {
// MARK: - Constants
public enum State: String {
case started
case paused
case resumed
case stopped
}
// MARK: - Public
@objc static func isStarted(for name: String) -> Bool {
return name == State.started.rawValue
return name == VoiceBroadcastInfoState.started.rawValue
}
@objc static func isStopped(for name: String) -> Bool {
return name == State.stopped.rawValue
return name == VoiceBroadcastInfoState.stopped.rawValue
}
@objc static func startedValue() -> String {
return State.started.rawValue
return VoiceBroadcastInfoState.started.rawValue
}
@objc static func pausedValue() -> String {
return State.paused.rawValue
return VoiceBroadcastInfoState.paused.rawValue
}
@objc static func resumedValue() -> String {
return State.resumed.rawValue
return VoiceBroadcastInfoState.resumed.rawValue
}
@objc static func stoppedValue() -> String {
return State.stopped.rawValue
return VoiceBroadcastInfoState.stopped.rawValue
}
}
@@ -0,0 +1,22 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
public enum VoiceBroadcastInfoState: String {
case started
case paused
case resumed
case stopped
}
@@ -25,13 +25,13 @@ public class VoiceBroadcastService: NSObject {
public let room: MXRoom
public private(set) var voiceBroadcastId: String?
public private(set) var state: VoiceBroadcastInfo.State
public private(set) var state: VoiceBroadcastInfoState
// Mechanism to process one call of sendVoiceBroadcastInfo() at a time
private let asyncTaskQueue: MXAsyncTaskQueue
// MARK: - Setup
public init(room: MXRoom, state: VoiceBroadcastInfo.State) {
public init(room: MXRoom, state: VoiceBroadcastInfoState) {
self.room = room
self.state = state
self.asyncTaskQueue = MXAsyncTaskQueue(label: "VoiceBroadcastServiceQueueEventSerialQueue-" + MXTools.generateSecret())
@@ -47,7 +47,7 @@ public class VoiceBroadcastService: NSObject {
/// - Parameters:
/// - completion: A closure called when the operation completes. Provides the event id of the event generated on the home server on success.
func startVoiceBroadcast(completion: @escaping (MXResponse<String?>) -> Void) {
sendVoiceBroadcastInfo(state: VoiceBroadcastInfo.State.started) { [weak self] response in
sendVoiceBroadcastInfo(state: VoiceBroadcastInfoState.started) { [weak self] response in
guard let self = self else { return }
switch response {
@@ -64,21 +64,21 @@ public class VoiceBroadcastService: NSObject {
/// - Parameters:
/// - completion: A closure called when the operation completes. Provides the event id of the event generated on the home server on success.
func pauseVoiceBroadcast(completion: @escaping (MXResponse<String?>) -> Void) {
sendVoiceBroadcastInfo(state: VoiceBroadcastInfo.State.paused, completion: completion)
sendVoiceBroadcastInfo(state: VoiceBroadcastInfoState.paused, completion: completion)
}
/// resume a voice broadcast.
/// - Parameters:
/// - completion: A closure called when the operation completes. Provides the event id of the event generated on the home server on success.
func resumeVoiceBroadcast(completion: @escaping (MXResponse<String?>) -> Void) {
sendVoiceBroadcastInfo(state: VoiceBroadcastInfo.State.resumed, completion: completion)
sendVoiceBroadcastInfo(state: VoiceBroadcastInfoState.resumed, completion: completion)
}
/// stop a voice broadcast info.
/// - Parameters:
/// - completion: A closure called when the operation completes. Provides the event id of the event generated on the home server on success.
func stopVoiceBroadcast(completion: @escaping (MXResponse<String?>) -> Void) {
sendVoiceBroadcastInfo(state: VoiceBroadcastInfo.State.stopped, completion: completion)
sendVoiceBroadcastInfo(state: VoiceBroadcastInfoState.stopped, completion: completion)
}
func getState() -> String {
@@ -121,7 +121,7 @@ public class VoiceBroadcastService: NSObject {
// MARK: - Private
private func allowedStates(from state: VoiceBroadcastInfo.State) -> [VoiceBroadcastInfo.State] {
private func allowedStates(from state: VoiceBroadcastInfoState) -> [VoiceBroadcastInfoState] {
switch state {
case .started:
return [.paused, .stopped]
@@ -134,7 +134,7 @@ public class VoiceBroadcastService: NSObject {
}
}
private func sendVoiceBroadcastInfo(state: VoiceBroadcastInfo.State, completion: @escaping (MXResponse<String?>) -> Void) {
private func sendVoiceBroadcastInfo(state: VoiceBroadcastInfoState, completion: @escaping (MXResponse<String?>) -> Void) {
guard let userId = self.room.mxSession.myUserId else {
completion(.failure(VoiceBroadcastServiceError.missingUserId))
return
@@ -156,7 +156,7 @@ public class VoiceBroadcastService: NSObject {
voiceBroadcastInfo.state = state.rawValue
if state != VoiceBroadcastInfo.State.started {
if state != VoiceBroadcastInfoState.started {
guard let voiceBroadcastId = self.voiceBroadcastId else {
completion(.failure(VoiceBroadcastServiceError.notStarted))
taskCompleted()