@pyai/sdk 0.9.3 → 0.11.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/CLI.schema.json +11 -0
- package/README.md +106 -3
- package/dist/cli-omni-template.d.ts +2 -2
- package/dist/cli-omni-template.js +2 -2
- package/dist/cli.js +39 -4
- package/dist/dialer/appServer.d.ts +21 -0
- package/dist/dialer/appServer.js +195 -0
- package/dist/dialer/dialerElement.d.ts +23 -0
- package/dist/dialer/dialerElement.js +108 -0
- package/dist/dialer/dialingQueue.d.ts +31 -0
- package/dist/dialer/dialingQueue.js +78 -0
- package/dist/dialer/index.d.ts +6 -0
- package/dist/dialer/index.js +6 -0
- package/dist/dialer/indexedDbJournal.d.ts +11 -0
- package/dist/dialer/indexedDbJournal.js +62 -0
- package/dist/dialer/managedDialer.d.ts +65 -0
- package/dist/dialer/managedDialer.js +217 -0
- package/dist/dialer/meetingRecorder.d.ts +83 -0
- package/dist/dialer/meetingRecorder.js +261 -0
- package/dist/dialer/meetingRecorderElement.d.ts +20 -0
- package/dist/dialer/meetingRecorderElement.js +138 -0
- package/dist/dialer/meetingRecordingStore.d.ts +17 -0
- package/dist/dialer/meetingRecordingStore.js +129 -0
- package/dist/dialer/serverBroker.d.ts +3 -0
- package/dist/dialer/serverBroker.js +23 -0
- package/dist/dialer/voiceSdkAudio.d.ts +33 -0
- package/dist/dialer/voiceSdkAudio.js +66 -0
- package/dist/index.d.ts +122 -6
- package/dist/index.js +36 -3
- package/package.json +24 -1
- package/src/cli-omni-template.ts +2 -2
- package/src/cli.ts +25 -4
- package/src/dialer/app/app.css +1 -0
- package/src/dialer/app/app.html +7 -0
- package/src/dialer/app/app.js +88 -0
- package/src/dialer/app/icon.svg +1 -0
- package/src/dialer/app/manifest.webmanifest +1 -0
- package/src/dialer/appServer.ts +151 -0
- package/src/dialer/dialerElement.ts +80 -0
- package/src/dialer/dialingQueue.ts +65 -0
- package/src/dialer/index.ts +6 -0
- package/src/dialer/indexedDbJournal.ts +56 -0
- package/src/dialer/managedDialer.ts +187 -0
- package/src/dialer/meetingRecorder.ts +220 -0
- package/src/dialer/meetingRecorderElement.ts +99 -0
- package/src/dialer/meetingRecordingStore.ts +99 -0
- package/src/dialer/serverBroker.ts +23 -0
- package/src/dialer/voiceSdkAudio.ts +61 -0
- package/src/index.ts +118 -5
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** Permission-based, audio-only meeting capture. The user selects a source on
|
|
2
|
+
* every start; video is requested for the browser picker but is never recorded. */
|
|
3
|
+
export interface MeetingRecording {
|
|
4
|
+
id: string;
|
|
5
|
+
scope: string;
|
|
6
|
+
state: "recording" | "ready" | "incomplete";
|
|
7
|
+
mimeType: string;
|
|
8
|
+
sources: Array<"shared_audio" | "microphone">;
|
|
9
|
+
createdAt: number;
|
|
10
|
+
endedAt: number | null;
|
|
11
|
+
bytes: number;
|
|
12
|
+
chunks: number;
|
|
13
|
+
maxBytes: number;
|
|
14
|
+
signalObserved: {
|
|
15
|
+
shared_audio: boolean;
|
|
16
|
+
microphone: boolean;
|
|
17
|
+
};
|
|
18
|
+
error: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface MeetingRecordingStore {
|
|
21
|
+
/** Held for the entire capture; recovery must use the same exclusive lease. */
|
|
22
|
+
acquire(scope: string, id: string): Promise<() => void>;
|
|
23
|
+
create(recording: MeetingRecording): Promise<void>;
|
|
24
|
+
append(scope: string, id: string, sequence: number, bytes: Blob): Promise<void>;
|
|
25
|
+
finish(scope: string, id: string, state: "ready" | "incomplete", endedAt: number, error: string | null, signalObserved?: MeetingRecording["signalObserved"]): Promise<MeetingRecording>;
|
|
26
|
+
get(scope: string, id: string): Promise<MeetingRecording | null>;
|
|
27
|
+
list(scope: string): Promise<MeetingRecording[]>;
|
|
28
|
+
recover(scope: string, id: string): Promise<MeetingRecording>;
|
|
29
|
+
audio(scope: string, id: string): Promise<Blob>;
|
|
30
|
+
}
|
|
31
|
+
export interface MeetingCaptureOptions {
|
|
32
|
+
/** The host must display a recording notice before this foreground action. */
|
|
33
|
+
noticeAccepted: boolean;
|
|
34
|
+
microphone: boolean;
|
|
35
|
+
maxDurationSeconds?: number;
|
|
36
|
+
maxBytes?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface MeetingCaptureEnvironment {
|
|
39
|
+
sharedAudio(): Promise<MediaStream>;
|
|
40
|
+
microphone(): Promise<MediaStream>;
|
|
41
|
+
audioContext(): AudioContext;
|
|
42
|
+
recorder(stream: MediaStream): MediaRecorder;
|
|
43
|
+
newId(): string;
|
|
44
|
+
now(): number;
|
|
45
|
+
}
|
|
46
|
+
export interface MeetingCaptureSnapshot {
|
|
47
|
+
state: "idle" | "starting" | "recording" | "paused" | "stopping" | "ready" | "error";
|
|
48
|
+
recording: MeetingRecording | null;
|
|
49
|
+
error: string | null;
|
|
50
|
+
}
|
|
51
|
+
export declare class MeetingRecorder {
|
|
52
|
+
private readonly scope;
|
|
53
|
+
private readonly store;
|
|
54
|
+
private readonly environment;
|
|
55
|
+
private streams;
|
|
56
|
+
private context;
|
|
57
|
+
private recorder;
|
|
58
|
+
private listeners;
|
|
59
|
+
private snapshot;
|
|
60
|
+
private pendingWrites;
|
|
61
|
+
private writeError;
|
|
62
|
+
private sequence;
|
|
63
|
+
private generation;
|
|
64
|
+
private starting;
|
|
65
|
+
private stopping;
|
|
66
|
+
private timer;
|
|
67
|
+
private watchdog;
|
|
68
|
+
private analysers;
|
|
69
|
+
private signalObserved;
|
|
70
|
+
private releaseStorage;
|
|
71
|
+
constructor(scope: string, store: MeetingRecordingStore, environment?: MeetingCaptureEnvironment);
|
|
72
|
+
get current(): MeetingCaptureSnapshot;
|
|
73
|
+
get recordingScope(): string;
|
|
74
|
+
subscribe(listener: (snapshot: MeetingCaptureSnapshot) => void): () => void;
|
|
75
|
+
private update;
|
|
76
|
+
start(options: MeetingCaptureOptions): Promise<void>;
|
|
77
|
+
private prepare;
|
|
78
|
+
pause(): void;
|
|
79
|
+
resume(): void;
|
|
80
|
+
stop(): Promise<void>;
|
|
81
|
+
private finish;
|
|
82
|
+
private release;
|
|
83
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
const defaultEnvironment = {
|
|
2
|
+
// Do not narrow the source picker to an app selected by the host. Audio can
|
|
3
|
+
// cover a wider surface than video; the browser/OS must obtain real consent.
|
|
4
|
+
sharedAudio: () => navigator.mediaDevices.getDisplayMedia({ video: true, audio: true }),
|
|
5
|
+
microphone: () => navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true }, video: false }),
|
|
6
|
+
audioContext: () => new AudioContext(),
|
|
7
|
+
recorder: stream => {
|
|
8
|
+
const mimeType = ["audio/webm;codecs=opus", "audio/mp4"].find(type => MediaRecorder.isTypeSupported(type));
|
|
9
|
+
return new MediaRecorder(stream, { ...(mimeType ? { mimeType } : {}), audioBitsPerSecond: 64000 });
|
|
10
|
+
},
|
|
11
|
+
newId: () => crypto.randomUUID(), now: Date.now,
|
|
12
|
+
};
|
|
13
|
+
export class MeetingRecorder {
|
|
14
|
+
scope;
|
|
15
|
+
store;
|
|
16
|
+
environment;
|
|
17
|
+
streams = [];
|
|
18
|
+
context = null;
|
|
19
|
+
recorder = null;
|
|
20
|
+
listeners = new Set();
|
|
21
|
+
snapshot = { state: "idle", recording: null, error: null };
|
|
22
|
+
pendingWrites = Promise.resolve();
|
|
23
|
+
writeError = null;
|
|
24
|
+
sequence = 0;
|
|
25
|
+
generation = 0;
|
|
26
|
+
starting = null;
|
|
27
|
+
stopping = null;
|
|
28
|
+
timer = null;
|
|
29
|
+
watchdog = null;
|
|
30
|
+
analysers = [];
|
|
31
|
+
signalObserved = { shared_audio: false, microphone: false };
|
|
32
|
+
releaseStorage = null;
|
|
33
|
+
constructor(scope, store, environment = defaultEnvironment) {
|
|
34
|
+
if (!scope.trim())
|
|
35
|
+
throw new Error("A workspace/user recording scope is required.");
|
|
36
|
+
this.scope = scope;
|
|
37
|
+
this.store = store;
|
|
38
|
+
this.environment = environment;
|
|
39
|
+
}
|
|
40
|
+
get current() { return structuredClone(this.snapshot); }
|
|
41
|
+
get recordingScope() { return this.scope; }
|
|
42
|
+
subscribe(listener) {
|
|
43
|
+
this.listeners.add(listener);
|
|
44
|
+
listener(this.current);
|
|
45
|
+
return () => { this.listeners.delete(listener); };
|
|
46
|
+
}
|
|
47
|
+
update(patch) {
|
|
48
|
+
this.snapshot = { ...this.snapshot, ...patch };
|
|
49
|
+
for (const listener of this.listeners) {
|
|
50
|
+
try {
|
|
51
|
+
listener(this.current);
|
|
52
|
+
}
|
|
53
|
+
catch { /* UI cannot prevent capture cleanup. */ }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async start(options) {
|
|
57
|
+
if (this.starting || this.stopping || ["recording", "paused", "starting", "stopping"].includes(this.snapshot.state))
|
|
58
|
+
throw new Error("Finish the current recording first.");
|
|
59
|
+
if (!options.noticeAccepted)
|
|
60
|
+
throw new Error("Confirm the recording notice before starting.");
|
|
61
|
+
const duration = options.maxDurationSeconds ?? 7200, maxBytes = options.maxBytes ?? 128 * 1024 * 1024;
|
|
62
|
+
if (!Number.isInteger(duration) || duration < 1 || duration > 7200 || !Number.isSafeInteger(maxBytes) || maxBytes < 65536 || maxBytes > 256 * 1024 * 1024)
|
|
63
|
+
throw new Error("Recording limits must be 1–7200 seconds and 64 KiB–256 MiB.");
|
|
64
|
+
const generation = ++this.generation;
|
|
65
|
+
this.pendingWrites = Promise.resolve();
|
|
66
|
+
this.writeError = null;
|
|
67
|
+
this.sequence = 0;
|
|
68
|
+
this.signalObserved = { shared_audio: false, microphone: false };
|
|
69
|
+
this.update({ state: "starting", recording: null, error: null });
|
|
70
|
+
const prepare = this.prepare(options, generation, duration, maxBytes);
|
|
71
|
+
this.starting = prepare;
|
|
72
|
+
try {
|
|
73
|
+
await prepare;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
if (this.starting === prepare)
|
|
77
|
+
this.starting = null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async prepare(options, generation, duration, maxBytes) {
|
|
81
|
+
try {
|
|
82
|
+
const shared = await this.environment.sharedAudio();
|
|
83
|
+
this.streams.push(shared);
|
|
84
|
+
if (generation !== this.generation) {
|
|
85
|
+
await this.release();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!shared.getAudioTracks().some(track => track.readyState === "live" && track.enabled))
|
|
89
|
+
throw new Error("The selected source has no shared audio. Enable sharing audio or choose a supported tab or system source.");
|
|
90
|
+
const sources = ["shared_audio"];
|
|
91
|
+
if (options.microphone) {
|
|
92
|
+
const mic = await this.environment.microphone();
|
|
93
|
+
this.streams.push(mic);
|
|
94
|
+
if (generation !== this.generation) {
|
|
95
|
+
await this.release();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!mic.getAudioTracks().some(track => track.readyState === "live" && track.enabled))
|
|
99
|
+
throw new Error("The microphone is unavailable.");
|
|
100
|
+
sources.push("microphone");
|
|
101
|
+
}
|
|
102
|
+
const context = this.environment.audioContext();
|
|
103
|
+
this.context = context;
|
|
104
|
+
await context.resume();
|
|
105
|
+
if (generation !== this.generation) {
|
|
106
|
+
await this.release();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const destination = context.createMediaStreamDestination();
|
|
110
|
+
for (const [index, stream] of this.streams.entries()) {
|
|
111
|
+
const audio = new MediaStream(stream.getAudioTracks());
|
|
112
|
+
const gain = context.createGain();
|
|
113
|
+
gain.gain.value = this.streams.length > 1 ? 0.5 : 1;
|
|
114
|
+
const analyser = context.createAnalyser();
|
|
115
|
+
analyser.fftSize = 512;
|
|
116
|
+
context.createMediaStreamSource(audio).connect(analyser).connect(gain).connect(destination);
|
|
117
|
+
this.analysers.push({ source: index === 0 ? "shared_audio" : "microphone", node: analyser, samples: new Float32Array(512) });
|
|
118
|
+
}
|
|
119
|
+
const recorder = this.environment.recorder(destination.stream);
|
|
120
|
+
this.recorder = recorder;
|
|
121
|
+
const recording = { id: this.environment.newId(), scope: this.scope, state: "recording", mimeType: recorder.mimeType,
|
|
122
|
+
sources, createdAt: this.environment.now(), endedAt: null, bytes: 0, chunks: 0, maxBytes, signalObserved: { ...this.signalObserved }, error: null };
|
|
123
|
+
this.releaseStorage = await this.store.acquire(this.scope, recording.id);
|
|
124
|
+
await this.store.create(recording);
|
|
125
|
+
if (generation !== this.generation) {
|
|
126
|
+
await this.store.finish(this.scope, recording.id, "incomplete", this.environment.now(), "Capture was cancelled before audio started.");
|
|
127
|
+
await this.release();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.update({ recording, state: "recording" });
|
|
131
|
+
recorder.ondataavailable = event => {
|
|
132
|
+
if (!event.data.size)
|
|
133
|
+
return;
|
|
134
|
+
const sequence = this.sequence++;
|
|
135
|
+
this.pendingWrites = this.pendingWrites.then(async () => {
|
|
136
|
+
if (this.writeError)
|
|
137
|
+
return;
|
|
138
|
+
await this.store.append(this.scope, recording.id, sequence, event.data);
|
|
139
|
+
const stored = await this.store.get(this.scope, recording.id);
|
|
140
|
+
if (stored)
|
|
141
|
+
this.update({ recording: stored });
|
|
142
|
+
}).catch(error => {
|
|
143
|
+
this.writeError = error instanceof Error ? error : new Error("Recording storage failed.");
|
|
144
|
+
void this.stop();
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
recorder.onerror = () => { this.writeError = new Error("Audio capture failed; the saved recording may be incomplete."); void this.stop(); };
|
|
148
|
+
// A stop from the browser/OS source chooser must also release the mic.
|
|
149
|
+
for (const stream of this.streams)
|
|
150
|
+
for (const track of stream.getTracks())
|
|
151
|
+
track.addEventListener("ended", () => void this.stop(), { once: true });
|
|
152
|
+
recorder.start(1000);
|
|
153
|
+
this.timer = setTimeout(() => void this.stop(), duration * 1000);
|
|
154
|
+
this.watchdog = setInterval(() => {
|
|
155
|
+
if (this.snapshot.state === "recording")
|
|
156
|
+
for (const analyser of this.analysers) {
|
|
157
|
+
analyser.node.getFloatTimeDomainData(analyser.samples);
|
|
158
|
+
if (analyser.samples.some(sample => Math.abs(sample) > 0.00001))
|
|
159
|
+
this.signalObserved[analyser.source] = true;
|
|
160
|
+
}
|
|
161
|
+
if (this.streams.some(stream => stream.getAudioTracks().some(track => track.readyState !== "live" || !track.enabled))) {
|
|
162
|
+
this.writeError = new Error("An audio source stopped; the saved recording may be incomplete.");
|
|
163
|
+
void this.stop();
|
|
164
|
+
}
|
|
165
|
+
}, 250);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
await this.release();
|
|
169
|
+
if (generation === this.generation)
|
|
170
|
+
this.update({ state: "error", error: error instanceof Error ? error.message : "Meeting capture could not start." });
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
pause() {
|
|
175
|
+
if (this.snapshot.state !== "recording" || !this.recorder)
|
|
176
|
+
throw new Error("No recording to pause.");
|
|
177
|
+
this.recorder.pause();
|
|
178
|
+
this.update({ state: "paused" });
|
|
179
|
+
}
|
|
180
|
+
resume() {
|
|
181
|
+
if (this.snapshot.state !== "paused" || !this.recorder)
|
|
182
|
+
throw new Error("No paused recording.");
|
|
183
|
+
this.recorder.resume();
|
|
184
|
+
this.update({ state: "recording" });
|
|
185
|
+
}
|
|
186
|
+
async stop() {
|
|
187
|
+
if (this.stopping)
|
|
188
|
+
return this.stopping;
|
|
189
|
+
++this.generation;
|
|
190
|
+
const finish = this.finish();
|
|
191
|
+
this.stopping = finish;
|
|
192
|
+
try {
|
|
193
|
+
await finish;
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
if (this.stopping === finish)
|
|
197
|
+
this.stopping = null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async finish() {
|
|
201
|
+
this.update({ state: "stopping" });
|
|
202
|
+
if (this.starting)
|
|
203
|
+
await this.starting.catch(() => { });
|
|
204
|
+
const recorder = this.recorder, recording = this.snapshot.recording;
|
|
205
|
+
try {
|
|
206
|
+
if (recorder && recorder.state !== "inactive") {
|
|
207
|
+
await new Promise(resolve => {
|
|
208
|
+
const timeout = setTimeout(() => { this.writeError = new Error("Audio finalization was not acknowledged."); resolve(); }, 5000);
|
|
209
|
+
recorder.addEventListener("stop", () => { clearTimeout(timeout); resolve(); }, { once: true });
|
|
210
|
+
try {
|
|
211
|
+
recorder.stop();
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
clearTimeout(timeout);
|
|
215
|
+
this.writeError = new Error("Audio finalization failed.");
|
|
216
|
+
resolve();
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
await this.pendingWrites;
|
|
221
|
+
if (recording) {
|
|
222
|
+
const stored = await this.store.get(this.scope, recording.id);
|
|
223
|
+
const error = this.writeError?.message ?? (!stored?.bytes ? "No audio was saved." : !this.signalObserved.shared_audio ? "No sound was detected from the shared source. Check this recording before using it." : null);
|
|
224
|
+
const final = await this.store.finish(this.scope, recording.id, error ? "incomplete" : "ready", this.environment.now(), error, { ...this.signalObserved });
|
|
225
|
+
this.update({ state: error ? "error" : "ready", recording: final, error });
|
|
226
|
+
}
|
|
227
|
+
else
|
|
228
|
+
this.update({ state: "idle", error: null });
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
this.update({ state: "error", error: error instanceof Error ? error.message : "Recording finalization failed; saved chunks remain recoverable." });
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
await this.release();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async release() {
|
|
238
|
+
if (this.timer)
|
|
239
|
+
clearTimeout(this.timer);
|
|
240
|
+
if (this.watchdog)
|
|
241
|
+
clearInterval(this.watchdog);
|
|
242
|
+
this.timer = null;
|
|
243
|
+
this.watchdog = null;
|
|
244
|
+
for (const stream of this.streams)
|
|
245
|
+
for (const track of stream.getTracks()) {
|
|
246
|
+
try {
|
|
247
|
+
track.stop();
|
|
248
|
+
}
|
|
249
|
+
catch { /* Release the remaining sources. */ }
|
|
250
|
+
}
|
|
251
|
+
this.streams = [];
|
|
252
|
+
this.recorder = null;
|
|
253
|
+
this.releaseStorage?.();
|
|
254
|
+
this.releaseStorage = null;
|
|
255
|
+
this.analysers = [];
|
|
256
|
+
const context = this.context;
|
|
257
|
+
this.context = null;
|
|
258
|
+
if (context && context.state !== "closed")
|
|
259
|
+
await context.close().catch(() => { });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MeetingRecorder } from "./meetingRecorder.ts";
|
|
2
|
+
import type { MeetingRecordingStore } from "./meetingRecorder.ts";
|
|
3
|
+
/** Foreground capture controls. The native browser/OS picker is always shown;
|
|
4
|
+
* the application never silently chooses a user's window or microphone. */
|
|
5
|
+
export declare class PyaiMeetingRecorderElement extends HTMLElement {
|
|
6
|
+
private root;
|
|
7
|
+
private recorder;
|
|
8
|
+
private store;
|
|
9
|
+
private unsubscribe;
|
|
10
|
+
private historyGeneration;
|
|
11
|
+
constructor();
|
|
12
|
+
bind(recorder: MeetingRecorder, store: MeetingRecordingStore): void;
|
|
13
|
+
connectedCallback(): void;
|
|
14
|
+
disconnectedCallback(): void;
|
|
15
|
+
private render;
|
|
16
|
+
private refreshHistory;
|
|
17
|
+
private download;
|
|
18
|
+
private showError;
|
|
19
|
+
private run;
|
|
20
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** Foreground capture controls. The native browser/OS picker is always shown;
|
|
2
|
+
* the application never silently chooses a user's window or microphone. */
|
|
3
|
+
export class PyaiMeetingRecorderElement extends HTMLElement {
|
|
4
|
+
root;
|
|
5
|
+
recorder = null;
|
|
6
|
+
store = null;
|
|
7
|
+
unsubscribe = null;
|
|
8
|
+
historyGeneration = 0;
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.root = this.attachShadow({ mode: "open" });
|
|
12
|
+
this.root.innerHTML = `<style>
|
|
13
|
+
:host{display:block;max-width:440px;color:#202332;font:14px/1.5 system-ui,sans-serif;--recorder-accent:#5b55e7}*{box-sizing:border-box}section{background:#fff;border:1px solid #e7e8ef;border-radius:24px;padding:26px;box-shadow:0 16px 56px #25284c12}h2{margin:0 0 8px;font-size:19px}.description,.hint{color:#737b8e;font-size:13px;margin:0 0 20px}.status{background:#f5f5fc;border-radius:14px;padding:16px;margin-bottom:20px;display:flex;gap:10px;align-items:center}.dot{width:9px;height:9px;border-radius:50%;background:#a6abba}.dot.active{background:#e33f56;box-shadow:0 0 0 5px #e33f5612}label{display:flex;gap:10px;margin:14px 0;align-items:flex-start}input{accent-color:var(--recorder-accent);margin-top:4px}.actions{display:flex;gap:8px;margin-top:22px}button{font:600 13px system-ui;cursor:pointer;border:0;border-radius:13px;padding:14px 18px;min-height:46px;background:#f1f2f7;color:#535b70}button.primary{flex:1;background:var(--recorder-accent);color:white}button.end{background:#da4055}button:disabled{opacity:.45;cursor:default}button:focus-visible{outline:3px solid #bdb8ff;outline-offset:2px}.error{color:#b42338;font-size:12px;min-height:18px}.saved{font-size:12px;color:#667085;overflow-wrap:anywhere}.hint{font-size:11px;margin:16px 0 0}
|
|
14
|
+
</style><section><h2>Record a meeting</h2><p class="description">Record shared audio and your microphone. Choose a meeting tab or a supported system audio source.</p>
|
|
15
|
+
<div class="status" role="status" aria-live="polite"><span class="dot"></span><span data-status>Ready when you are</span></div>
|
|
16
|
+
<label><input type="checkbox" data-notice><span>Everyone has been informed and I’m ready to record.</span></label>
|
|
17
|
+
<label><input type="checkbox" data-microphone checked><span>Include my microphone</span></label>
|
|
18
|
+
<div class="actions"><button class="primary" data-start disabled>Choose audio & record</button><button data-pause disabled>Pause</button><button data-download hidden>Save audio</button></div>
|
|
19
|
+
<p class="error" role="alert"></p><p class="saved"></p><p class="hint">Saved privately in this browser. Nothing is uploaded until your app explicitly submits it. Video is never saved.</p>
|
|
20
|
+
<details><summary>Saved recordings</summary><button data-refresh>Refresh recordings</button><ul data-history></ul></details></section>`;
|
|
21
|
+
this.root.querySelector("[data-notice]").addEventListener("change", () => { if (this.recorder)
|
|
22
|
+
this.render(this.recorder.current); });
|
|
23
|
+
this.root.querySelector("[data-start]").addEventListener("click", () => void this.run(async () => {
|
|
24
|
+
if (!this.recorder)
|
|
25
|
+
return;
|
|
26
|
+
if (["starting", "recording", "paused", "stopping"].includes(this.recorder.current.state))
|
|
27
|
+
await this.recorder.stop();
|
|
28
|
+
else
|
|
29
|
+
await this.recorder.start({ noticeAccepted: this.root.querySelector("[data-notice]").checked,
|
|
30
|
+
microphone: this.root.querySelector("[data-microphone]").checked });
|
|
31
|
+
}));
|
|
32
|
+
this.root.querySelector("[data-pause]").addEventListener("click", () => {
|
|
33
|
+
if (!this.recorder)
|
|
34
|
+
return;
|
|
35
|
+
try {
|
|
36
|
+
this.recorder.current.state === "paused" ? this.recorder.resume() : this.recorder.pause();
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
this.showError(error);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
this.root.querySelector("[data-download]").addEventListener("click", () => void this.download());
|
|
43
|
+
this.root.querySelector("[data-refresh]").addEventListener("click", () => void this.run(() => this.refreshHistory()));
|
|
44
|
+
}
|
|
45
|
+
bind(recorder, store) {
|
|
46
|
+
if (this.recorder && this.recorder !== recorder && ["starting", "recording", "paused", "stopping"].includes(this.recorder.current.state))
|
|
47
|
+
throw new Error("Stop the current recording before switching workspaces.");
|
|
48
|
+
this.unsubscribe?.();
|
|
49
|
+
this.recorder = recorder;
|
|
50
|
+
this.store = store;
|
|
51
|
+
this.unsubscribe = recorder.subscribe(snapshot => this.render(snapshot));
|
|
52
|
+
void this.run(() => this.refreshHistory());
|
|
53
|
+
}
|
|
54
|
+
connectedCallback() { if (this.recorder && !this.unsubscribe)
|
|
55
|
+
this.unsubscribe = this.recorder.subscribe(snapshot => this.render(snapshot)); }
|
|
56
|
+
disconnectedCallback() {
|
|
57
|
+
this.unsubscribe?.();
|
|
58
|
+
this.unsubscribe = null;
|
|
59
|
+
++this.historyGeneration;
|
|
60
|
+
// Removing the only visible controls cannot leave a hidden capture running.
|
|
61
|
+
if (this.recorder && ["starting", "recording", "paused"].includes(this.recorder.current.state))
|
|
62
|
+
void this.recorder.stop();
|
|
63
|
+
}
|
|
64
|
+
render(snapshot) {
|
|
65
|
+
const labels = { idle: "Ready when you are", starting: "Waiting for your audio selection…", recording: "Recording your selected audio", paused: "Recording paused", stopping: "Saving your audio…", ready: "Recording saved", error: "Recording needs attention" };
|
|
66
|
+
this.root.querySelector("[data-status]").textContent = labels[snapshot.state];
|
|
67
|
+
this.root.querySelector(".dot").classList.toggle("active", snapshot.state === "recording");
|
|
68
|
+
const active = ["starting", "recording", "paused", "stopping"].includes(snapshot.state);
|
|
69
|
+
const start = this.root.querySelector("[data-start]");
|
|
70
|
+
start.textContent = active ? "Stop recording" : "Choose audio & record";
|
|
71
|
+
start.disabled = snapshot.state === "stopping" || !this.recorder || !active && !this.root.querySelector("[data-notice]").checked;
|
|
72
|
+
start.classList.toggle("end", active);
|
|
73
|
+
const pause = this.root.querySelector("[data-pause]");
|
|
74
|
+
pause.disabled = !["recording", "paused"].includes(snapshot.state);
|
|
75
|
+
pause.textContent = snapshot.state === "paused" ? "Resume" : "Pause";
|
|
76
|
+
this.root.querySelector("[data-notice]").disabled = active;
|
|
77
|
+
this.root.querySelector("[data-microphone]").disabled = active;
|
|
78
|
+
this.root.querySelector("[data-download]").hidden = !snapshot.recording?.bytes || active;
|
|
79
|
+
this.root.querySelector(".error").textContent = snapshot.error ?? "";
|
|
80
|
+
this.root.querySelector(".saved").textContent = snapshot.recording?.bytes ? `${Math.ceil(snapshot.recording.bytes / 1024)} KB saved · ${snapshot.recording.state === "incomplete" ? "Review incomplete recording" : "Audio only"}` : "";
|
|
81
|
+
}
|
|
82
|
+
async refreshHistory() {
|
|
83
|
+
const recorder = this.recorder, store = this.store, generation = ++this.historyGeneration;
|
|
84
|
+
if (!recorder || !store)
|
|
85
|
+
return;
|
|
86
|
+
const records = await store.list(recorder.recordingScope);
|
|
87
|
+
if (generation !== this.historyGeneration || recorder !== this.recorder)
|
|
88
|
+
return;
|
|
89
|
+
const list = this.root.querySelector("[data-history]");
|
|
90
|
+
list.replaceChildren();
|
|
91
|
+
for (const recording of records.slice(0, 40)) {
|
|
92
|
+
const item = document.createElement("li"), label = document.createElement("p"), action = document.createElement("button");
|
|
93
|
+
label.textContent = `${new Date(recording.createdAt).toLocaleString()} · ${Math.ceil(recording.bytes / 1024)} KB · ${recording.state === "ready" ? "Saved" : recording.state === "incomplete" ? "Incomplete — review audio" : "Active or interrupted"}`;
|
|
94
|
+
action.textContent = recording.state === "recording" ? "Recover interrupted recording" : "Save recording";
|
|
95
|
+
action.addEventListener("click", () => void this.run(async () => {
|
|
96
|
+
if (recorder !== this.recorder)
|
|
97
|
+
return;
|
|
98
|
+
if (recording.state === "recording") {
|
|
99
|
+
await store.recover(recording.scope, recording.id);
|
|
100
|
+
await this.refreshHistory();
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
await this.download(recording);
|
|
104
|
+
}));
|
|
105
|
+
item.append(label, action);
|
|
106
|
+
list.append(item);
|
|
107
|
+
}
|
|
108
|
+
if (!records.length) {
|
|
109
|
+
const item = document.createElement("li");
|
|
110
|
+
item.textContent = "No saved recordings in this workspace.";
|
|
111
|
+
list.append(item);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async download(selected) {
|
|
115
|
+
await this.run(async () => {
|
|
116
|
+
const recording = selected ?? this.recorder?.current.recording;
|
|
117
|
+
if (!recording || !this.store)
|
|
118
|
+
throw new Error("No saved recording.");
|
|
119
|
+
if (recording.scope !== this.recorder?.recordingScope)
|
|
120
|
+
throw new Error("No recording in this workspace.");
|
|
121
|
+
const blob = await this.store.audio(recording.scope, recording.id), url = URL.createObjectURL(blob);
|
|
122
|
+
const link = document.createElement("a");
|
|
123
|
+
link.href = url;
|
|
124
|
+
link.download = `Meeting-${new Date(recording.createdAt).toISOString().replace(/[:.]/g, "-")}.${recording.mimeType.includes("mp4") ? "m4a" : "webm"}`;
|
|
125
|
+
link.click();
|
|
126
|
+
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
showError(error) { this.root.querySelector(".error").textContent = error instanceof Error ? error.message : "Recording action failed."; }
|
|
130
|
+
async run(action) { try {
|
|
131
|
+
await action();
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
this.showError(error);
|
|
135
|
+
} }
|
|
136
|
+
}
|
|
137
|
+
if (!customElements.get("pyai-meeting-recorder"))
|
|
138
|
+
customElements.define("pyai-meeting-recorder", PyaiMeetingRecorderElement);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MeetingRecording, MeetingRecordingStore } from "./meetingRecorder.ts";
|
|
2
|
+
/** Private, scoped chunk storage. Completed and interrupted captures survive
|
|
3
|
+
* reload; storage errors never cause a silent fallback to public uploads. */
|
|
4
|
+
export declare class IndexedDbMeetingRecordingStore implements MeetingRecordingStore {
|
|
5
|
+
private readonly database;
|
|
6
|
+
constructor(name?: string);
|
|
7
|
+
private lockName;
|
|
8
|
+
acquire(scope: string, id: string): Promise<() => void>;
|
|
9
|
+
recover(scope: string, id: string): Promise<MeetingRecording>;
|
|
10
|
+
private transact;
|
|
11
|
+
create(recording: MeetingRecording): Promise<void>;
|
|
12
|
+
append(scope: string, id: string, sequence: number, bytes: Blob): Promise<void>;
|
|
13
|
+
get(scope: string, id: string): Promise<MeetingRecording | null>;
|
|
14
|
+
finish(scope: string, id: string, state: "ready" | "incomplete", endedAt: number, error: string | null, signalObserved?: MeetingRecording["signalObserved"]): Promise<MeetingRecording>;
|
|
15
|
+
list(scope: string): Promise<MeetingRecording[]>;
|
|
16
|
+
audio(scope: string, id: string): Promise<Blob>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** Private, scoped chunk storage. Completed and interrupted captures survive
|
|
2
|
+
* reload; storage errors never cause a silent fallback to public uploads. */
|
|
3
|
+
export class IndexedDbMeetingRecordingStore {
|
|
4
|
+
database;
|
|
5
|
+
constructor(name = "pyai-meeting-recordings") {
|
|
6
|
+
this.database = new Promise((resolve, reject) => {
|
|
7
|
+
const request = indexedDB.open(name, 1);
|
|
8
|
+
request.onupgradeneeded = () => {
|
|
9
|
+
request.result.createObjectStore("recordings", { keyPath: ["scope", "id"] });
|
|
10
|
+
const chunks = request.result.createObjectStore("chunks", { keyPath: ["scope", "id", "sequence"] });
|
|
11
|
+
chunks.createIndex("recording", ["scope", "id"]);
|
|
12
|
+
};
|
|
13
|
+
request.onsuccess = () => { request.result.onversionchange = () => request.result.close(); resolve(request.result); };
|
|
14
|
+
request.onerror = () => reject(new Error("Private recording storage is unavailable."));
|
|
15
|
+
request.onblocked = () => reject(new Error("Close the older recorder tab to upgrade storage."));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
lockName(scope, id) { return `pyai-meeting:${JSON.stringify([scope, id])}`; }
|
|
19
|
+
async acquire(scope, id) {
|
|
20
|
+
if (!navigator.locks)
|
|
21
|
+
throw new Error("This browser cannot safely recover meeting recordings. Use a current supported browser.");
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
void navigator.locks.request(this.lockName(scope, id), { ifAvailable: true }, async (lock) => {
|
|
24
|
+
if (!lock)
|
|
25
|
+
throw new Error("This recording is active in another tab.");
|
|
26
|
+
await new Promise(release => resolve(release));
|
|
27
|
+
}).catch(reject);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async recover(scope, id) {
|
|
31
|
+
const release = await this.acquire(scope, id);
|
|
32
|
+
try {
|
|
33
|
+
return await this.finish(scope, id, "incomplete", Date.now(), "Recording was interrupted. Saved audio was recovered; review it before use.");
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
release();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async transact(stores, mode, action) {
|
|
40
|
+
const database = await this.database;
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const tx = database.transaction(stores, mode);
|
|
43
|
+
let value, error = null;
|
|
44
|
+
tx.oncomplete = () => resolve(value);
|
|
45
|
+
tx.onerror = tx.onabort = () => reject(new Error(error ?? "Recording storage failed; earlier audio remains saved."));
|
|
46
|
+
action(tx, next => { value = next; }, message => { error = message; tx.abort(); });
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
create(recording) {
|
|
50
|
+
return this.transact(["recordings"], "readwrite", (tx, done) => { tx.objectStore("recordings").add(structuredClone(recording)); done(undefined); });
|
|
51
|
+
}
|
|
52
|
+
append(scope, id, sequence, bytes) {
|
|
53
|
+
return this.transact(["recordings", "chunks"], "readwrite", (tx, done, fail) => {
|
|
54
|
+
const records = tx.objectStore("recordings"), request = records.get([scope, id]);
|
|
55
|
+
request.onsuccess = () => {
|
|
56
|
+
const current = request.result;
|
|
57
|
+
if (!current || current.state !== "recording" || current.chunks !== sequence) {
|
|
58
|
+
fail("Recording chunk sequence changed.");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (current.bytes + bytes.size > current.maxBytes) {
|
|
62
|
+
fail("Recording storage limit reached; earlier audio remains saved.");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
tx.objectStore("chunks").add({ scope, id, sequence, bytes });
|
|
66
|
+
records.put({ ...current, bytes: current.bytes + bytes.size, chunks: sequence + 1 });
|
|
67
|
+
done(undefined);
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
get(scope, id) {
|
|
72
|
+
return this.transact(["recordings"], "readonly", (tx, done) => {
|
|
73
|
+
const request = tx.objectStore("recordings").get([scope, id]);
|
|
74
|
+
request.onsuccess = () => done(request.result ?? null);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
finish(scope, id, state, endedAt, error, signalObserved) {
|
|
78
|
+
return this.transact(["recordings"], "readwrite", (tx, done, fail) => {
|
|
79
|
+
const records = tx.objectStore("recordings"), request = records.get([scope, id]);
|
|
80
|
+
request.onsuccess = () => {
|
|
81
|
+
const current = request.result;
|
|
82
|
+
if (!current) {
|
|
83
|
+
fail("No recording in this workspace.");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (current.state !== "recording") {
|
|
87
|
+
done(current);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const final = { ...current, state, endedAt, error, ...(signalObserved ? { signalObserved } : {}) };
|
|
91
|
+
records.put(final);
|
|
92
|
+
done(final);
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
list(scope) {
|
|
97
|
+
return this.transact(["recordings"], "readonly", (tx, done) => {
|
|
98
|
+
const request = tx.objectStore("recordings").getAll(IDBKeyRange.bound([scope, ""], [scope, "\uffff"]));
|
|
99
|
+
request.onsuccess = () => done(request.result.sort((a, b) => b.createdAt - a.createdAt));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async audio(scope, id) {
|
|
103
|
+
return this.transact(["recordings", "chunks"], "readonly", (tx, done, fail) => {
|
|
104
|
+
const record = tx.objectStore("recordings").get([scope, id]);
|
|
105
|
+
record.onsuccess = () => {
|
|
106
|
+
const current = record.result;
|
|
107
|
+
if (!current || current.state === "recording" || !current.bytes) {
|
|
108
|
+
fail("Stop or recover this recording before downloading it.");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const chunks = tx.objectStore("chunks").index("recording").getAll(IDBKeyRange.only([scope, id]));
|
|
112
|
+
chunks.onsuccess = () => {
|
|
113
|
+
const rows = chunks.result;
|
|
114
|
+
rows.sort((a, b) => a.sequence - b.sequence);
|
|
115
|
+
if (rows.length !== current.chunks || rows.some((row, i) => row.sequence !== i)) {
|
|
116
|
+
fail("Saved audio is incomplete; preserve its chunks for recovery.");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const blob = new Blob(rows.map(row => row.bytes), { type: current.mimeType });
|
|
120
|
+
if (blob.size !== current.bytes) {
|
|
121
|
+
fail("Saved recording size changed.");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
done(blob);
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|