Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to record screen when connecting #69

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RealityMixer/Capture/Model/MixedRealityConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct MixedRealityConfiguration: Codable, Equatable {
let visibility: BackgroundVisibility
}

let shouldRecord: Bool
let enableAudio: Bool
let enableAutoFocus: Bool
let enablePersonSegmentation: Bool
Expand All @@ -36,6 +37,7 @@ struct MixedRealityConfiguration: Codable, Equatable {
let backgroundLayerOptions: BackgroundLayerOptions

static let defaultConfiguration = MixedRealityConfiguration(
shouldRecord: true,
enableAudio: true,
enableAutoFocus: true,
enablePersonSegmentation: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
import ARKit
import ReplayKit
import SwiftSocket

final class MixedRealityConnectionViewController: UIViewController {
Expand All @@ -31,7 +32,10 @@ final class MixedRealityConnectionViewController: UIViewController {
@IBOutlet private weak var backgroundChromaKeySection: UIStackView!
@IBOutlet private weak var backgroundChromaKeySegmentedControl: UISegmentedControl!

@IBOutlet private weak var showOptionsButton: UIButton!
// MARK: - Recording options
@IBOutlet private weak var recordingSwitch: UISwitch!

@IBOutlet /*private*/ weak var showOptionsButton: UIButton!
@IBOutlet private weak var resetOptionsButton: UIButton!

@IBOutlet private weak var infoLabel: UILabel!
Expand Down Expand Up @@ -122,6 +126,7 @@ final class MixedRealityConnectionViewController: UIViewController {
}

private func didUpdate(configuration: MixedRealityConfiguration) {
recordingSwitch.isOn = configuration.shouldRecord
audioSwitch.isOn = configuration.enableAudio
autoFocusSwitch.isOn = configuration.enableAutoFocus
personSegmentationSwitch.isOn = configuration.enablePersonSegmentation
Expand Down Expand Up @@ -169,6 +174,7 @@ final class MixedRealityConnectionViewController: UIViewController {

private func updateConfiguration(enablePersonSegmentation: Bool) {
configuration = MixedRealityConfiguration(
shouldRecord: recordingSwitch.isOn,
enableAudio: audioSwitch.isOn,
enableAutoFocus: autoFocusSwitch.isOn,
enablePersonSegmentation: enablePersonSegmentation,
Expand Down Expand Up @@ -239,6 +245,12 @@ final class MixedRealityConnectionViewController: UIViewController {
let cameraPoseSender = CameraPoseSender(address: address)
let configuration = self.configuration

let screenRecorder = RPScreenRecorder.shared()
if configuration.shouldRecord, screenRecorder.isAvailable, !screenRecorder.isRecording {
// TODO: Present alert to the user if this fails
screenRecorder.startRecording(handler: nil)
}

connectionAlert.dismiss(animated: false, completion: { [weak self] in

let viewController = MixedRealityViewController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<outlet property="optionsStackView" destination="JdO-4j-7D3" id="hyp-LZ-l9o"/>
<outlet property="personSegmentationSwitch" destination="ipx-3g-qMd" id="rhy-1D-71z"/>
<outlet property="portTextField" destination="Lky-ae-zSD" id="2KE-UZ-PBo"/>
<outlet property="recordingSwitch" destination="ymb-A5-IkS" id="C0I-6D-bT7"/>
<outlet property="resetOptionsButton" destination="GAr-dN-Zdp" id="iS1-Qn-LAa"/>
<outlet property="scrollView" destination="Fl1-MX-Dh0" id="nAb-23-e3d"/>
<outlet property="secondInfoLabel" destination="i5n-Pa-HjL" id="phQ-wk-zIK"/>
Expand All @@ -44,10 +45,10 @@
<rect key="frame" x="0.0" y="0.0" width="1194" height="784"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BKZ-mI-AUe">
<rect key="frame" x="0.0" y="0.0" width="1194" height="1071.5"/>
<rect key="frame" x="0.0" y="0.0" width="1194" height="1147"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="ThD-0e-MfL">
<rect key="frame" x="347" y="40" width="500" height="991.5"/>
<rect key="frame" x="347" y="40" width="500" height="1067"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="WA0-LP-4eU">
<rect key="frame" x="0.0" y="0.0" width="500" height="52.5"/>
Expand Down Expand Up @@ -103,7 +104,7 @@
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="JdO-4j-7D3">
<rect key="frame" x="0.0" y="205" width="500" height="471.5"/>
<rect key="frame" x="0.0" y="205" width="500" height="547"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="r7d-A4-VaM">
<rect key="frame" x="0.0" y="0.0" width="500" height="178.5"/>
Expand Down Expand Up @@ -324,8 +325,37 @@
</stackView>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="fjT-hA-1gp">
<rect key="frame" x="0.0" y="431.5" width="500" height="55.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Recording Options" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sNZ-BC-aBj">
<rect key="frame" x="0.0" y="0.0" width="500" height="14.5"/>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="12"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5ns-uX-AfD">
<rect key="frame" x="0.0" y="24.5" width="500" height="31"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Start recording after connecting" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uzf-fp-d5C">
<rect key="frame" x="0.0" y="0.0" width="451" height="31"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="14"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ymb-A5-IkS">
<rect key="frame" x="451" y="0.0" width="51" height="31"/>
<color key="onTintColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="thumbTintColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<action selector="configurationValueDidChange:" destination="-1" eventType="valueChanged" id="uNo-gC-6il"/>
</connections>
</switch>
</subviews>
</stackView>
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="GAr-dN-Zdp" userLabel="Reset Options">
<rect key="frame" x="0.0" y="431.5" width="500" height="40"/>
<rect key="frame" x="0.0" y="507" width="500" height="40"/>
<color key="backgroundColor" white="0.10000000000000001" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="Z3Q-vf-CA3"/>
Expand All @@ -346,7 +376,7 @@
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zAL-RL-fM1">
<rect key="frame" x="0.0" y="696.5" width="500" height="40"/>
<rect key="frame" x="0.0" y="772" width="500" height="40"/>
<color key="backgroundColor" white="0.10000000000000001" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="gOQ-FN-r77"/>
Expand All @@ -365,20 +395,20 @@
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Bgm-b4-8r2">
<rect key="frame" x="0.0" y="756.5" width="500" height="1"/>
<rect key="frame" x="0.0" y="832" width="500" height="1"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="5cw-uV-ee1"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Info" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Cvo-ep-K0W">
<rect key="frame" x="0.0" y="777.5" width="500" height="18"/>
<rect key="frame" x="0.0" y="853" width="500" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ruk-RS-qSj">
<rect key="frame" x="0.0" y="815.5" width="500" height="40"/>
<rect key="frame" x="0.0" y="891" width="500" height="40"/>
<color key="backgroundColor" white="0.10000000000000001" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="Ke5-K4-nlc"/>
Expand All @@ -397,13 +427,13 @@
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Info" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="i5n-Pa-HjL">
<rect key="frame" x="0.0" y="875.5" width="500" height="18"/>
<rect key="frame" x="0.0" y="951" width="500" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cLW-1L-KGI">
<rect key="frame" x="0.0" y="913.5" width="500" height="40"/>
<rect key="frame" x="0.0" y="989" width="500" height="40"/>
<color key="backgroundColor" white="0.10000000000000001" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="dng-VS-vKF"/>
Expand All @@ -422,7 +452,7 @@
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Info" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IU3-yK-ZhP">
<rect key="frame" x="0.0" y="973.5" width="500" height="18"/>
<rect key="frame" x="0.0" y="1049" width="500" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
import ARKit
import ReplayKit
import AVFoundation
import SwiftSocket

Expand Down Expand Up @@ -314,7 +315,23 @@ final class MixedRealityViewController: UIViewController {

private func disconnect() {
invalidate()
dismiss(animated: false, completion: nil)

let parentViewController = (presentingViewController?.children.first as? MixedRealityConnectionViewController)

dismiss(animated: false, completion: {
let screenRecorder = RPScreenRecorder.shared()

if screenRecorder.isRecording {
screenRecorder.stopRecording(handler: { (previewViewController, error) in
// TODO: Present error alert to the user if this fails.
guard let previewViewController = previewViewController else { return }

// TODO: Set delegate
previewViewController.popoverPresentationController?.sourceView = parentViewController?.showOptionsButton
parentViewController?.present(previewViewController, animated: true, completion: nil)
})
}
})
}

@objc private func willResignActive() {
Expand Down