diff --git a/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj b/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj new file mode 100644 index 0000000..ffc4158 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj @@ -0,0 +1,382 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 77; + objects = { + +/* Begin PBXBuildFile section */ + B301E4C82CA5338900775259 /* Sora in Frameworks */ = {isa = PBXBuildFile; productRef = B301E4C72CA5338900775259 /* Sora */; }; + B301E4CA2CA5338900775259 /* WebRTC in Frameworks */ = {isa = PBXBuildFile; productRef = B301E4C92CA5338900775259 /* WebRTC */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + B301E4AD2CA52C3200775259 /* SendOnly.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SendOnly.app; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ + B301E4C32CA52F1200775259 /* Exceptions for "SendOnly" folder in "SendOnly" target */ = { + isa = PBXFileSystemSynchronizedBuildFileExceptionSet; + membershipExceptions = ( + Environment.example.swift, + ); + target = B301E4AC2CA52C3200775259 /* SendOnly */; + }; +/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */ + +/* Begin PBXFileSystemSynchronizedRootGroup section */ + B301E4AF2CA52C3200775259 /* SendOnly */ = { + isa = PBXFileSystemSynchronizedRootGroup; + exceptions = ( + B301E4C32CA52F1200775259 /* Exceptions for "SendOnly" folder in "SendOnly" target */, + ); + path = SendOnly; + sourceTree = ""; + }; +/* End PBXFileSystemSynchronizedRootGroup section */ + +/* Begin PBXFrameworksBuildPhase section */ + B301E4AA2CA52C3200775259 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + B301E4C82CA5338900775259 /* Sora in Frameworks */, + B301E4CA2CA5338900775259 /* WebRTC in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + B301E4A42CA52C3200775259 = { + isa = PBXGroup; + children = ( + B301E4AF2CA52C3200775259 /* SendOnly */, + B301E4AE2CA52C3200775259 /* Products */, + ); + sourceTree = ""; + }; + B301E4AE2CA52C3200775259 /* Products */ = { + isa = PBXGroup; + children = ( + B301E4AD2CA52C3200775259 /* SendOnly.app */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + B301E4AC2CA52C3200775259 /* SendOnly */ = { + isa = PBXNativeTarget; + buildConfigurationList = B301E4BB2CA52C3400775259 /* Build configuration list for PBXNativeTarget "SendOnly" */; + buildPhases = ( + B301E4A92CA52C3200775259 /* Sources */, + B301E4AA2CA52C3200775259 /* Frameworks */, + B301E4AB2CA52C3200775259 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + fileSystemSynchronizedGroups = ( + B301E4AF2CA52C3200775259 /* SendOnly */, + ); + name = SendOnly; + packageProductDependencies = ( + B301E4C72CA5338900775259 /* Sora */, + B301E4C92CA5338900775259 /* WebRTC */, + ); + productName = SendOnly; + productReference = B301E4AD2CA52C3200775259 /* SendOnly.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + B301E4A52CA52C3200775259 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1600; + LastUpgradeCheck = 1600; + TargetAttributes = { + B301E4AC2CA52C3200775259 = { + CreatedOnToolsVersion = 16.0; + }; + }; + }; + buildConfigurationList = B301E4A82CA52C3200775259 /* Build configuration list for PBXProject "SendOnly" */; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = B301E4A42CA52C3200775259; + minimizedProjectReferenceProxies = 1; + packageReferences = ( + B301E4C62CA5338900775259 /* XCRemoteSwiftPackageReference "sora-ios-sdk" */, + ); + preferredProjectObjectVersion = 77; + productRefGroup = B301E4AE2CA52C3200775259 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + B301E4AC2CA52C3200775259 /* SendOnly */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + B301E4AB2CA52C3200775259 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + B301E4A92CA52C3200775259 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + B301E4B92CA52C3400775259 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.0; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + B301E4BA2CA52C3400775259 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.0; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + B301E4BC2CA52C3400775259 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"SendOnly/Preview Content\""; + DEVELOPMENT_TEAM = D7MQUAK3LC; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSCameraUsageDescription = WebRTC; + INFOPLIST_KEY_NSMicrophoneUsageDescription = WebRTC; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = jp.shiguredo.SendOnly; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + B301E4BD2CA52C3400775259 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"SendOnly/Preview Content\""; + DEVELOPMENT_TEAM = D7MQUAK3LC; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSCameraUsageDescription = WebRTC; + INFOPLIST_KEY_NSMicrophoneUsageDescription = WebRTC; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = jp.shiguredo.SendOnly; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + B301E4A82CA52C3200775259 /* Build configuration list for PBXProject "SendOnly" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + B301E4B92CA52C3400775259 /* Debug */, + B301E4BA2CA52C3400775259 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + B301E4BB2CA52C3400775259 /* Build configuration list for PBXNativeTarget "SendOnly" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + B301E4BC2CA52C3400775259 /* Debug */, + B301E4BD2CA52C3400775259 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + B301E4C62CA5338900775259 /* XCRemoteSwiftPackageReference "sora-ios-sdk" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/shiguredo/sora-ios-sdk"; + requirement = { + branch = "feature/swiftui-view"; + kind = branch; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + B301E4C72CA5338900775259 /* Sora */ = { + isa = XCSwiftPackageProductDependency; + package = B301E4C62CA5338900775259 /* XCRemoteSwiftPackageReference "sora-ios-sdk" */; + productName = Sora; + }; + B301E4C92CA5338900775259 /* WebRTC */ = { + isa = XCSwiftPackageProductDependency; + package = B301E4C62CA5338900775259 /* XCRemoteSwiftPackageReference "sora-ios-sdk" */; + productName = WebRTC; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = B301E4A52CA52C3200775259 /* Project object */; +} diff --git a/SwiftUI/SendOnly/SendOnly/Assets.xcassets/AccentColor.colorset/Contents.json b/SwiftUI/SendOnly/SendOnly/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUI/SendOnly/SendOnly/Assets.xcassets/AppIcon.appiconset/Contents.json b/SwiftUI/SendOnly/SendOnly/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..2305880 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,35 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "tinted" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUI/SendOnly/SendOnly/Assets.xcassets/Contents.json b/SwiftUI/SendOnly/SendOnly/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift new file mode 100644 index 0000000..480f882 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -0,0 +1,129 @@ +import SwiftUI +import Sora + +// 接続状態 +enum ConnectionState { + case connecting // 接続試行 + case connected // 接続 + case disconnected //切断 +} + +struct ContentView: View { + @State private var mediaChannel: MediaChannel? + + @State private var senderStream: MediaStream? + @State private var showsAlert = false + @State private var connectionError: Error? + @State private var connectionState: ConnectionState = .disconnected // 接続状態を管理 + + // connectionMode が manual のときは以下の State で映像制御を実装する必要がある + @State private var isVideoStopped: Bool = false // Video描画の停止管理 + @State private var isVideoClear: Bool = false // Video描画をクリアして背景を表示させるフラグ + + var body: some View { + VStack { + ZStack { + SwiftUIVideoView( + senderStream, + isStop: $isVideoStopped, + isClear: $isVideoClear + ) + .videoAspect(.fill) + .connectionMode(.manual) // NOTE: mode によって、view の autoStop 時の挙動が変わる(default: .autoClear + .ignoresSafeArea() + VStack { + Spacer() + HStack { + Button { + connect() + } label: { + Text("接続") + .font(.title) + } + .disabled(connectionState == .connecting || connectionState == .connected) // 接続試行中 or 接続中は無効化 + + + Button { + disconnect() + } label: { + Text("切断") + .font(.title) + } + .disabled(connectionState == .connecting || connectionState == .disconnected) // 接続試行中 or 切断中は無効化 + + Button { + toggleVideo() + } label: { + Text("映像表示切替") + .font(.title) + } + } + }.padding() + } + .alert("エラー", isPresented: $showsAlert, actions: { + Button("OK") { + showsAlert = false + connectionError = nil + } + }, message: { + if let error = connectionError { + Text(error.localizedDescription) + } else { + Text("エラー内容不明") + } + }) + } + } + + func connect() { + if connectionState == .connected { + print("Already connected.") + return + } + + connectionState = .connecting // 接続処理中に設定 + + var config = Configuration( + urlCandidates: AppEnvironment.urls, + channelId: AppEnvironment.channelId, + role: .sendonly, + multistreamEnabled: true) + config.signalingConnectMetadata = AppEnvironment.signalingConnectMetadata + + _ = Sora.shared.connect(configuration: config) { mediaChannel, error in + if let error = error { + connectionError = error + showsAlert = true + connectionState = .disconnected // 接続失敗したので、状態を切断中に更新 + print("Error: \(error)") + } else { + self.mediaChannel = mediaChannel + senderStream = self.mediaChannel?.senderStream + connectionState = .connected + } + } + } + + func disconnect() { + if connectionState == .disconnected { + print("Already disconnected.") + return + } + guard let mediaChannel = self.mediaChannel else { + return + } + mediaChannel.disconnect(error: nil) + self.mediaChannel = nil + self.senderStream = nil + self.connectionState = .disconnected + } + + func toggleVideo() { + isVideoStopped.toggle() + isVideoClear.toggle() + } +} + +#Preview { + ContentView() +} diff --git a/SwiftUI/SendOnly/SendOnly/Environment.example.swift b/SwiftUI/SendOnly/SendOnly/Environment.example.swift new file mode 100644 index 0000000..859643d --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/Environment.example.swift @@ -0,0 +1,13 @@ +import Foundation + +enum AppEnvironment { + // 接続するサーバーのシグナリング URL + // 配列で複数の URL を指定することが可能です + static let urls = [URL(string: "wss://sora.example.com/signaling")!] + + // チャネル ID + static let channelId = "sora" + + // type: connect に含めるメタデータ + static let signalingConnectMetadata: Encodable? = nil +} diff --git a/SwiftUI/SendOnly/SendOnly/Preview Content/Preview Assets.xcassets/Contents.json b/SwiftUI/SendOnly/SendOnly/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUI/SendOnly/SendOnly/Sandbox.swift b/SwiftUI/SendOnly/SendOnly/Sandbox.swift new file mode 100644 index 0000000..b6b7572 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/Sandbox.swift @@ -0,0 +1,79 @@ +import SwiftUI +import UIKit + +// UIKitでnameとisEnabledを管理し、UILabelでテキストを表示 +class UIKitView: UIView { + private let label: UILabel + var isEnabled: Bool = false { + didSet { + updateText() + } + } + + override init(frame: CGRect) { + label = UILabel(frame: .zero) + super.init(frame: frame) + setupView() + updateText() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupView() { + addSubview(label) + label.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + label.centerXAnchor.constraint(equalTo: self.centerXAnchor), + label.centerYAnchor.constraint(equalTo: self.centerYAnchor), + ]) + } + + // isEnabledの値に応じて表示されるテキストを変更 + private func updateText() { + label.text = isEnabled ? "zztkm" : "not zztkm" + } +} + +// UIViewRepresentableでUIKitViewをSwiftUIに統合 +struct RepresentedUIKitView: UIViewRepresentable { + @Binding var isEnabled: Bool + + func makeUIView(context: Context) -> UIKitView { + let uiKitView = UIKitView() + uiKitView.isEnabled = isEnabled + return uiKitView + } + + func updateUIView(_ uiView: UIKitView, context: Context) { + uiView.isEnabled = isEnabled + } +} + +// MySubViewでRepresentedUIKitViewを描画 +struct MySubView: View { + @Binding var isEnabled: Bool + + var body: some View { + RepresentedUIKitView(isEnabled: $isEnabled) // UIKitViewの表示 + } +} + +// SandboxViewでToggleを制御し、MySubViewに変更を伝達 +struct SandboxView: View { + @State private var isEnabled = false + + var body: some View { + VStack { + Toggle("Enabled", isOn: $isEnabled) // ToggleでisEnabledを制御 + MySubView(isEnabled: $isEnabled) // MySubViewにisEnabledを渡す + } + .padding() + } +} + +// Preview +#Preview { + SandboxView() +} diff --git a/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift b/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift new file mode 100644 index 0000000..e993b0f --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift @@ -0,0 +1,10 @@ +import SwiftUI + +@main +struct SendOnlyApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/SwiftUI/VideoChatSample/SoraiOSSwiftUI/AppEnvironment.swift b/SwiftUI/VideoChatSample/SoraiOSSwiftUI/AppEnvironment.swift new file mode 100644 index 0000000..5e40059 --- /dev/null +++ b/SwiftUI/VideoChatSample/SoraiOSSwiftUI/AppEnvironment.swift @@ -0,0 +1,13 @@ +import Foundation + +enum AppEnvironment { + // 接続するサーバーのシグナリング URL + // 配列で複数の URL を指定することが可能です + static let urls = [URL(string: "wss://0001.sora-zztkm.veltiosoft.dev/signaling")!] + + // チャネル ID + static let channelId = "sora" + + // type: connect に含めるメタデータ + static let signalingConnectMetadata: Encodable? = nil +}