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.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/network-computer-ios.git
HTTPS
https://gitstable.com/git/askrobots/network-computer-ios.git
SSH
ssh://git@gitstable.com:2222/askrobots/network-computer-ios.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Dan Quellhorst First cut of the iPhone client cc1f67f 2 months ago History
VideoView.swift · 1.6 KB · 58 lines
1import SwiftUI
2import WebRTC
3
4/// Metal-backed renderer for the remote desktop.
5struct VideoView: UIViewRepresentable {
6 let track: RTCVideoTrack?
7
8 func makeUIView(context: Context) -> RTCMTLVideoView {
9 let v = RTCMTLVideoView()
10 v.videoContentMode = .scaleAspectFit
11 v.backgroundColor = .black
12 return v
13 }
14
15 func updateUIView(_ v: RTCMTLVideoView, context: Context) {
16 if context.coordinator.track !== track {
17 context.coordinator.track?.remove(v)
18 track?.add(v)
19 context.coordinator.track = track
20 }
21 }
22
23 func makeCoordinator() -> Coordinator { Coordinator() }
24 final class Coordinator { var track: RTCVideoTrack? }
25}
26
27struct TrackpadRepresentable: UIViewRepresentable {
28 let trackpadMode: Bool
29 let send: (InputEvent) -> Void
30
31 func makeUIView(context: Context) -> TrackpadView {
32 let v = TrackpadView(frame: .zero)
33 v.send = send
34 return v
35 }
36 func updateUIView(_ v: TrackpadView, context: Context) {
37 v.trackpadMode = trackpadMode
38 v.send = send
39 }
40}
41
42struct KeyCaptureRepresentable: UIViewRepresentable {
43 @Binding var active: Bool
44 let send: (InputEvent) -> Void
45
46 func makeUIView(context: Context) -> KeyCaptureView {
47 let v = KeyCaptureView(frame: .zero)
48 v.send = send
49 return v
50 }
51 func updateUIView(_ v: KeyCaptureView, context: Context) {
52 v.send = send
53 DispatchQueue.main.async {
54 if active, !v.isFirstResponder { v.becomeFirstResponder() }
55 if !active, v.isFirstResponder { v.resignFirstResponder() }
56 }
57 }
58}