rvlib-shipkit 2.20.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/package.json +1 -1
  3. package/src/asks/asks-queue.ts +8 -7
  4. package/src/assets/kits/identity-kit.ts +158 -2
  5. package/src/checks/SK004-gitignore-policy.check.ts +6 -3
  6. package/src/cli/cmd_Bump.ts +3 -3
  7. package/src/cli/cmd_GlobalProcesses.ts +2 -107
  8. package/src/cli/cmd_Home.ts +1 -1
  9. package/src/cli/cmd_Overview.ts +2 -1
  10. package/src/cli/cmd_Rec.ts +349 -0
  11. package/src/cli/cmd_Releases.ts +42 -3
  12. package/src/cli/cmd_Review.ts +22 -13
  13. package/src/cli/cmd_Secret.ts +10 -3
  14. package/src/cli/cmd_Sign.ts +24 -0
  15. package/src/cli/cmd_Social.ts +57 -8
  16. package/src/cli/cmd_Sound.ts +17 -4
  17. package/src/cli/cmd_Trailer.ts +67 -1
  18. package/src/cli/family-pages.ts +1 -0
  19. package/src/cli/registry.ts +6 -1
  20. package/src/collections/collection-types.ts +1 -1
  21. package/src/collections/review.ts +23 -4
  22. package/src/core/agent-spawn.ts +4 -17
  23. package/src/core/code-lines.ts +49 -0
  24. package/src/core/discover-checks.ts +27 -3
  25. package/src/core/hard-reset.ts +34 -0
  26. package/src/core/layout.ts +6 -0
  27. package/src/core/raw-access.ts +3 -13
  28. package/src/core/throwaway-worktree.ts +72 -0
  29. package/src/home/app-sign.ts +98 -0
  30. package/src/home/gui-app/ShipkitGui.swift +35 -0
  31. package/src/home/gui-app.ts +31 -11
  32. package/src/home/home-routes.ts +6 -0
  33. package/src/home/pm-switch.ts +112 -0
  34. package/src/home/serve-web.ts +1 -1
  35. package/src/identities/identities.ts +17 -6
  36. package/src/media-kinds.ts +5 -3
  37. package/src/media-store/forget.ts +54 -0
  38. package/src/media-store/put.ts +4 -3
  39. package/src/media-store/space.ts +63 -24
  40. package/src/messages/brief.ts +3 -3
  41. package/src/messages/score.ts +2 -0
  42. package/src/recordings/delete.ts +19 -0
  43. package/src/recordings/edit.ts +231 -0
  44. package/src/recordings/load.ts +37 -0
  45. package/src/recordings/marks-draw.ts +111 -0
  46. package/src/recordings/marks-png.ts +25 -0
  47. package/src/recordings/marks.ts +138 -0
  48. package/src/recordings/media-kind.ts +67 -0
  49. package/src/recordings/model.ts +170 -0
  50. package/src/recordings/open.ts +33 -0
  51. package/src/recordings/place.ts +89 -0
  52. package/src/recordings/presets.ts +99 -0
  53. package/src/recordings/recorder-app/Capture.swift +510 -0
  54. package/src/recordings/recorder-app/Clip.swift +107 -0
  55. package/src/recordings/recorder-app/Editor.swift +39 -0
  56. package/src/recordings/recorder-app/Tray.swift +298 -0
  57. package/src/recordings/recorder-app/main.swift +859 -0
  58. package/src/recordings/recorder-app.ts +46 -0
  59. package/src/recordings/recorder.shipkit.ts +11 -0
  60. package/src/recordings/routes.ts +140 -0
  61. package/src/recordings/run-recorder.ts +40 -0
  62. package/src/recordings/share.ts +107 -0
  63. package/src/recordings/take.ts +146 -0
  64. package/src/recordings/view.ts +40 -0
  65. package/src/release/gate-checkout.ts +74 -0
  66. package/src/release/release-scope.ts +35 -26
  67. package/src/release/run-bump.ts +79 -37
  68. package/src/release/run-release.ts +67 -53
  69. package/src/releases/add.ts +38 -5
  70. package/src/releases/before.ts +31 -0
  71. package/src/releases/from-card.ts +105 -20
  72. package/src/releases/model.ts +100 -18
  73. package/src/releases/pictures.ts +29 -8
  74. package/src/repo-config.ts +7 -3
  75. package/src/review/http.ts +1 -1
  76. package/src/review/model.ts +12 -2
  77. package/src/review/stage-card.ts +1 -1
  78. package/src/review/store.ts +12 -2
  79. package/src/review/trailer-desk.ts +20 -0
  80. package/src/review/trailer-model.ts +67 -0
  81. package/src/review/trailer-routes.ts +98 -1
  82. package/src/review/trailer-voices.ts +144 -0
  83. package/src/review/watchers.ts +58 -1
  84. package/src/secrets/manager.ts +18 -1
  85. package/src/serve/hub-app/benign-errors.ts +22 -0
  86. package/src/serve/hub-app/hash-route.ts +27 -15
  87. package/src/serve/hub-app/home-st.ts +23 -5
  88. package/src/serve/hub-app/home.html +1 -0
  89. package/src/serve/hub-app/hub-app.tsx +8 -1
  90. package/src/serve/hub-app/icons.tsx +2 -0
  91. package/src/serve/hub-app/palette-st.ts +1 -0
  92. package/src/serve/hub-app/project-list.css +7 -2
  93. package/src/serve/hub-app/project-list.tsx +10 -0
  94. package/src/serve/hub-app/projects-svc.ts +17 -7
  95. package/src/serve/hub-app/recordings-st.ts +641 -0
  96. package/src/serve/hub-app/recordings-view.tsx +504 -0
  97. package/src/serve/hub-app/recordings.css +82 -0
  98. package/src/serve/hub-app/releases/releases-page.tsx +121 -28
  99. package/src/serve/hub-app/releases/releases-st.ts +46 -4
  100. package/src/serve/hub-app/releases.css +30 -3
  101. package/src/serve/hub-app/repo-sections.ts +1 -1
  102. package/src/serve/hub-app/repo-st.ts +16 -11
  103. package/src/serve/hub-app/review/clip-st.ts +3 -1
  104. package/src/serve/hub-app/review/kit.tsx +3 -3
  105. package/src/serve/hub-app/review/trailer-page.tsx +32 -6
  106. package/src/serve/hub-app/review/trailer-st.ts +184 -8
  107. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -4
  108. package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
  109. package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
  110. package/src/serve/hub-app/review.css +90 -0
  111. package/src/serve/hub-app/social/comms-page.tsx +10 -5
  112. package/src/serve/hub-app/social/next-release.tsx +118 -0
  113. package/src/serve/hub-app/social/post-card.tsx +31 -3
  114. package/src/serve/hub-app/social/social-model.ts +6 -0
  115. package/src/serve/hub-app/social/social-st.ts +50 -1
  116. package/src/serve/hub-app/social.css +12 -0
  117. package/src/serve/hub-app/tree-build.ts +2 -0
  118. package/src/serve/project-gutter-route.ts +8 -0
  119. package/src/serve/project-gutter.ts +4 -2
  120. package/src/shipkit.ts +2 -2
  121. package/src/shot/box.ts +49 -22
  122. package/src/shot/browser-slot.ts +13 -3
  123. package/src/shot/client.ts +1 -1
  124. package/src/shot/film-box.ts +193 -117
  125. package/src/shot/shooter.ts +20 -8
  126. package/src/smoke/run-smoke.ts +8 -6
  127. package/src/social/compose.ts +14 -0
  128. package/src/social/desk-index.ts +49 -8
  129. package/src/social/discord-layout.ts +6 -2
  130. package/src/social/drafts.ts +1 -1
  131. package/src/social/kinds.ts +3 -2
  132. package/src/social/load.ts +42 -9
  133. package/src/social/publish/index.ts +27 -10
  134. package/src/social/publish/secret.ts +12 -4
  135. package/src/social/release-card.ts +69 -0
  136. package/src/social/release-stage.ts +173 -30
  137. package/src/social/routes.ts +7 -1
  138. package/src/social/stage.ts +45 -22
  139. package/src/trailer/bed.ts +111 -0
  140. package/src/trailer/build.ts +81 -38
  141. package/src/trailer/ffmpeg.ts +14 -0
  142. package/src/trailer/grammar.ts +32 -4
  143. package/src/trailer/graph.ts +12 -1
  144. package/src/trailer/look.ts +7 -0
  145. package/src/trailer/shot-plan.ts +75 -0
  146. package/src/trailer/shot-state.ts +191 -0
  147. package/src/trailer/sound/audio.ts +28 -0
  148. package/src/trailer/sound/brand.ts +53 -3
  149. package/src/trailer/sound/gen.ts +61 -2
  150. package/src/trailer/sound/index.ts +25 -11
  151. package/src/trailer/sound/presets.ts +86 -5
  152. package/src/trailer/sound/run.ts +1 -1
  153. package/src/trailer/sound/takes.ts +94 -0
  154. package/src/trailer/titles.ts +36 -0
  155. package/src/trailer/url.ts +1 -1
  156. package/src/veille/chrome.ts +6 -3
