mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 18:42:47 +02:00
Rename some existing voice broadcast files to VoiceBroadcastPlayback
Record will happen in separate files
This commit is contained in:
+116
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// Copyright 2021 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.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import MatrixSDK
|
||||
import SwiftUI
|
||||
|
||||
struct VoiceBroadcastPlaybackControllerParameters {
|
||||
let session: MXSession
|
||||
let room: MXRoom
|
||||
let voiceBroadcastStartEvent: MXEvent
|
||||
}
|
||||
|
||||
final class VoiceBroadcastPlaybackController: Coordinator, Presentable, VoiceBroadcastAggregatorDelegate {
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let parameters: VoiceBroadcastPlaybackControllerParameters
|
||||
private let selectedAnswerIdentifiersSubject = PassthroughSubject<[String], Never>()
|
||||
|
||||
private var voiceBroadcastAggregator: VoiceBroadcastAggregator
|
||||
private var viewModel: VoiceBroadcastPlaybackViewModelProtocol!
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
// MARK: Public
|
||||
|
||||
// Must be used only internally
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(parameters: VoiceBroadcastPlaybackControllerParameters) throws {
|
||||
self.parameters = parameters
|
||||
|
||||
try voiceBroadcastAggregator = VoiceBroadcastAggregator(session: parameters.session, room: parameters.room, voiceBroadcastStartEventId: parameters.voiceBroadcastStartEvent.eventId)
|
||||
voiceBroadcastAggregator.delegate = self
|
||||
|
||||
viewModel = VoiceBroadcastPlaybackViewModel(VoiceBroadcastPlaybackDetails: buildVoiceBroadcastPlaybackFrom(voiceBroadcastAggregator.voiceBroadcast))
|
||||
|
||||
viewModel.completion = { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch result {
|
||||
case .played:
|
||||
// TODO: VB Add player and playing chunk files
|
||||
MXLog.debug("click on play")
|
||||
case .paused:
|
||||
// TODO: VB stop playing chunk files
|
||||
MXLog.debug("click on pause")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func start() { }
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
VectorHostingController(rootView: VoiceBroadcastPlaybackView(viewModel: viewModel.context),
|
||||
forceZeroSafeAreaInsets: true)
|
||||
}
|
||||
|
||||
func canEndVoiceBroadcast() -> Bool {
|
||||
// TODO: VB check is voicebroadcast stopped
|
||||
return false
|
||||
}
|
||||
|
||||
func canEditVoiceBroadcast() -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func endVoiceBroadcast() {}
|
||||
|
||||
// MARK: - VoiceBroadcastAggregatorDelegate
|
||||
|
||||
func voiceBroadcastAggregatorDidUpdateData(_ aggregator: VoiceBroadcastAggregator) {
|
||||
viewModel.updateWithVoiceBroadcastDetails(buildVoiceBroadcastPlaybackFrom(aggregator.voiceBroadcast))
|
||||
}
|
||||
|
||||
func voiceBroadcastAggregatorDidStartLoading(_ aggregator: VoiceBroadcastAggregator) { }
|
||||
|
||||
func voiceBroadcastAggregatorDidEndLoading(_ aggregator: VoiceBroadcastAggregator) { }
|
||||
|
||||
func voiceBroadcastAggregator(_ aggregator: VoiceBroadcastAggregator, didFailWithError: Error) { }
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
// VoiceBroadcast is intentionally not available in the SwiftUI target as we don't want
|
||||
// to add the SDK as a dependency to it. We need to translate from one to the other on this level.
|
||||
func buildVoiceBroadcastPlaybackFrom(_ voiceBroadcast: VoiceBroadcast) -> VoiceBroadcastPlaybackDetails {
|
||||
|
||||
return VoiceBroadcastPlaybackDetails(type: voiceBroadcastKindToVoiceBroadcastPlaybackType(voiceBroadcast.kind), chunks: Array(voiceBroadcast.chunks))
|
||||
}
|
||||
|
||||
private func voiceBroadcastKindToVoiceBroadcastPlaybackType(_ kind: VoiceBroadcastKind) -> VoiceBroadcastPlaybackType {
|
||||
let mapping = [VoiceBroadcastKind.player: VoiceBroadcastPlaybackType.player,
|
||||
VoiceBroadcastKind.recorder: VoiceBroadcastPlaybackType.recorder]
|
||||
|
||||
return mapping[kind] ?? .player
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class VoiceBroadcastPlaybackProvider {
|
||||
static let shared = VoiceBroadcastPlaybackProvider()
|
||||
|
||||
var session: MXSession?
|
||||
var coordinatorsForEventIdentifiers = [String: VoiceBroadcastPlaybackController]()
|
||||
|
||||
private init() { }
|
||||
|
||||
/// Create or retrieve the voiceBroadcast timeline coordinator for this event and return
|
||||
/// a view to be displayed in the timeline
|
||||
func buildVoiceBroadcastPlaybackViewForEvent(_ event: MXEvent) -> UIView? {
|
||||
guard let session = session, let room = session.room(withRoomId: event.roomId) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if let coordinator = coordinatorsForEventIdentifiers[event.eventId] {
|
||||
return coordinator.toPresentable().view
|
||||
}
|
||||
|
||||
let parameters = VoiceBroadcastPlaybackControllerParameters(session: session, room: room, voiceBroadcastStartEvent: event)
|
||||
guard let coordinator = try? VoiceBroadcastPlaybackController(parameters: parameters) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
coordinatorsForEventIdentifiers[event.eventId] = coordinator
|
||||
|
||||
return coordinator.toPresentable().view
|
||||
}
|
||||
|
||||
/// Retrieve the voiceBroadcast timeline coordinator for the given event or nil if it hasn't been created yet
|
||||
func voiceBroadcastPlaybackControllerForEventIdentifier(_ eventIdentifier: String) -> VoiceBroadcastPlaybackController? {
|
||||
coordinatorsForEventIdentifiers[eventIdentifier]
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class VoiceBroadcastPlaybackService: VoiceBroadcastPlaybackServiceProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private(set) var voiceBroadcastChunks: [VoiceBroadcastChunk] = []
|
||||
private let roomId: String
|
||||
|
||||
// MARK: Private
|
||||
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var didUpdateVoiceBroadcastChunks: (([VoiceBroadcastChunk]) -> Void)?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(roomId: String) {
|
||||
self.roomId = roomId
|
||||
|
||||
updateVoiceBroadcastChunks(notifyUpdate: false)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func startPlayingVoiceBroadcast() {
|
||||
|
||||
}
|
||||
|
||||
func pausePlayingVoiceBroadcast() {
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func updateVoiceBroadcastChunks(notifyUpdate: Bool) {
|
||||
// TODO: VB udpate voicebroadcast chunks. We already have a listener on voicebroadcast events in VoiceBroadcastAggregator
|
||||
|
||||
if notifyUpdate {
|
||||
didUpdateVoiceBroadcastChunks?(voiceBroadcastChunks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
|
||||
protocol VoiceBroadcastPlaybackServiceProtocol {
|
||||
/// All shared voice broadcast chunks
|
||||
var voiceBroadcastChunks: [VoiceBroadcastChunk] { get }
|
||||
|
||||
/// Called when voice broadcast chunks are updated.
|
||||
var didUpdateVoiceBroadcastChunks: (([VoiceBroadcastChunk]) -> Void)? { get set }
|
||||
|
||||
func startPlayingVoiceBroadcast()
|
||||
|
||||
func pausePlayingVoiceBroadcast()
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct VoiceBroadcastPlaybackView: View {
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@ObservedObject var viewModel: VoiceBroadcastPlaybackViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
let voiceBroadcast = viewModel.viewState.voiceBroadcast
|
||||
|
||||
VStack(alignment: .leading, spacing: 16.0) {
|
||||
Text(VectorL10n.voiceBroadcastInTimelineTitle)
|
||||
.font(theme.fonts.bodySB)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
// Text(VectorL10n.voiceBroadcastInTimelineBody)
|
||||
// .font(theme.fonts.body)
|
||||
// .foregroundColor(theme.colors.primaryContent)
|
||||
|
||||
HStack(alignment: .top, spacing: 16.0) {
|
||||
Button { viewModel.send(viewAction: .play) } label: {
|
||||
Image("voice_broadcast_play")
|
||||
.renderingMode(.original)
|
||||
}
|
||||
.accessibilityIdentifier("playButton")
|
||||
|
||||
Button { viewModel.send(viewAction: .pause) } label: {
|
||||
Image("voice_broadcast_pause")
|
||||
.renderingMode(.original)
|
||||
}
|
||||
.accessibilityIdentifier("pauseButton")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
.padding([.horizontal, .top], 2.0)
|
||||
.padding([.bottom])
|
||||
.alert(item: $viewModel.alertInfo) { info in
|
||||
info.alert
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct VoiceBroadcastPlaybackView_Previews: PreviewProvider {
|
||||
static let stateRenderer = MockVoiceBroadcastPlaybackScreenState.stateRenderer
|
||||
static var previews: some View {
|
||||
stateRenderer.screenGroup()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
enum VoiceBroadcastPlaybackViewAction {
|
||||
case play
|
||||
case pause
|
||||
}
|
||||
|
||||
enum VoiceBroadcastPlaybackViewModelResult {
|
||||
// TODO: VB send all chunk file urls from ViewModel
|
||||
case played
|
||||
case paused
|
||||
}
|
||||
|
||||
enum VoiceBroadcastPlaybackType {
|
||||
case player
|
||||
case recorder
|
||||
}
|
||||
|
||||
struct VoiceBroadcastPlaybackDetails {
|
||||
var type: VoiceBroadcastPlaybackType
|
||||
var chunks: [VoiceBroadcastChunk]
|
||||
|
||||
// TODO: VB Add playback state
|
||||
}
|
||||
|
||||
struct VoiceBroadcastPlaybackViewState: BindableState {
|
||||
var voiceBroadcast: VoiceBroadcastPlaybackDetails
|
||||
var bindings: VoiceBroadcastPlaybackViewStateBindings
|
||||
}
|
||||
|
||||
struct VoiceBroadcastPlaybackViewStateBindings {
|
||||
var alertInfo: AlertInfo<VoiceBroadcastPlaybackAlertType>?
|
||||
}
|
||||
|
||||
enum VoiceBroadcastPlaybackAlertType {
|
||||
case failedClosingVoiceBroadcast
|
||||
}
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
/// Using an enum for the screen allows you define the different state cases with
|
||||
/// the relevant associated data for each case.
|
||||
enum MockVoiceBroadcastPlaybackScreenState: MockScreenState, CaseIterable {
|
||||
// A case for each state you want to represent
|
||||
// with specific, minimal associated data that will allow you
|
||||
// mock that screen.
|
||||
case animated
|
||||
|
||||
/// The associated screen
|
||||
var screenType: Any.Type {
|
||||
VoiceBroadcastPlaybackView.self
|
||||
}
|
||||
|
||||
/// A list of screen state definitions
|
||||
static var allCases: [MockVoiceBroadcastPlaybackScreenState] {
|
||||
[.animated]
|
||||
}
|
||||
|
||||
/// Generate the view struct for the screen state.
|
||||
var screenView: ([Any], AnyView) {
|
||||
let voiceBroadcast = VoiceBroadcastPlaybackDetails(type: VoiceBroadcastPlaybackType.player, chunks: [])
|
||||
|
||||
let viewModel = VoiceBroadcastPlaybackViewModel(VoiceBroadcastPlaybackDetails: voiceBroadcast)
|
||||
|
||||
return (
|
||||
[false, viewModel],
|
||||
AnyView(VoiceBroadcastPlaybackView(viewModel: viewModel.context))
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias VoiceBroadcastPlaybackViewModelType = StateStoreViewModel<VoiceBroadcastPlaybackViewState, VoiceBroadcastPlaybackViewAction>
|
||||
|
||||
class VoiceBroadcastPlaybackViewModel: VoiceBroadcastPlaybackViewModelType, VoiceBroadcastPlaybackViewModelProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var completion: ((VoiceBroadcastPlaybackViewModelResult) -> Void)?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(VoiceBroadcastPlaybackDetails: VoiceBroadcastPlaybackDetails) {
|
||||
super.init(initialViewState: VoiceBroadcastPlaybackViewState(voiceBroadcast: VoiceBroadcastPlaybackDetails, bindings: VoiceBroadcastPlaybackViewStateBindings()))
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: VoiceBroadcastPlaybackViewAction) {
|
||||
switch viewAction {
|
||||
case .play:
|
||||
play()
|
||||
case .pause:
|
||||
pause()
|
||||
}
|
||||
}
|
||||
|
||||
/// Listen voice broadcast
|
||||
private func play() {
|
||||
// TODO: VB call voice broadcast playback service to play the chunks
|
||||
completion?(.played)
|
||||
}
|
||||
|
||||
/// Stop voice broadcast
|
||||
private func pause() {
|
||||
completion?(.paused)
|
||||
}
|
||||
|
||||
// MARK: - VoiceBroadcastPlaybackViewModelProtocol
|
||||
|
||||
func updateWithVoiceBroadcastDetails(_ voiceBroadcastDetails: VoiceBroadcastPlaybackDetails) {
|
||||
state.voiceBroadcast = voiceBroadcastDetails
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol VoiceBroadcastPlaybackViewModelProtocol {
|
||||
var context: VoiceBroadcastPlaybackViewModelType.Context { get }
|
||||
var completion: ((VoiceBroadcastPlaybackViewModelResult) -> Void)? { get set }
|
||||
|
||||
func updateWithVoiceBroadcastDetails(_ voiceBroadcastDetails: VoiceBroadcastPlaybackDetails)
|
||||
}
|
||||
Reference in New Issue
Block a user