askrobots / network-computer-ios
Public
iPhone client for network-computer: see and drive a remote Linux/Mac desktop over WebRTC, phone as trackpad and keyboard, desktop on a TV via AirPlay.
AppDelegate.swift · 1.8 KB · 43 lines
| 1 | import UIKit |
| 2 | import WebRTC |
| 3 | |
| 4 | @main |
| 5 | final class AppDelegate: UIResponder, UIApplicationDelegate { |
| 6 | func application(_ application: UIApplication, |
| 7 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { |
| 8 | RTCInitializeSSL() |
| 9 | // Route remote desktop audio to the speaker (or AirPlay/Bluetooth), not the earpiece. |
| 10 | let cfg = RTCAudioSessionConfiguration.webRTC() |
| 11 | cfg.category = AVAudioSession.Category.playAndRecord.rawValue |
| 12 | cfg.categoryOptions = [.defaultToSpeaker, .allowAirPlay, .allowBluetoothA2DP] |
| 13 | cfg.mode = AVAudioSession.Mode.default.rawValue |
| 14 | RTCAudioSessionConfiguration.setWebRTC(cfg) |
| 15 | return true |
| 16 | } |
| 17 | |
| 18 | // The main window and the external display (wired or AirPlay) get separate scene delegates. |
| 19 | func application(_ application: UIApplication, |
| 20 | configurationForConnecting session: UISceneSession, |
| 21 | options: UIScene.ConnectionOptions) -> UISceneConfiguration { |
| 22 | if session.role == .windowExternalDisplayNonInteractive { |
| 23 | let c = UISceneConfiguration(name: "External", sessionRole: session.role) |
| 24 | c.delegateClass = ExternalSceneDelegate.self |
| 25 | return c |
| 26 | } |
| 27 | let c = UISceneConfiguration(name: "Main", sessionRole: session.role) |
| 28 | c.delegateClass = SceneDelegate.self |
| 29 | return c |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | final class SceneDelegate: UIResponder, UIWindowSceneDelegate { |
| 34 | var window: UIWindow? |
| 35 | |
| 36 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options: UIScene.ConnectionOptions) { |
| 37 | guard let ws = scene as? UIWindowScene else { return } |
| 38 | let w = UIWindow(windowScene: ws) |
| 39 | w.rootViewController = RootViewController() |
| 40 | window = w |
| 41 | w.makeKeyAndVisible() |
| 42 | } |
| 43 | } |