oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2import SwiftUI
3
4/// Described calls for the offline snapshots of the call views (Mac, from
5/// CallsInterop) and the iPhone's UI test of its controls (a debug build
6/// launched with `-CallsCallFixture <name>`). No server, no media: the
7/// tiles show their placeholders, which is what an off-screen capture
8/// would show of video anyway.
9@_spi(Fixtures) public enum CallFixture: String, CaseIterable, Sendable {
10 /// One other person, muted, on the stage.
11 case focus
12 /// Four people in the call.
13 case grid
14 /// Somebody sharing a screen, with two cameras beside it, and you
15 /// sharing too.
16 case screen
17 /// Somebody waiting to be let in, and the connection coming back.
18 case notices
19 /// Two people who have just joined (spec §15.24): one still connecting
20 /// and unable to hear you yet, the other's browser blocking sound.
21 case connecting
22 /// The focus call in a meeting someone named: its title is shown,
23 /// centred where a window's title would be (CallTitle).
24 case named
25 /// Nobody else here yet: "Waiting for others", and you in the corner
26 /// (Paul's 0.4.6 screenshot, 2026-10-03).
27 case alone
28
29 public static let title = "Call, 24 Sep 10:21"
30 public static let namedTitle = "Board meeting"
31
32 @MainActor public func apply(to call: Call) {
33 let me = #"{"peer":"me","name":"Paul Campbell","kind":"member"}"#
34 let ana = #"{"peer":"ana","name":"Ana García","kind":"member","media":{"muted":true,"cameraOff":false}}"#
35 let tom = #"{"peer":"tom","name":"Tom Byrne","kind":"guest","media":{"muted":false,"cameraOff":true}}"#
36 let li = #"{"peer":"li","name":"Li Wei","kind":"member"}"#
37 func roster(_ phase: String, _ peers: [String], waiting: [String] = []) -> String {
38 #"{"phase":"\#(phase)","peer":"me","boot":"fixture","peers":[\#(peers.joined(separator: ","))],"waiting":[\#(waiting.joined(separator: ","))]}"#
39 }
40 switch self {
41 case .focus:
42 call.showFixture(title: Self.title, state: roster("admitted", [me, ana]))
43 case .grid:
44 call.showFixture(title: Self.title, state: roster("admitted", [me, ana, tom, li]))
45 case .screen:
46 call.showFixture(
47 title: Self.title, state: roster("admitted", [me, ana, tom, li]), screens: ["li"],
48 sharingScreen: true)
49 case .notices:
50 let knock = #"{"peer":"sam","name":"Sam Kelly","kind":"guest"}"#
51 call.showFixture(
52 title: Self.title, status: "Reconnecting…",
53 state: roster("reconnecting", [me, ana], waiting: [knock]), muted: true, floor: true)
54 case .connecting:
55 let sam = #"{"peer":"sam","name":"Samuel Okafor","kind":"member","media":{"muted":false,"cameraOff":false,"hearing":[]}}"#
56 let bea = #"{"peer":"bea","name":"Bea Ruiz","kind":"guest","media":{"muted":false,"cameraOff":true,"audioBlocked":true,"hearing":[]}}"#
57 call.showFixture(title: Self.title, state: roster("admitted", [me, ana, sam, bea]))
58 call.showFixtureConnecting(["sam", "bea"])
59 case .named:
60 call.showFixture(title: Self.namedTitle, state: roster("admitted", [me, ana]), named: true)
61 case .alone:
62 call.showFixture(title: Self.title, state: roster("admitted", [me]))
63 }
64 }
65}
66
67/// How loudly everyone is speaking, for the snapshots of the glow behind
68/// the names: silent, and low, middling and loud speech.
69@_spi(Fixtures) public enum FixtureSpeaking: String, CaseIterable, Sendable {
70 case silent, low, mid, high
71
72 public var decibels: Float {
73 switch self {
74 case .silent: -60
75 case .low: -29
76 case .mid: -21
77 case .high: -12
78 }
79 }
80
81 @MainActor public func apply(to call: Call) {
82 call.showFixtureSpeaking(level: pow(10, decibels / 20))
83 }
84}
85
86/// What the snapshots put behind the call's overlay in place of video, to
87/// show that the controls read over anything: black, white, and a busy
88/// frame with light and dark and colour and fine detail in it.
89@_spi(Fixtures) public enum FixtureBackdrop: String, CaseIterable, Sendable {
90 case black, white, busy
91}
92
93/// Your own state, for the snapshots of the controls in each.
94@_spi(Fixtures) public enum FixtureSelf: String, CaseIterable, Sendable {
95 case normal, muted, cameraOff, sharing
96
97 @MainActor public func apply(to call: Call) {
98 call.showFixtureSelf(
99 muted: self == .muted, cameraOff: self == .cameraOff, sharingScreen: self == .sharing)
100 }
101}
102
103extension FixtureBackdrop {
104 /// The frame itself, filling whatever it is given.
105 @_spi(Fixtures) @MainActor @ViewBuilder public var view: some View {
106 switch self {
107 case .black: Color.black
108 case .white: Color.white
109 case .busy: BusyFrame()
110 }
111 }
112}
113
114/// A stand-in for a busy picture: a bright window and a dark room, a
115/// saturated poster, and stripes as fine as a patterned shirt, across the
116/// whole frame so the bar and the pills each land on some of everything.
117private struct BusyFrame: View {
118 var body: some View {
119 GeometryReader { geometry in
120 let size = geometry.size
121 ZStack {
122 LinearGradient(
123 colors: [Color(white: 0.95), Color(red: 0.55, green: 0.42, blue: 0.3), Color(white: 0.08)],
124 startPoint: .topLeading, endPoint: .bottomTrailing)
125 Rectangle().fill(Color(red: 0.98, green: 0.85, blue: 0.2))
126 .frame(width: size.width * 0.28, height: size.height * 0.5)
127 .position(x: size.width * 0.2, y: size.height * 0.62)
128 Rectangle().fill(Color(red: 0.1, green: 0.35, blue: 0.85))
129 .frame(width: size.width * 0.22, height: size.height * 0.7)
130 .position(x: size.width * 0.72, y: size.height * 0.55)
131 HStack(spacing: 6) {
132 ForEach(0..<60, id: \.self) { index in
133 Rectangle().fill(index.isMultiple(of: 2) ? Color.white : Color.black)
134 .frame(width: 6)
135 }
136 }
137 .frame(width: size.width * 0.45, height: size.height * 0.35)
138 .position(x: size.width * 0.45, y: size.height * 0.88)
139 Circle().fill(Color(red: 0.9, green: 0.2, blue: 0.3))
140 .frame(width: size.height * 0.3)
141 .position(x: size.width * 0.9, y: size.height * 0.12)
142 }
143 .clipped()
144 }
145 }
146}
147
148private struct FixtureBackdropKey: EnvironmentKey {
149 static let defaultValue: FixtureBackdrop? = nil
150}
151
152extension EnvironmentValues {
153 /// A fixture's frame in place of the call's stage; nil in a real call.
154 @_spi(Fixtures) public var fixtureBackdrop: FixtureBackdrop? {
155 get { self[FixtureBackdropKey.self] }
156 set { self[FixtureBackdropKey.self] = newValue }
157 }
158}
159
160private struct FixtureStagePictureKey: EnvironmentKey {
161 static let defaultValue: FixtureBackdrop? = nil
162}
163
164extension EnvironmentValues {
165 /// A fixture's frame as the picture on the stage's tile, so snapshots of
166 /// Speaker view show how a picture sits under the filmstrip and the bar,
167 /// which a tile's placeholder cannot; nil in a real call.
168 @_spi(Fixtures) public var fixtureStagePicture: FixtureBackdrop? {
169 get { self[FixtureStagePictureKey.self] }
170 set { self[FixtureStagePictureKey.self] = newValue }
171 }
172}
173
174private struct FixtureFeedsKey: EnvironmentKey {
175 static let defaultValue: [String: CGSize] = [:]
176}
177
178extension EnvironmentValues {
179 /// Each fixture peer's picture size as displayed ("ana": 720 × 1280 for
180 /// a phone held upright), drawn in place of video on every tile that
181 /// peer has; "me" is your own. Empty in a real call.
182 @_spi(Fixtures) public var fixtureFeeds: [String: CGSize] {
183 get { self[FixtureFeedsKey.self] }
184 set { self[FixtureFeedsKey.self] = newValue }
185 }
186}
187
188@_spi(Fixtures) public enum FixtureFeeds {
189 /// "ana=720x1280,li=1280x720", as the iPhone's launch argument and the
190 /// snapshot harness give them.
191 public static func parse(_ text: String) -> [String: CGSize] {
192 var feeds: [String: CGSize] = [:]
193 for pair in text.split(separator: ",") {
194 let parts = pair.split(separator: "=")
195 guard parts.count == 2 else { continue }
196 let dims = parts[1].split(separator: "x").compactMap { Double($0) }
197 guard dims.count == 2, dims[0] > 0, dims[1] > 0 else { continue }
198 feeds[String(parts[0])] = CGSize(width: dims[0], height: dims[1])
199 }
200 return feeds
201 }
202}
203
204/// A fixture's frame drawn as a tile draws video: placed by
205/// `PlacedPicture` (a camera's 16:9 picture filling the tile with
206/// headroom, a screen's 16:10 fitted whole, and a camera of another shape
207/// than the tile — `video`, a phone's 720 × 1280 — fitted whole too) and,
208/// around a fitted picture, the same frame soft and dimmed as
209/// `ScreenBackdrop` draws it. A picture of its own size is the busy
210/// frame with a person in it, so the snapshots show what a crop cuts.
211@_spi(Fixtures) public struct FixtureVideo: View {
212 let picture: FixtureBackdrop
213 let video: CGSize?
214 let screen: Bool
215 let backdrop: Bool
216 public init(picture: FixtureBackdrop, video: CGSize? = nil, screen: Bool, backdrop: Bool = true) {
217 self.picture = picture
218 self.video = video
219 self.screen = screen
220 self.backdrop = backdrop
221 }
222 public var body: some View {
223 GeometryReader { geometry in
224 let bounds = geometry.size
225 let size = video ?? (screen ? CGSize(width: 16, height: 10) : CGSize(width: 16, height: 9))
226 let placed = Self.placement(video: size, screen: screen, in: bounds)
227 ZStack(alignment: .topLeading) {
228 if placed.fitted {
229 CallsAppearance.stageSurface
230 if backdrop {
231 // As ScreenBackdrop draws it: the picture filling the place,
232 // a little past its edges, soft (its 64-wide sample enlarged)
233 // and dimmed.
234 let filled = VideoFrame.place(video: size, in: bounds, fit: false)
235 frame
236 .frame(width: filled.width, height: filled.height)
237 .offset(x: filled.minX, y: filled.minY)
238 .scaleEffect(1.15)
239 .blur(radius: max(bounds.width, bounds.height) / 40)
240 .opacity(BackdropSampler.dimmed)
241 }
242 }
243 frame
244 .frame(width: placed.frame.width, height: placed.frame.height)
245 .offset(x: placed.frame.minX, y: placed.frame.minY)
246 }
247 }
248 .clipped()
249 }
250
251 @ViewBuilder private var frame: some View {
252 if video != nil {
253 ZStack {
254 picture.view
255 FixturePerson()
256 }
257 } else {
258 picture.view
259 }
260 }
261
262 /// Whether to place as 0.4.10 did, every camera filling: for the
263 /// before-and-after snapshots of portrait video (2026-10-21).
264 @MainActor public static var fillsEveryCamera = false
265
266 @MainActor static func placement(video: CGSize, screen: Bool, in bounds: CGSize) -> (frame: CGRect, fitted: Bool) {
267 if fillsEveryCamera, !screen {
268 return (VideoFrame.place(video: video, in: bounds, fit: false), false)
269 }
270 var placed = PlacedPicture(screen: screen)
271 placed.update(video: video)
272 return placed.place(in: bounds)
273 }
274}
275
276/// A head and shoulders, centred a little above the middle of whatever
277/// frame it is in, as a camera sees a person: the part a crop must keep.
278private struct FixturePerson: View {
279 var body: some View {
280 GeometryReader { geometry in
281 let size = geometry.size
282 let unit = min(size.width, size.height)
283 ZStack {
284 Ellipse().fill(Color(red: 0.24, green: 0.27, blue: 0.36))
285 .frame(width: unit * 0.9, height: unit * 0.55)
286 .position(x: size.width / 2, y: size.height * 0.4 + unit * 0.5)
287 Circle().fill(Color(red: 0.87, green: 0.68, blue: 0.55))
288 .frame(width: unit * 0.42)
289 .position(x: size.width / 2, y: size.height * 0.4)
290 Capsule().fill(Color(white: 0.15))
291 .frame(width: unit * 0.16, height: unit * 0.035)
292 .position(x: size.width / 2, y: size.height * 0.4 + unit * 0.1)
293 }
294 }
295 }
296}
297
298/// The warm rim on a tile's name at one level, over each kind of picture
299/// it has to read on (0.4.3): the rim mock-up's own dark and bright tiles,
300/// for comparing with it, then white and the busy frame. The name is the
301/// tiles' own `TileSpeakingName`, full size and compact.
302@_spi(Fixtures) public struct WarmRimGallery: View {
303 let level: FixtureSpeaking
304 @State private var glow = GlowLevel()
305 public init(level: FixtureSpeaking) { self.level = level }
306
307 public enum Picture: String, CaseIterable, Sendable { case mockDark, mockBright, white, busy }
308
309 public var body: some View {
310 VStack(spacing: 10) {
311 ForEach(Picture.allCases, id: \.self) { picture in
312 ZStack(alignment: .bottomLeading) {
313 Self.view(picture)
314 HStack(spacing: 12) {
315 TileSpeakingName(label: "Vicky Walsh", muted: false, compact: false, glow: glow)
316 TileSpeakingName(label: "Tony Keane", muted: false, compact: true, glow: glow)
317 }
318 .padding(14)
319 }
320 .frame(width: 360, height: 150)
321 .clipShape(RoundedRectangle(cornerRadius: 16))
322 }
323 }
324 .padding(10)
325 .onAppear { glow.showFixture(level: pow(10, level.decibels / 20)) }
326 }
327
328 @MainActor @ViewBuilder static func view(_ picture: Picture) -> some View {
329 switch picture {
330 case .mockDark:
331 // speaking-indicator-options/index.html's .tile, as near as SwiftUI
332 // draws its gradients.
333 ZStack {
334 LinearGradient(
335 stops: [
336 .init(color: Color(red: 0x3b / 255, green: 0x36 / 255, blue: 0x32 / 255), location: 0),
337 .init(color: Color(red: 0x1d / 255, green: 0x1b / 255, blue: 0x1a / 255), location: 0.6),
338 .init(color: Color(red: 0x12 / 255, green: 0x12 / 255, blue: 0x12 / 255), location: 1),
339 ], startPoint: .topLeading, endPoint: .bottomTrailing)
340 EllipticalGradient(
341 colors: [Color(red: 1, green: 214 / 255, blue: 170 / 255).opacity(0.35), .clear],
342 center: UnitPoint(x: 0.55, y: 0.4), startRadiusFraction: 0, endRadiusFraction: 0.5)
343 EllipticalGradient(
344 colors: [Color(red: 90 / 255, green: 110 / 255, blue: 140 / 255).opacity(0.45), .clear],
345 center: UnitPoint(x: 0.3, y: 0.8), startRadiusFraction: 0, endRadiusFraction: 0.35)
346 }
347 case .mockBright:
348 ZStack {
349 LinearGradient(
350 stops: [
351 .init(color: Color(red: 0xe9 / 255, green: 0xe4 / 255, blue: 0xdc / 255), location: 0),
352 .init(color: Color(red: 0xc9 / 255, green: 0xc2 / 255, blue: 0xb7 / 255), location: 0.6),
353 .init(color: Color(red: 0xa9 / 255, green: 0xa1 / 255, blue: 0x96 / 255), location: 1),
354 ], startPoint: .topLeading, endPoint: .bottomTrailing)
355 EllipticalGradient(
356 colors: [Color.white.opacity(0.9), .clear],
357 center: UnitPoint(x: 0.55, y: 0.4), startRadiusFraction: 0, endRadiusFraction: 0.5)
358 }
359 case .white: FixtureBackdrop.white.view
360 case .busy: FixtureBackdrop.busy.view
361 }
362 }
363}
364
365#if os(macOS)
366 /// Where the full-window call's control bar last laid out, in its
367 /// window's coordinates (top-left origin), for the bar layout gate
368 /// (`CallsInterop --bar-layout`): the glass pane, and the row of
369 /// buttons on it, which overflow the pane if it is too narrow for them.
370 @_spi(Fixtures) @MainActor public enum CallBarProbe {
371 public static var pane: CGRect = .zero
372 /// The first button on the bar and the last (Leave).
373 public static var first: CGRect = .zero
374 public static var last: CGRect = .zero
375 public static var row: CGRect { first.union(last) }
376 /// The floating self view, or zero when nobody floats.
377 public static var selfView: CGRect = .zero
378 }
379
380 /// Records a bar button's frame for CallBarProbe; nothing else reads it.
381 struct CallBarEndProbe: ViewModifier {
382 let last: Bool
383 func body(content: Content) -> some View {
384 content.background(
385 GeometryReader { button in
386 Color.clear
387 .onAppear { record(button.frame(in: .global)) }
388 .onChange(of: button.frame(in: .global)) { _, now in record(now) }
389 })
390 }
391 @MainActor private func record(_ frame: CGRect) {
392 if last { CallBarProbe.last = frame } else { CallBarProbe.first = frame }
393 }
394 }
395#endif
396