rvlib-shipkit 2.20.0 → 2.21.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.
- package/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +1 -1
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +39 -3
- package/src/cli/cmd_Review.ts +22 -13
- package/src/cli/cmd_Social.ts +13 -7
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/registry.ts +2 -1
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +23 -4
- package/src/core/layout.ts +6 -0
- package/src/home/gui-app/ShipkitGui.swift +35 -0
- package/src/home/gui-app.ts +1 -0
- package/src/home/pm-switch.ts +112 -0
- package/src/identities/identities.ts +11 -6
- package/src/messages/brief.ts +3 -3
- package/src/messages/score.ts +2 -0
- package/src/releases/add.ts +33 -5
- package/src/releases/before.ts +31 -0
- package/src/releases/from-card.ts +104 -19
- package/src/releases/model.ts +73 -13
- package/src/releases/pictures.ts +29 -8
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +12 -2
- package/src/review/stage-card.ts +1 -1
- package/src/review/store.ts +12 -2
- package/src/review/trailer-desk.ts +19 -0
- package/src/review/trailer-model.ts +65 -0
- package/src/review/trailer-routes.ts +98 -1
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/hash-route.ts +27 -15
- package/src/serve/hub-app/home-st.ts +8 -0
- package/src/serve/hub-app/hub-app.tsx +2 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +121 -28
- package/src/serve/hub-app/releases/releases-st.ts +46 -4
- package/src/serve/hub-app/releases.css +30 -3
- package/src/serve/hub-app/repo-sections.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +15 -10
- package/src/serve/hub-app/review/clip-st.ts +3 -1
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/trailer-page.tsx +31 -6
- package/src/serve/hub-app/review/trailer-st.ts +168 -8
- package/src/serve/hub-app/review/trailer-timeline.tsx +36 -4
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +88 -0
- package/src/serve/hub-app/social/comms-page.tsx +10 -5
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/social-model.ts +2 -0
- package/src/serve/hub-app/social/social-st.ts +38 -1
- package/src/serve/hub-app/social.css +8 -0
- package/src/serve/hub-app/tree-build.ts +2 -0
- package/src/serve/project-gutter-route.ts +8 -0
- package/src/serve/project-gutter.ts +4 -2
- package/src/shot/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +19 -9
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +6 -2
- package/src/social/drafts.ts +1 -1
- package/src/social/kinds.ts +3 -2
- package/src/social/load.ts +26 -7
- package/src/social/publish/index.ts +24 -9
- package/src/social/release-stage.ts +133 -29
- package/src/social/routes.ts +2 -1
- package/src/social/stage.ts +39 -20
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +57 -38
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +23 -2
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
|
@@ -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
|
+
}
|