From 50d5ff5ffac7b2f9db347c7e541288d61be8ad66 Mon Sep 17 00:00:00 2001 From: zztkm Date: Thu, 26 Sep 2024 15:01:41 +0900 Subject: [PATCH 01/13] =?UTF-8?q?=E5=88=9D=E6=9C=9F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SendOnly.xcodeproj/project.pbxproj | 344 ++++++++++++++++++ .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 35 ++ .../SendOnly/Assets.xcassets/Contents.json | 6 + SwiftUI/SendOnly/SendOnly/ContentView.swift | 24 ++ .../SendOnly/Environment.example.swift | 13 + .../Preview Assets.xcassets/Contents.json | 6 + SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift | 17 + 8 files changed, 456 insertions(+) create mode 100644 SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj create mode 100644 SwiftUI/SendOnly/SendOnly/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 SwiftUI/SendOnly/SendOnly/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 SwiftUI/SendOnly/SendOnly/Assets.xcassets/Contents.json create mode 100644 SwiftUI/SendOnly/SendOnly/ContentView.swift create mode 100644 SwiftUI/SendOnly/SendOnly/Environment.example.swift create mode 100644 SwiftUI/SendOnly/SendOnly/Preview Content/Preview Assets.xcassets/Contents.json create mode 100644 SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift diff --git a/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj b/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj new file mode 100644 index 0000000..e9fd957 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj @@ -0,0 +1,344 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 77; + objects = { + +/* 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 = ( + ); + 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 = ( + ); + 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; + 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\""; + 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\""; + 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 */ + }; + 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..6092cd6 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -0,0 +1,24 @@ +// +// ContentView.swift +// SendOnly +// +// Created by zztkm on 2024/09/26. +// + +import SwiftUI + +struct ContentView: View { + var body: some View { + VStack { + Image(systemName: "globe") + .imageScale(.large) + .foregroundStyle(.tint) + Text("Hello, world!") + } + .padding() + } +} + +#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/SendOnlyApp.swift b/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift new file mode 100644 index 0000000..de9069c --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift @@ -0,0 +1,17 @@ +// +// SendOnlyApp.swift +// SendOnly +// +// Created by zztkm on 2024/09/26. +// + +import SwiftUI + +@main +struct SendOnlyApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} From 88ae4b9ac5393f6aa30178c019431ab3feb46dc6 Mon Sep 17 00:00:00 2001 From: zztkm Date: Thu, 26 Sep 2024 17:21:47 +0900 Subject: [PATCH 02/13] =?UTF-8?q?SendOnly=20=E3=82=B5=E3=83=B3=E3=83=97?= =?UTF-8?q?=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SendOnly.xcodeproj/project.pbxproj | 38 ++++++++ SwiftUI/SendOnly/SendOnly/ContentView.swift | 95 ++++++++++++++++--- .../SendOnly/SendOnly/SoraSDKManager.swift | 65 +++++++++++++ 3 files changed, 186 insertions(+), 12 deletions(-) create mode 100644 SwiftUI/SendOnly/SendOnly/SoraSDKManager.swift diff --git a/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj b/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj index e9fd957..e707051 100644 --- a/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj +++ b/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj @@ -6,6 +6,11 @@ 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 */ @@ -36,6 +41,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + B301E4C82CA5338900775259 /* Sora in Frameworks */, + B301E4CA2CA5338900775259 /* WebRTC in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -78,6 +85,8 @@ ); name = SendOnly; packageProductDependencies = ( + B301E4C72CA5338900775259 /* Sora */, + B301E4C92CA5338900775259 /* WebRTC */, ); productName = SendOnly; productReference = B301E4AD2CA52C3200775259 /* SendOnly.app */; @@ -107,6 +116,9 @@ ); mainGroup = B301E4A42CA52C3200775259; minimizedProjectReferenceProxies = 1; + packageReferences = ( + B301E4C62CA5338900775259 /* XCRemoteSwiftPackageReference "sora-ios-sdk" */, + ); preferredProjectObjectVersion = 77; productRefGroup = B301E4AE2CA52C3200775259 /* Products */; projectDirPath = ""; @@ -265,6 +277,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"SendOnly/Preview Content\""; + DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSCameraUsageDescription = WebRTC; @@ -295,6 +308,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"SendOnly/Preview Content\""; + DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSCameraUsageDescription = WebRTC; @@ -339,6 +353,30 @@ 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/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index 6092cd6..d9f42ab 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -1,21 +1,92 @@ -// -// ContentView.swift -// SendOnly -// -// Created by zztkm on 2024/09/26. -// - import SwiftUI +import Sora struct ContentView: View { + @State private var senderStream: MediaStream? + // アラートを表示するための状態管理変数 + @State private var showsAlert = false + // 接続時のエラー + @State private var connectionError: Error? + + var mediaChannel: MediaChannel? { + SoraSDKManager.shared.currentMediaChannel + } + var body: some View { VStack { - Image(systemName: "globe") - .imageScale(.large) - .foregroundStyle(.tint) - Text("Hello, world!") + ZStack { + Video(senderStream) + .videoAspect(.fill) + // この中の要素は画面下に寄せる + VStack { + Spacer() + HStack { + Button { + connect() + } label: { + Text("接続") + .font(.title) + } + Button { + disconnect() + } 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("エラー内容不明") + } + }) } - .padding() + } + + func connect() { + var config = Configuration( + urlCandidates: AppEnvironment.urls, + channelId: AppEnvironment.channelId, + role: .sendonly, + multistreamEnabled: true) + config.signalingConnectMetadata = AppEnvironment.signalingConnectMetadata + + // mediaChannel のイベントハンドラ + config.mediaChannelHandlers.onConnect = { error in + if error != nil { + self.connectionError = error + self.showsAlert = true + print("Error: \(error!)") + } + // 接続に成功した場合、senderStream がセットされているので senderStream にセットする + self.senderStream = self.mediaChannel?.senderStream + } + + // Sora 接続処理 + SoraSDKManager.shared.connect(config: config) { error in + if let error { + self.connectionError = error + self.showsAlert = true + print("Error: \(error)") + } else { + print("Connected") + } + } + } + + func disconnect() { + // ここで self.senderStream = nil しなくても、disconnet() した時点で nil になる + SoraSDKManager.shared.disconnect() } } diff --git a/SwiftUI/SendOnly/SendOnly/SoraSDKManager.swift b/SwiftUI/SendOnly/SendOnly/SoraSDKManager.swift new file mode 100644 index 0000000..fd33360 --- /dev/null +++ b/SwiftUI/SendOnly/SendOnly/SoraSDKManager.swift @@ -0,0 +1,65 @@ +import Foundation +import Sora + +/** + Sora SDK関連の、アプリケーション全体で共通して行いたい処理を行うシングルトン・マネージャ・クラスです。 + + このようなクラスを用意しておくと、Sora SDKのConnectionをアプリケーション全体で一つだけ確実に管理する事が可能になるため、おすすめです。 + */ +class SoraSDKManager { + /** + SoraSDKManagerのシングルトンインスタンスです。 + */ + static let shared = SoraSDKManager() + + /** + 現在接続中のSora SDKのMediaChannelです。 + + 殆どの場合、アプリケーション全体で一つだけ同時にMediaChannelに接続することになるので、シングルトンとして用意すると便利に使えます。 + */ + private(set) var currentMediaChannel: MediaChannel? + + /** + シングルトンにしたいので、イニシャライザはprivateにしてあります。 + */ + private init() { + // SDK のログを表示します。 + // 送受信されるシグナリングの内容や接続エラーを確認できます。 + Logger.shared.level = .debug + } + + /** + 新たにSoraに接続を試みます。接続に成功した場合、currentMediaChannelが更新されます。 + + 既に接続されており、currentMediaChannelが設定されている場合は新たに接続ができないようにしてあります。 + その場合は、一旦先に `disconnect()` を呼び出して、現在の接続を終了してください。 + */ + func connect(config: Configuration, completionHandler: ((Error?) -> Void)?) { + // 既にcurrentMediaChannelが設定されている場合は、接続済みとみなし、何もしないで終了します。 + guard currentMediaChannel == nil else { + return + } + + // Soraに接続を試みます。 + _ = Sora.shared.connect(configuration: config) { [weak self] mediaChannel, error in + // 接続に成功した場合は、mediaChannelに値が返され、errorがnilになります。 + // 一方、接続に失敗した場合は、mediaChannelはnilとなり、errorが返されます。 + self?.currentMediaChannel = mediaChannel + completionHandler?(error) + NSLog("[sample] mediaChannel.connectedUrl: \(String(describing: mediaChannel?.connectedUrl))") + } + } + + /** + 既に接続済みのmediaChannelから切断します。 + + currentMediaChannelがnilで、まだ接続されていないときは、何もしないで終了します。 + */ + func disconnect() { + guard let mediaChannel = currentMediaChannel else { + return + } + mediaChannel.disconnect(error: nil) + currentMediaChannel = nil + } +} From c7881fcab0c3dcf78575ec79831231248118ff1c Mon Sep 17 00:00:00 2001 From: zztkm Date: Thu, 26 Sep 2024 19:34:08 +0900 Subject: [PATCH 03/13] =?UTF-8?q?SoraSDKManager=20=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 48 +++++++++----- .../SendOnly/SendOnly/SoraSDKManager.swift | 65 ------------------- 2 files changed, 32 insertions(+), 81 deletions(-) delete mode 100644 SwiftUI/SendOnly/SendOnly/SoraSDKManager.swift diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index d9f42ab..8094a08 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -2,14 +2,16 @@ import SwiftUI import Sora struct ContentView: View { + @State private var mediaChannel: MediaChannel? + @State private var senderStream: MediaStream? // アラートを表示するための状態管理変数 @State private var showsAlert = false // 接続時のエラー @State private var connectionError: Error? - - var mediaChannel: MediaChannel? { - SoraSDKManager.shared.currentMediaChannel + // 接続状態 + private var isConnected: Bool { + mediaChannel?.isAvailable ?? false } var body: some View { @@ -26,13 +28,13 @@ struct ContentView: View { } label: { Text("接続") .font(.title) - } + }.disabled(isConnected) Button { disconnect() } label: { Text("切断") .font(.title) - } + }.disabled(!isConnected) } }.padding() @@ -54,13 +56,18 @@ struct ContentView: View { } func connect() { + if isConnected { + print("Already connected.") + return + } + var config = Configuration( urlCandidates: AppEnvironment.urls, channelId: AppEnvironment.channelId, role: .sendonly, multistreamEnabled: true) config.signalingConnectMetadata = AppEnvironment.signalingConnectMetadata - + // mediaChannel のイベントハンドラ config.mediaChannelHandlers.onConnect = { error in if error != nil { @@ -71,22 +78,31 @@ struct ContentView: View { // 接続に成功した場合、senderStream がセットされているので senderStream にセットする self.senderStream = self.mediaChannel?.senderStream } - - // Sora 接続処理 - SoraSDKManager.shared.connect(config: config) { error in - if let error { - self.connectionError = error - self.showsAlert = true + + // Soraに接続を試みます。 + _ = Sora.shared.connect(configuration: config) { mediaChannel, error in + // 接続に成功した場合は、mediaChannelに値が返され、errorがnilになります。 + // 一方、接続に失敗した場合は、mediaChannelはnilとなり、errorが返されます。 + if let error = error { + connectionError = error + showsAlert = true print("Error: \(error)") - } else { - print("Connected") } + self.mediaChannel = mediaChannel } } func disconnect() { - // ここで self.senderStream = nil しなくても、disconnet() した時点で nil になる - SoraSDKManager.shared.disconnect() + if isConnected == false { + print("Already disconnected.") + return + } + guard let mediaChannel = self.mediaChannel else { + return + } + mediaChannel.disconnect(error: nil) + self.mediaChannel = nil + self.senderStream = nil } } diff --git a/SwiftUI/SendOnly/SendOnly/SoraSDKManager.swift b/SwiftUI/SendOnly/SendOnly/SoraSDKManager.swift deleted file mode 100644 index fd33360..0000000 --- a/SwiftUI/SendOnly/SendOnly/SoraSDKManager.swift +++ /dev/null @@ -1,65 +0,0 @@ -import Foundation -import Sora - -/** - Sora SDK関連の、アプリケーション全体で共通して行いたい処理を行うシングルトン・マネージャ・クラスです。 - - このようなクラスを用意しておくと、Sora SDKのConnectionをアプリケーション全体で一つだけ確実に管理する事が可能になるため、おすすめです。 - */ -class SoraSDKManager { - /** - SoraSDKManagerのシングルトンインスタンスです。 - */ - static let shared = SoraSDKManager() - - /** - 現在接続中のSora SDKのMediaChannelです。 - - 殆どの場合、アプリケーション全体で一つだけ同時にMediaChannelに接続することになるので、シングルトンとして用意すると便利に使えます。 - */ - private(set) var currentMediaChannel: MediaChannel? - - /** - シングルトンにしたいので、イニシャライザはprivateにしてあります。 - */ - private init() { - // SDK のログを表示します。 - // 送受信されるシグナリングの内容や接続エラーを確認できます。 - Logger.shared.level = .debug - } - - /** - 新たにSoraに接続を試みます。接続に成功した場合、currentMediaChannelが更新されます。 - - 既に接続されており、currentMediaChannelが設定されている場合は新たに接続ができないようにしてあります。 - その場合は、一旦先に `disconnect()` を呼び出して、現在の接続を終了してください。 - */ - func connect(config: Configuration, completionHandler: ((Error?) -> Void)?) { - // 既にcurrentMediaChannelが設定されている場合は、接続済みとみなし、何もしないで終了します。 - guard currentMediaChannel == nil else { - return - } - - // Soraに接続を試みます。 - _ = Sora.shared.connect(configuration: config) { [weak self] mediaChannel, error in - // 接続に成功した場合は、mediaChannelに値が返され、errorがnilになります。 - // 一方、接続に失敗した場合は、mediaChannelはnilとなり、errorが返されます。 - self?.currentMediaChannel = mediaChannel - completionHandler?(error) - NSLog("[sample] mediaChannel.connectedUrl: \(String(describing: mediaChannel?.connectedUrl))") - } - } - - /** - 既に接続済みのmediaChannelから切断します。 - - currentMediaChannelがnilで、まだ接続されていないときは、何もしないで終了します。 - */ - func disconnect() { - guard let mediaChannel = currentMediaChannel else { - return - } - mediaChannel.disconnect(error: nil) - currentMediaChannel = nil - } -} From 280f40a95d875e7e0d6c33b8755853fd54d7ec1a Mon Sep 17 00:00:00 2001 From: zztkm Date: Thu, 26 Sep 2024 19:37:55 +0900 Subject: [PATCH 04/13] =?UTF-8?q?=E6=98=A0=E5=83=8F=E6=8F=8F=E7=94=BB?= =?UTF-8?q?=E3=82=92=E7=94=BB=E9=9D=A2=E5=85=A8=E4=BD=93=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index 8094a08..6f83dd5 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -19,6 +19,7 @@ struct ContentView: View { ZStack { Video(senderStream) .videoAspect(.fill) + .ignoresSafeArea() // この中の要素は画面下に寄せる VStack { Spacer() From 6e92d1720c34bff58d39994bff68be7fde0434b6 Mon Sep 17 00:00:00 2001 From: zztkm Date: Fri, 27 Sep 2024 10:03:58 +0900 Subject: [PATCH 05/13] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=B3?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift | 7 ------- 1 file changed, 7 deletions(-) diff --git a/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift b/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift index de9069c..e993b0f 100644 --- a/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift +++ b/SwiftUI/SendOnly/SendOnly/SendOnlyApp.swift @@ -1,10 +1,3 @@ -// -// SendOnlyApp.swift -// SendOnly -// -// Created by zztkm on 2024/09/26. -// - import SwiftUI @main From 5d61d11f471fa307c4e28d4130f4e6b2efa36cb0 Mon Sep 17 00:00:00 2001 From: zztkm Date: Fri, 27 Sep 2024 12:00:23 +0900 Subject: [PATCH 06/13] =?UTF-8?q?Sora=20=E3=81=A8=E3=81=AE=E6=8E=A5?= =?UTF-8?q?=E7=B6=9A=E7=8A=B6=E6=85=8B=E3=82=92=E7=AE=A1=E7=90=86=E3=81=99?= =?UTF-8?q?=E3=82=8B=20State=20=E3=82=92=201=20=E3=81=A4=E3=81=AB=E3=81=BE?= =?UTF-8?q?=E3=81=A8=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 53 ++++++++++++--------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index 6f83dd5..55fbed3 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -1,18 +1,23 @@ import SwiftUI import Sora +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? - // 接続状態 - private var isConnected: Bool { - mediaChannel?.isAvailable ?? false - } + @State private var connectionState: ConnectionState = .disconnected // 接続状態を管理 var body: some View { VStack { @@ -20,7 +25,6 @@ struct ContentView: View { Video(senderStream) .videoAspect(.fill) .ignoresSafeArea() - // この中の要素は画面下に寄せる VStack { Spacer() HStack { @@ -29,18 +33,20 @@ struct ContentView: View { } label: { Text("接続") .font(.title) - }.disabled(isConnected) + } + .disabled(connectionState == .connecting || connectionState == .connected) // 接続試行中 or 接続中は無効化 + + Button { disconnect() } label: { Text("切断") .font(.title) - }.disabled(!isConnected) + } + .disabled(connectionState == .connecting || connectionState == .disconnected) // 接続試行中 or 切断中は無効化 } }.padding() - } - // 何らかのエラー時にアラートを表示します。 .alert("エラー", isPresented: $showsAlert, actions: { Button("OK") { showsAlert = false @@ -57,11 +63,13 @@ struct ContentView: View { } func connect() { - if isConnected { + if connectionState == .connected { print("Already connected.") return } + connectionState = .connecting // 接続処理中に設定 + var config = Configuration( urlCandidates: AppEnvironment.urls, channelId: AppEnvironment.channelId, @@ -69,32 +77,32 @@ struct ContentView: View { multistreamEnabled: true) config.signalingConnectMetadata = AppEnvironment.signalingConnectMetadata - // mediaChannel のイベントハンドラ config.mediaChannelHandlers.onConnect = { error in - if error != nil { + if let error = error { self.connectionError = error self.showsAlert = true - print("Error: \(error!)") + self.connectionState = .disconnected // 接続に失敗したので、状態を切断中に更新 + print("Error: \(error)") + } else { + self.senderStream = self.mediaChannel?.senderStream + self.connectionState = .connected } - // 接続に成功した場合、senderStream がセットされているので senderStream にセットする - self.senderStream = self.mediaChannel?.senderStream } - // Soraに接続を試みます。 _ = Sora.shared.connect(configuration: config) { mediaChannel, error in - // 接続に成功した場合は、mediaChannelに値が返され、errorがnilになります。 - // 一方、接続に失敗した場合は、mediaChannelはnilとなり、errorが返されます。 if let error = error { connectionError = error showsAlert = true + connectionState = .disconnected // 接続失敗したので、状態を切断中に更新 print("Error: \(error)") + } else { + self.mediaChannel = mediaChannel } - self.mediaChannel = mediaChannel } } func disconnect() { - if isConnected == false { + if connectionState == .disconnected { print("Already disconnected.") return } @@ -104,6 +112,7 @@ struct ContentView: View { mediaChannel.disconnect(error: nil) self.mediaChannel = nil self.senderStream = nil + self.connectionState = .disconnected } } From 6d93c1abc1f7b4ca6ec43814fc7f3be8f53a4f7f Mon Sep 17 00:00:00 2001 From: zztkm Date: Fri, 27 Sep 2024 12:15:19 +0900 Subject: [PATCH 07/13] =?UTF-8?q?=E6=8E=A5=E7=B6=9A=E5=BE=8C=E3=81=AE?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=20Sora.connect=20=E3=81=AE=E6=96=B9?= =?UTF-8?q?=E3=81=AB=E5=AF=84=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index 55fbed3..baa69c3 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -77,18 +77,6 @@ struct ContentView: View { multistreamEnabled: true) config.signalingConnectMetadata = AppEnvironment.signalingConnectMetadata - config.mediaChannelHandlers.onConnect = { error in - if let error = error { - self.connectionError = error - self.showsAlert = true - self.connectionState = .disconnected // 接続に失敗したので、状態を切断中に更新 - print("Error: \(error)") - } else { - self.senderStream = self.mediaChannel?.senderStream - self.connectionState = .connected - } - } - _ = Sora.shared.connect(configuration: config) { mediaChannel, error in if let error = error { connectionError = error @@ -97,6 +85,8 @@ struct ContentView: View { print("Error: \(error)") } else { self.mediaChannel = mediaChannel + senderStream = self.mediaChannel?.senderStream + connectionState = .connected } } } From 2dd24886832fe0a260d4505e59a1ca4ccaf62ea5 Mon Sep 17 00:00:00 2001 From: zztkm Date: Mon, 30 Sep 2024 12:41:52 +0900 Subject: [PATCH 08/13] =?UTF-8?q?SwiftUIVideoView=20=E3=81=B8=E3=81=AE=20r?= =?UTF-8?q?ename=20=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index baa69c3..d96a422 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -22,7 +22,7 @@ struct ContentView: View { var body: some View { VStack { ZStack { - Video(senderStream) + SwiftUIVideoView(senderStream) .videoAspect(.fill) .ignoresSafeArea() VStack { From 6e5f58210b3ff06c21e09498aa36b700f0614fb9 Mon Sep 17 00:00:00 2001 From: zztkm Date: Wed, 2 Oct 2024 10:51:39 +0900 Subject: [PATCH 09/13] =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=81=97=E3=81=9F=20im?= =?UTF-8?q?port=20=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index d96a422..056b278 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -1,9 +1,6 @@ import SwiftUI import Sora -import SwiftUI -import Sora - // 接続状態 enum ConnectionState { case connecting // 接続試行 @@ -18,7 +15,6 @@ struct ContentView: View { @State private var showsAlert = false @State private var connectionError: Error? @State private var connectionState: ConnectionState = .disconnected // 接続状態を管理 - var body: some View { VStack { ZStack { From 4c2175c23c8bf8f5c20081bba99fbe872c51faad Mon Sep 17 00:00:00 2001 From: zztkm Date: Wed, 2 Oct 2024 19:01:40 +0900 Subject: [PATCH 10/13] =?UTF-8?q?videoStop=20=E5=8B=95=E4=BD=9C=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index 056b278..75cf07d 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -15,10 +15,13 @@ struct ContentView: View { @State private var showsAlert = false @State private var connectionError: Error? @State private var connectionState: ConnectionState = .disconnected // 接続状態を管理 + + @State private var isVideoStopped: Bool = false // Video描画の停止管理 + var body: some View { VStack { ZStack { - SwiftUIVideoView(senderStream) + SwiftUIVideoView(senderStream, stopVideo: $isVideoStopped) .videoAspect(.fill) .ignoresSafeArea() VStack { @@ -40,6 +43,13 @@ struct ContentView: View { .font(.title) } .disabled(connectionState == .connecting || connectionState == .disconnected) // 接続試行中 or 切断中は無効化 + + Button { + isVideoStopped.toggle() + } label: { + Text("映像表示切替") + .font(.title) + } } }.padding() } From e2fe9f38a6a6b0b45c06f274c16eb22426e14d8f Mon Sep 17 00:00:00 2001 From: zztkm Date: Thu, 3 Oct 2024 11:24:51 +0900 Subject: [PATCH 11/13] =?UTF-8?q?=E7=A2=BA=E8=AA=8D=E7=94=A8=E3=81=AB=20co?= =?UTF-8?q?nnectionMode=20=E3=81=A7=20manual=20=E3=82=92=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit このとき、VideoView の start method を実行しても映像が描画されなかった --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index 75cf07d..79ba0ee 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -23,6 +23,8 @@ struct ContentView: View { ZStack { SwiftUIVideoView(senderStream, stopVideo: $isVideoStopped) .videoAspect(.fill) + .videoOnRender(perform: self.videoOnRender) + .connectionMode(.manual) // NOTE: mode によって、view の autoStop 時の挙動が変わる(default: .autoClear .ignoresSafeArea() VStack { Spacer() @@ -68,6 +70,10 @@ struct ContentView: View { } } + func videoOnRender(frame: VideoFrame?) -> Void { + //print("zztkm: videoOnRender") + } + func connect() { if connectionState == .connected { print("Already connected.") From 386fad4eb63260272399ced954f1d363bb5a6aef Mon Sep 17 00:00:00 2001 From: zztkm Date: Mon, 7 Oct 2024 19:32:40 +0900 Subject: [PATCH 12/13] =?UTF-8?q?isClear=20=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUI/SendOnly/SendOnly/ContentView.swift | 8 +++++++- SwiftUI/SendOnly/SendOnly/Sandbox.swift | 0 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 SwiftUI/SendOnly/SendOnly/Sandbox.swift diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index 79ba0ee..3fbe797 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -17,11 +17,16 @@ struct ContentView: View { @State private var connectionState: ConnectionState = .disconnected // 接続状態を管理 @State private var isVideoStopped: Bool = false // Video描画の停止管理 + @State private var isVideoClear: Bool = false // Video描画をクリアして背景を表示させるフラグ var body: some View { VStack { ZStack { - SwiftUIVideoView(senderStream, stopVideo: $isVideoStopped) + SwiftUIVideoView( + senderStream, + isStop: $isVideoStopped, + isClear: $isVideoClear + ) .videoAspect(.fill) .videoOnRender(perform: self.videoOnRender) .connectionMode(.manual) // NOTE: mode によって、view の autoStop 時の挙動が変わる(default: .autoClear @@ -48,6 +53,7 @@ struct ContentView: View { Button { isVideoStopped.toggle() + isVideoClear.toggle() } label: { Text("映像表示切替") .font(.title) diff --git a/SwiftUI/SendOnly/SendOnly/Sandbox.swift b/SwiftUI/SendOnly/SendOnly/Sandbox.swift new file mode 100644 index 0000000..e69de29 From af220e8650a5319e222915546519c800ca1ee38b Mon Sep 17 00:00:00 2001 From: zztkm Date: Thu, 5 Dec 2024 12:33:46 +0900 Subject: [PATCH 13/13] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AA=E3=81=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SendOnly.xcodeproj/project.pbxproj | 4 +- SwiftUI/SendOnly/SendOnly/ContentView.swift | 14 ++-- SwiftUI/SendOnly/SendOnly/Sandbox.swift | 79 +++++++++++++++++++ .../SoraiOSSwiftUI/AppEnvironment.swift | 13 +++ 4 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 SwiftUI/VideoChatSample/SoraiOSSwiftUI/AppEnvironment.swift diff --git a/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj b/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj index e707051..ffc4158 100644 --- a/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj +++ b/SwiftUI/SendOnly/SendOnly.xcodeproj/project.pbxproj @@ -277,7 +277,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"SendOnly/Preview Content\""; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = D7MQUAK3LC; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSCameraUsageDescription = WebRTC; @@ -308,7 +308,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"SendOnly/Preview Content\""; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = D7MQUAK3LC; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSCameraUsageDescription = WebRTC; diff --git a/SwiftUI/SendOnly/SendOnly/ContentView.swift b/SwiftUI/SendOnly/SendOnly/ContentView.swift index 3fbe797..480f882 100644 --- a/SwiftUI/SendOnly/SendOnly/ContentView.swift +++ b/SwiftUI/SendOnly/SendOnly/ContentView.swift @@ -16,6 +16,7 @@ struct ContentView: View { @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描画をクリアして背景を表示させるフラグ @@ -28,7 +29,6 @@ struct ContentView: View { isClear: $isVideoClear ) .videoAspect(.fill) - .videoOnRender(perform: self.videoOnRender) .connectionMode(.manual) // NOTE: mode によって、view の autoStop 時の挙動が変わる(default: .autoClear .ignoresSafeArea() VStack { @@ -52,8 +52,7 @@ struct ContentView: View { .disabled(connectionState == .connecting || connectionState == .disconnected) // 接続試行中 or 切断中は無効化 Button { - isVideoStopped.toggle() - isVideoClear.toggle() + toggleVideo() } label: { Text("映像表示切替") .font(.title) @@ -76,10 +75,6 @@ struct ContentView: View { } } - func videoOnRender(frame: VideoFrame?) -> Void { - //print("zztkm: videoOnRender") - } - func connect() { if connectionState == .connected { print("Already connected.") @@ -122,6 +117,11 @@ struct ContentView: View { self.senderStream = nil self.connectionState = .disconnected } + + func toggleVideo() { + isVideoStopped.toggle() + isVideoClear.toggle() + } } #Preview { diff --git a/SwiftUI/SendOnly/SendOnly/Sandbox.swift b/SwiftUI/SendOnly/SendOnly/Sandbox.swift index e69de29..b6b7572 100644 --- a/SwiftUI/SendOnly/SendOnly/Sandbox.swift +++ 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/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 +}