mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-19 07:24:05 -05:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> - Add fallback support to HLS and MJPEG - Improve UI - Move WebRTC known issues disclaimer to a sheet view ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> <img width="3160" height="1068" alt="CleanShot 2026-01-12 at 15 43 49@2x" src="https://github.com/user-attachments/assets/77d445d7-88f0-40fb-8b0d-b1eab3c56e3d" /> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. --> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
61 lines
2.0 KiB
Swift
61 lines
2.0 KiB
Swift
import Shared
|
|
import SwiftUI
|
|
import UIKit
|
|
import WebRTC
|
|
|
|
class WebRTCVideoPlayerViewController: UIViewController {
|
|
private let viewModel: WebRTCViewPlayerViewModel
|
|
private var remoteVideoView: RTCMTLVideoView!
|
|
|
|
var onVideoStarted: (() -> Void)?
|
|
|
|
init(viewModel: WebRTCViewPlayerViewModel) {
|
|
self.viewModel = viewModel
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
@available(*, unavailable)
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
setupVideoView()
|
|
viewModel.start()
|
|
if let client = viewModel.webRTCClient {
|
|
client.renderRemoteVideo(to: remoteVideoView)
|
|
}
|
|
}
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
super.viewWillDisappear(animated)
|
|
viewModel.webRTCClient?.closeConnection()
|
|
}
|
|
|
|
private func setupVideoView() {
|
|
remoteVideoView = RTCMTLVideoView(frame: view.bounds)
|
|
remoteVideoView.translatesAutoresizingMaskIntoConstraints = false
|
|
remoteVideoView.delegate = self
|
|
view.addSubview(remoteVideoView)
|
|
NSLayoutConstraint.activate([
|
|
remoteVideoView.topAnchor.constraint(equalTo: view.topAnchor),
|
|
remoteVideoView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
|
remoteVideoView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
remoteVideoView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
])
|
|
remoteVideoView.videoContentMode = .scaleAspectFit
|
|
remoteVideoView.backgroundColor = .black
|
|
}
|
|
}
|
|
|
|
extension WebRTCVideoPlayerViewController: RTCVideoViewDelegate {
|
|
func videoView(_ videoView: RTCVideoRenderer, didChangeVideoSize size: CGSize) {
|
|
// Hide loader when the first frame is rendered
|
|
DispatchQueue.main.async { [weak self] in
|
|
self?.viewModel.showLoader = false
|
|
self?.onVideoStarted?()
|
|
}
|
|
}
|
|
}
|