@@ -0,0 +1,370 @@
1
+ // the trailer page's Voices as state (wiki tools/trailer/trailer-sound.md, Your own voice): every line of the trailer
2
+ // on screen, the one open with its clip, and his microphone while he records it. A take goes up as the browser
3
+ // recorded it; the build trims and levels it. Read with the trailer page's poll
4
+ import { makeAutoObservable, runInAction } from 'mobx'
5
+ import type { VoiceLine, VoicesDesk, VoiceUse } from '../../../review/trailer-model.ts'
6
+ import { reach } from '../reach.ts'
7
+ import type { RepoSt } from '../repo-st.ts'
8
+
9
+ /** the line's state, in the order the list shows them: his to record first */
10
+ export type VoiceState = 'waiting' | 'recorded' | 'other'
11
+ export const stateOfLine = (l: VoiceLine): VoiceState => (l.mine ? (l.take ? 'recorded' : 'waiting') : 'other')
12
+ const RANK: Record<VoiceState, number> = { waiting: 0, recorded: 1, other: 2 }
13
+
14
+ /** the input he picked, kept by this browser */
15
+ const MIC_KEY = 'shipkit.voices.mic'
16
+ /** the clip's playback level, kept by this browser */
17
+ const VOLUME_KEY = 'shipkit.voices.volume'
18
+
19
+ function readVolume(): number {
20
+ try {
21
+ const v = Number(localStorage.getItem(VOLUME_KEY))
22
+ return localStorage.getItem(VOLUME_KEY) !== null && Number.isFinite(v) ? Math.max(0, Math.min(1, v)) : 1
23
+ } catch {
24
+ return 1
25
+ }
26
+ }
27
+
28
+ /** the mime the browser records in: Chrome and Firefox take webm/opus, Safari mp4 */
29
+ const recMime = (): string => ['audio/webm;codecs=opus', 'audio/webm', 'audio/mp4', 'audio/ogg'].find((m) => typeof MediaRecorder !== 'undefined' && MediaRecorder.isTypeSupported(m)) ?? ''
30
+
31
+ interface Mic {
32
+ key: string
33
+ stream: MediaStream
34
+ rec: MediaRecorder
35
+ chunks: Blob[]
36
+ ctx: AudioContext
37
+ meter: AnalyserNode
38
+ raf: number
39
+ }
40
+
41
+ export class VoicesSt {
42
+ /** the Voices view shows in place of the player */
43
+ on = false
44
+ desk: VoicesDesk | null = null
45
+ error: string | null = null
46
+ /** each trailer's lines waiting for him */
47
+ counts: Record<string, number> = {}
48
+ openKey: string | null = null
49
+ /** recording: the line, since when, the mic's level 0 to 1 */
50
+ recording: { key: string; since: number; level: number } | null = null
51
+ saving: string | null = null
52
+ /** the audio inputs of this machine, and the one a take records from ('' the system's default), kept by this browser */
53
+ mics: { id: string; label: string }[] = []
54
+ micId = ''
55
+ private mic: Mic | null = null
56
+
57
+ constructor(
58
+ private readonly st: RepoSt,
59
+ private readonly trailerId: () => string | null,
60
+ ) {
61
+ try {
62
+ this.micId = localStorage.getItem(MIC_KEY) ?? ''
63
+ } catch {
64
+ // a blocked storage records from the default input
65
+ }
66
+ makeAutoObservable<this, 'st' | 'mic' | 'trailerId'>(this, { st: false, mic: false, trailerId: false })
67
+ }
68
+
69
+ show(on: boolean): void {
70
+ this.on = on
71
+ if (on) {
72
+ void this.refresh()
73
+ void this.loadMics()
74
+ } else void this.cancel()
75
+ }
76
+
77
+ /** the inputs as the browser lists them: a name each once the page was given the microphone, else a number */
78
+ async loadMics(): Promise<void> {
79
+ if (typeof navigator.mediaDevices?.enumerateDevices !== 'function') return
80
+ if (!this.micsWatched) {
81
+ this.micsWatched = true
82
+ navigator.mediaDevices.addEventListener('devicechange', () => void this.loadMics())
83
+ }
84
+ const all = await navigator.mediaDevices.enumerateDevices()
85
+ runInAction(() => {
86
+ this.mics = all.filter((d) => d.kind === 'audioinput' && d.deviceId !== 'default' && d.deviceId !== '').map((d, i) => ({ id: d.deviceId, label: d.label || `microphone ${i + 1}` }))
87
+ })
88
+ }
89
+
90
+ pickMic(id: string): void {
91
+ this.micId = id
92
+ try {
93
+ localStorage.setItem(MIC_KEY, id)
94
+ } catch {
95
+ // the pick holds for this page only
96
+ }
97
+ }
98
+
99
+ private micsWatched = false
100
+
101
+ /** the view on a line, by its key (a tree row); the first waiting one when null */
102
+ open(key: string | null): void {
103
+ this.on = true
104
+ this.openKey = key
105
+ }
106
+
107
+ pick(key: string): void {
108
+ if (this.recording && this.recording.key !== key) void this.cancel()
109
+ this.openKey = key
110
+ }
111
+
112
+ async refresh(): Promise<void> {
113
+ try {
114
+ const counts = await this.get<Record<string, number>>('/api/trailer/voices')
115
+ const id = this.trailerId()
116
+ const desk = this.on && id ? await this.get<VoicesDesk>(`/api/trailer/voices/${id}`) : null
117
+ runInAction(() => {
118
+ this.counts = counts
119
+ if (desk) this.desk = desk
120
+ this.error = null
121
+ })
122
+ } catch (e) {
123
+ runInAction(() => (this.error = (e as Error).message))
124
+ }
125
+ }
126
+
127
+ get root(): string {
128
+ return this.st.root
129
+ }
130
+
131
+ get count(): number {
132
+ return Object.values(this.counts).reduce((a, b) => a + b, 0)
133
+ }
134
+
135
+ /** the trailer on screen's lines, his to record first, then in the order the cuts speak them */
136
+ get lines(): VoiceLine[] {
137
+ const d = this.desk
138
+ if (!d || d.trailer !== this.trailerId()) return []
139
+ return [...d.lines].sort((a, b) => RANK[stateOfLine(a)] - RANK[stateOfLine(b)] || (a.uses[0]?.cut ?? '').localeCompare(b.uses[0]?.cut ?? '') || (a.uses[0]?.at ?? 0) - (b.uses[0]?.at ?? 0))
140
+ }
141
+
142
+ get line(): VoiceLine | null {
143
+ const ls = this.lines
144
+ return ls.find((l) => l.key === this.openKey) ?? ls.find((l) => stateOfLine(l) === 'waiting') ?? ls[0] ?? null
145
+ }
146
+
147
+ /** the use the clip shows: one of his voice first, then the first */
148
+ useOf(l: VoiceLine): VoiceUse | null {
149
+ return l.uses.find((u) => u.mine && u.video) ?? l.uses.find((u) => u.video) ?? l.uses[0] ?? null
150
+ }
151
+
152
+ /** the version of a line the clip plays: the reference or his take, the same on every line */
153
+ hear: 'ref' | 'take' = 'take'
154
+
155
+ setHear(h: 'ref' | 'take'): void {
156
+ this.hear = h
157
+ }
158
+
159
+ /** the clip's range plays over and over, on every line */
160
+ loop = false
161
+
162
+ setLoop(on: boolean): void {
163
+ this.loop = on
164
+ }
165
+
166
+ /** the level the clip and a lane alone play at, 0 to 1, and its mute; kept by this browser */
167
+ volume = readVolume()
168
+ muted = false
169
+
170
+ setVolume(v: number): void {
171
+ this.volume = Math.max(0, Math.min(1, v))
172
+ this.muted = false
173
+ try {
174
+ localStorage.setItem(VOLUME_KEY, String(this.volume))
175
+ } catch {
176
+ // the level holds for this page only
177
+ }
178
+ }
179
+
180
+ toggleMute(): void {
181
+ this.muted = !this.muted
182
+ }
183
+
184
+ /** what a media element's volume is set to */
185
+ get level(): number {
186
+ return this.muted ? 0 : this.volume
187
+ }
188
+
189
+ /** a line's passage, picture and music and one version of it (none while he records), made by the hub on first
190
+ * ask; a new render, a new take or an edit of it is another url */
191
+ passageUrl(l: VoiceLine, u: VoiceUse, hear: 'ref' | 'take' | 'none'): string | null {
192
+ const id = this.trailerId()
193
+ if (!id || !u.video) return null
194
+ const v = [u.video.mtime, u.standin?.made ?? u.made ?? '', l.take?.made ?? ''].join('-')
195
+ return this.st.url(`/api/trailer/voices/passage/${id}/${l.key}/${u.cut}/${u.line}/${hear}.mp4?v=${v}`)
196
+ }
197
+
198
+ madeUrlOf(key: string): string {
199
+ return this.st.url(`/api/trailer/voices/made/${key}.wav`)
200
+ }
201
+
202
+ madeUrl(u: VoiceUse): string | null {
203
+ return u.made ? this.madeUrlOf(u.made) : null
204
+ }
205
+
206
+ takeUrl(l: VoiceLine): string | null {
207
+ const id = this.trailerId()
208
+ return l.take && id ? this.st.url(`/api/trailer/voices/${id}/take/${l.key}?v=${Math.round(l.take.mtime)}`) : null
209
+ }
210
+
211
+ /** the next line after the open one, the list's order */
212
+ next(): void {
213
+ const ls = this.lines
214
+ const i = ls.findIndex((l) => l.key === this.line?.key)
215
+ const n = ls[i + 1]
216
+ if (n) this.pick(n.key)
217
+ }
218
+
219
+ async record(key: string): Promise<void> {
220
+ if (this.recording) return
221
+ this.openKey = key
222
+ try {
223
+ // a window that gives the page no microphone api says so, with what decides it, instead of a type error
224
+ if (typeof navigator.mediaDevices?.getUserMedia !== 'function')
225
+ throw new Error(`this window gives the page no microphone (${location.origin}, secure context ${String(window.isSecureContext)}): quit and reopen the app with sk gui, or open this page in Chrome`)
226
+ const device = this.micId ? { deviceId: { exact: this.micId } } : {}
227
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: { ...device, echoCancellation: false, noiseSuppression: true, autoGainControl: false, channelCount: 1 } })
228
+ // the names of the inputs show once the page may use the microphone
229
+ void this.loadMics()
230
+ const mime = recMime()
231
+ const rec = new MediaRecorder(stream, mime ? { mimeType: mime } : {})
232
+ const ctx = new AudioContext()
233
+ const meter = ctx.createAnalyser()
234
+ meter.fftSize = 1024
235
+ ctx.createMediaStreamSource(stream).connect(meter)
236
+ const mic: Mic = { key, stream, rec, chunks: [], ctx, meter, raf: 0 }
237
+ rec.ondataavailable = (e) => void (e.data.size > 0 && mic.chunks.push(e.data))
238
+ rec.start(250)
239
+ this.mic = mic
240
+ runInAction(() => (this.recording = { key, since: Date.now(), level: 0 }))
241
+ const buf = new Float32Array(meter.fftSize)
242
+ const tick = (): void => {
243
+ meter.getFloatTimeDomainData(buf)
244
+ let peak = 0
245
+ for (const x of buf) peak = Math.max(peak, Math.abs(x))
246
+ runInAction(() => {
247
+ if (this.recording) this.recording.level = peak
248
+ })
249
+ mic.raf = requestAnimationFrame(tick)
250
+ }
251
+ tick()
252
+ } catch (e) {
253
+ this.release()
254
+ // the input picked is gone (unplugged): back to the default one, said, and he presses again
255
+ const gone = this.micId !== '' && ['OverconstrainedError', 'NotFoundError'].includes((e as Error).name)
256
+ if (gone) this.pickMic('')
257
+ runInAction(() => (this.error = gone ? 'the microphone picked is not here any more: back to the default input, press Record again' : `the microphone: ${(e as Error).message}`))
258
+ }
259
+ }
260
+
261
+ /** the take stopped and kept: it replaces the one before */
262
+ async stop(): Promise<void> {
263
+ const mic = this.mic
264
+ if (!mic) return
265
+ const blob = await this.finish(mic)
266
+ const id = this.trailerId()
267
+ if (!id) return
268
+ runInAction(() => (this.saving = mic.key))
269
+ try {
270
+ const type = (blob.type || 'audio/webm').split(';')[0] ?? 'audio/webm'
271
+ await this.call(`/api/trailer/voices/${id}/take/${mic.key}`, 'PUT', { type, body: blob })
272
+ await this.refresh()
273
+ } catch (e) {
274
+ runInAction(() => (this.error = `the take was not kept: ${(e as Error).message}`))
275
+ } finally {
276
+ runInAction(() => (this.saving = null))
277
+ }
278
+ }
279
+
280
+ /** the recording dropped, nothing kept */
281
+ async cancel(): Promise<void> {
282
+ if (this.mic) await this.finish(this.mic)
283
+ }
284
+
285
+ /** his drag and his mask on a take kept (offset null: back to its first sound); the line is made again before the
286
+ * answer, so the next read draws and plays it */
287
+ async editTake(l: VoiceLine, edit: { offset: number | null; mask: [number, number][] }): Promise<void> {
288
+ const id = this.trailerId()
289
+ if (!id || !l.take) return
290
+ runInAction(() => (this.saving = l.key))
291
+ try {
292
+ await this.call(`/api/trailer/voices/${id}/take/${l.key}/edit`, 'POST', { type: 'application/json', body: JSON.stringify(edit) })
293
+ await this.refresh()
294
+ } catch (e) {
295
+ runInAction(() => (this.error = `the edit was not kept: ${(e as Error).message}`))
296
+ } finally {
297
+ runInAction(() => (this.saving = null))
298
+ }
299
+ }
300
+
301
+ async drop(l: VoiceLine): Promise<void> {
302
+ const id = this.trailerId()
303
+ if (!id || !l.take) return
304
+ try {
305
+ await this.call(`/api/trailer/voices/${id}/take/${l.key}`, 'DELETE')
306
+ await this.refresh()
307
+ } catch (e) {
308
+ runInAction(() => (this.error = (e as Error).message))
309
+ }
310
+ }
311
+
312
+ /** R records the open line or stops it, Esc drops a recording, N goes to the next line; true when used */
313
+ key(e: Pick<KeyboardEvent, 'key'>): boolean {
314
+ const l = this.line
315
+ if (e.key === 'r' || e.key === 'R') {
316
+ if (this.recording) void this.stop()
317
+ else if (l) void this.record(l.key)
318
+ return true
319
+ }
320
+ if (e.key === 'Escape' && this.recording) {
321
+ void this.cancel()
322
+ return true
323
+ }
324
+ if ((e.key === 'n' || e.key === 'N') && !this.recording) {
325
+ this.next()
326
+ return true
327
+ }
328
+ return false
329
+ }
330
+
331
+ private finish(mic: Mic): Promise<Blob> {
332
+ return new Promise((done) => {
333
+ mic.rec.onstop = () => {
334
+ this.release()
335
+ done(new Blob(mic.chunks, { type: mic.rec.mimeType }))
336
+ }
337
+ if (mic.rec.state === 'inactive') mic.rec.onstop(new Event('stop'))
338
+ else mic.rec.stop()
339
+ })
340
+ }
341
+
342
+ private release(): void {
343
+ const mic = this.mic
344
+ this.mic = null
345
+ if (mic) {
346
+ cancelAnimationFrame(mic.raf)
347
+ for (const t of mic.stream.getTracks()) t.stop()
348
+ void mic.ctx.close()
349
+ }
350
+ runInAction(() => (this.recording = null))
351
+ }
352
+
353
+ private get<T>(path: string): Promise<T> {
354
+ return this.call<T>(path, 'GET')
355
+ }
356
+
357
+ /** one call of the hub, its error said in the hub's words */
358
+ private async call<T>(path: string, method: 'GET' | 'PUT' | 'POST' | 'DELETE', body?: { type: string; body: Blob | string }): Promise<T> {
359
+ const r = await reach(this.st.url(path), { method, ...(body ? { headers: { 'content-type': body.type }, body: body.body } : {}) })
360
+ const text = await r.text()
361
+ let json: unknown = null
362
+ try {
363
+ json = JSON.parse(text)
364
+ } catch {
365
+ // a plain text answer says it already
366
+ }
367
+ if (!r.ok) throw new Error((json as { error?: string } | null)?.error ?? (text || `HTTP ${r.status}`))
368
+ return json as T
369
+ }
370
+ }