@peers-app/peers-ui 0.34.14 → 0.34.15
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/dist/apps-home/app-menu.d.ts +1 -2
- package/dist/apps-home/app-menu.js +29 -25
- package/dist/command-palette/command-palette-ui.js +13 -12
- package/dist/components/autocomplete-chips.d.ts +18 -0
- package/dist/components/autocomplete-chips.js +49 -0
- package/dist/components/autocomplete.d.ts +88 -0
- package/dist/components/autocomplete.js +346 -0
- package/dist/components/confirm-button.d.ts +26 -0
- package/dist/components/confirm-button.js +55 -0
- package/dist/components/data-grid/autocomplete.d.ts +1 -31
- package/dist/components/data-grid/autocomplete.js +5 -197
- package/dist/components/empty-state.d.ts +16 -0
- package/dist/components/empty-state.js +16 -0
- package/dist/components/group-switcher.d.ts +3 -3
- package/dist/components/group-switcher.js +22 -17
- package/dist/components/inline-create-form.d.ts +22 -0
- package/dist/components/inline-create-form.js +56 -0
- package/dist/components/list-row.d.ts +33 -0
- package/dist/components/list-row.js +30 -0
- package/dist/components/list-screen.d.ts +31 -3
- package/dist/components/list-screen.js +61 -28
- package/dist/components/markdown-editor/format-bar.js +15 -40
- package/dist/components/markdown-editor/link-plugin.js +38 -9
- package/dist/components/markdown-editor/selection-bar-place.d.ts +37 -0
- package/dist/components/markdown-editor/selection-bar-place.js +107 -0
- package/dist/components/menu-button.d.ts +34 -0
- package/dist/components/menu-button.js +66 -0
- package/dist/components/screen-header.d.ts +35 -0
- package/dist/components/screen-header.js +30 -0
- package/dist/components/search-field.d.ts +22 -0
- package/dist/components/search-field.js +22 -0
- package/dist/components/segmented-control.d.ts +25 -0
- package/dist/components/segmented-control.js +18 -0
- package/dist/components/typeahead.d.ts +9 -0
- package/dist/components/typeahead.js +7 -0
- package/dist/groups/groups-client.d.ts +23 -1
- package/dist/groups/groups-client.js +31 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +14 -1
- package/dist/isolated-screens/config.js +1 -9
- package/dist/isolated-screens/folder-picker-control.d.ts +57 -0
- package/dist/isolated-screens/folder-picker-control.js +217 -0
- package/dist/isolated-screens/folder-picker-host.d.ts +57 -0
- package/dist/isolated-screens/folder-picker-host.js +178 -0
- package/dist/isolated-screens/folder-picker-protocol.d.ts +75 -0
- package/dist/isolated-screens/folder-picker-protocol.js +104 -0
- package/dist/isolated-screens/frame-bridge.js +8 -0
- package/dist/isolated-screens/frame-document.js +2 -1
- package/dist/isolated-screens/frame-microphone.d.ts +55 -0
- package/dist/isolated-screens/frame-microphone.js +265 -0
- package/dist/isolated-screens/frame-permissions.d.ts +19 -0
- package/dist/isolated-screens/frame-permissions.js +32 -0
- package/dist/isolated-screens/frame-protocol.d.ts +26 -0
- package/dist/isolated-screens/frame-protocol.js +9 -0
- package/dist/isolated-screens/frame-pvars.d.ts +27 -0
- package/dist/isolated-screens/frame-pvars.js +101 -14
- package/dist/isolated-screens/global-widgets.d.ts +1 -2
- package/dist/isolated-screens/index.d.ts +2 -0
- package/dist/isolated-screens/index.js +3 -1
- package/dist/isolated-screens/isolated-screen.d.ts +21 -0
- package/dist/isolated-screens/isolated-screen.js +88 -5
- package/dist/isolated-screens/local-folder-picker.d.ts +55 -0
- package/dist/isolated-screens/local-folder-picker.js +143 -0
- package/dist/isolated-screens/microphone-host.d.ts +110 -0
- package/dist/isolated-screens/microphone-host.js +397 -0
- package/dist/isolated-screens/microphone-prompt.d.ts +20 -0
- package/dist/isolated-screens/microphone-prompt.js +60 -0
- package/dist/isolated-screens/piece-frames.js +5 -94
- package/dist/isolated-screens/piece-reach.d.ts +1 -0
- package/dist/isolated-screens/port-channel.d.ts +21 -11
- package/dist/isolated-screens/port-channel.js +15 -5
- package/dist/isolated-screens/slot-rect.d.ts +38 -0
- package/dist/isolated-screens/slot-rect.js +121 -0
- package/dist/isolated-screens/test-ports.d.ts +17 -0
- package/dist/isolated-screens/test-ports.js +25 -3
- package/dist/mentions/mention-chooser.js +1 -1
- package/dist/notifications/notifications-screen.js +1 -1
- package/dist/screens/data-explorer/data-explorer.d.ts +1 -0
- package/dist/screens/data-explorer/data-explorer.js +28 -10
- package/dist/screens/data-explorer/query-executor.d.ts +1 -0
- package/dist/screens/data-explorer/query-executor.js +3 -1
- package/dist/screens/groups/group-list.d.ts +13 -3
- package/dist/screens/groups/group-list.js +88 -11
- package/dist/screens/identity/identity-routes.d.ts +16 -0
- package/dist/screens/identity/identity-routes.js +27 -10
- package/dist/screens/identity/identity-screen.js +4 -1
- package/dist/screens/invites/activity-view.d.ts +3 -1
- package/dist/screens/invites/activity-view.js +7 -3
- package/dist/screens/invites/pending-invites-list.d.ts +8 -4
- package/dist/screens/invites/pending-invites-list.js +44 -45
- package/dist/screens/network-viewer/graph/network-graph-controls.js +3 -3
- package/dist/screens/packages/local-folder-grants-panel.d.ts +2 -0
- package/dist/screens/packages/local-folder-grants-panel.js +1 -1
- package/dist/screens/packages/package-info.js +2 -1
- package/dist/screens/packages/package-list.d.ts +2 -2
- package/dist/screens/packages/package-list.js +89 -105
- package/dist/screens/packages/package-microphone-panel.d.ts +14 -0
- package/dist/screens/packages/package-microphone-panel.js +62 -0
- package/dist/screens/packages/package-runtime-status.d.ts +10 -2
- package/dist/screens/packages/package-runtime-status.js +17 -4
- package/dist/screens/peer-types/peer-type-details.js +3 -2
- package/dist/screens/peer-types/peer-type-list.d.ts +1 -1
- package/dist/screens/peer-types/peer-type-list.js +4 -4
- package/dist/screens/settings/settings-page.js +1 -4
- package/dist/screens/tools/tool-details.js +2 -1
- package/dist/screens/tools/tool-list.d.ts +1 -1
- package/dist/screens/tools/tool-list.js +22 -60
- package/dist/screens/variables/variable-details.js +5 -4
- package/dist/screens/variables/variable-list.d.ts +17 -0
- package/dist/screens/variables/variable-list.js +72 -28
- package/dist/tabs-layout/network-status-details.d.ts +4 -4
- package/dist/tabs-layout/network-status-details.js +6 -5
- package/dist/tabs-layout/network-status-indicator.d.ts +1 -0
- package/dist/tabs-layout/network-status-indicator.js +1 -0
- package/dist/tabs-layout/tab-bar-shortcuts.d.ts +46 -0
- package/dist/tabs-layout/tab-bar-shortcuts.js +140 -0
- package/dist/tabs-layout/tabs-layout.js +11 -9
- package/dist/theme.css +326 -6
- package/dist/ui-contracts/popover-surface.d.ts +3 -0
- package/dist/ui-contracts/popover-surface.js +6 -3
- package/dist/ui-defaults/list-screen.js +10 -4
- package/package.json +3 -3
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TAP_MODULE = void 0;
|
|
4
|
+
exports.setMicrophoneCaptureForTests = setMicrophoneCaptureForTests;
|
|
5
|
+
exports.microphoneAllowedFor = microphoneAllowedFor;
|
|
6
|
+
exports.normalizeMicrophoneRequest = normalizeMicrophoneRequest;
|
|
7
|
+
exports.openFrameMicrophone = openFrameMicrophone;
|
|
8
|
+
exports.closeFrameMicrophone = closeFrameMicrophone;
|
|
9
|
+
exports.closeFrameMicrophones = closeFrameMicrophones;
|
|
10
|
+
exports.changeMicrophoneAnswer = changeMicrophoneAnswer;
|
|
11
|
+
exports.microphoneInUse = microphoneInUse;
|
|
12
|
+
exports.sharedTrackSettings = sharedTrackSettings;
|
|
13
|
+
const frame_permissions_1 = require("./frame-permissions");
|
|
14
|
+
const microphone_prompt_1 = require("./microphone-prompt");
|
|
15
|
+
/**
|
|
16
|
+
* The microphone for package screens in frames.
|
|
17
|
+
*
|
|
18
|
+
* A frame's opaque origin can't open the microphone: Chromium and WebKit refuse `getUserMedia`
|
|
19
|
+
* there, even with `allow="microphone"`. So the host opens it, once for each set of processing
|
|
20
|
+
* options however many screens listen, and an AudioWorklet copies each block of 128 samples into
|
|
21
|
+
* every screen stream's `MessagePort`. The blocks go from the host's audio thread to the frame's,
|
|
22
|
+
* so neither main thread handles the sound. The frame plays them into a `MediaStream`, which its
|
|
23
|
+
* `getUserMedia` returns (`frame-microphone.ts`).
|
|
24
|
+
*
|
|
25
|
+
* A package gets it only when its manifest declares it (`pkg.microphone`, with a reason) and the
|
|
26
|
+
* person allows it on this device. Peers asks once per package and keeps the answer either way.
|
|
27
|
+
* The microphone closes when the last stream on it stops, or its screen closes.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* The host's AudioWorklet module, the tap: copies each block of the microphone to every stream's
|
|
31
|
+
* port, since the engine reuses its input buffers. The copy is transferred, with one transfer
|
|
32
|
+
* list reused, so a block allocates only its copies. Exported for its tests.
|
|
33
|
+
*/
|
|
34
|
+
exports.TAP_MODULE = `
|
|
35
|
+
class PeersMicrophoneTap extends AudioWorkletProcessor {
|
|
36
|
+
constructor() {
|
|
37
|
+
super();
|
|
38
|
+
this.outs = new Map();
|
|
39
|
+
this.transfer = [null];
|
|
40
|
+
this.port.onmessage = (event) => {
|
|
41
|
+
const message = event.data;
|
|
42
|
+
if (message.type === "add") {
|
|
43
|
+
this.outs.set(message.id, message.port);
|
|
44
|
+
} else if (message.type === "remove") {
|
|
45
|
+
const port = this.outs.get(message.id);
|
|
46
|
+
this.outs.delete(message.id);
|
|
47
|
+
if (port) port.close();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
process(inputs) {
|
|
52
|
+
const channel = inputs[0] && inputs[0][0];
|
|
53
|
+
if (channel) {
|
|
54
|
+
for (const port of this.outs.values()) {
|
|
55
|
+
const copy = channel.slice();
|
|
56
|
+
this.transfer[0] = copy.buffer;
|
|
57
|
+
port.postMessage(copy, this.transfer);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
registerProcessor("peers-microphone-tap", PeersMicrophoneTap);
|
|
64
|
+
`;
|
|
65
|
+
let openCapture = openAudioCapture;
|
|
66
|
+
/**
|
|
67
|
+
* A test seam: replace how the host opens the microphone. Without an argument, the real one is
|
|
68
|
+
* back.
|
|
69
|
+
*
|
|
70
|
+
* @param factory - Opens a capture for a request.
|
|
71
|
+
*/
|
|
72
|
+
function setMicrophoneCaptureForTests(factory) {
|
|
73
|
+
openCapture = factory ?? openAudioCapture;
|
|
74
|
+
}
|
|
75
|
+
/** Open captures, by their processing options ({@link captureKey}). */
|
|
76
|
+
const captures = new Map();
|
|
77
|
+
/**
|
|
78
|
+
* Each open stream's capture, by `<frameId>:<streamId>`: the capture itself, since one that ended
|
|
79
|
+
* is no longer in {@link captures}, and its streams still close it.
|
|
80
|
+
*/
|
|
81
|
+
const streamCaptures = new Map();
|
|
82
|
+
/**
|
|
83
|
+
* Every stream asked for and not closed, from the request on: one whose screen closes while the
|
|
84
|
+
* person is asked, or the microphone opens, gets nothing.
|
|
85
|
+
*/
|
|
86
|
+
const requested = new Set();
|
|
87
|
+
/** Each stream asked for and not closed, with its package, so a refusal can stop its streams. */
|
|
88
|
+
const streamOwners = new Map();
|
|
89
|
+
/** A question on screen, by package: another of its screens waits for the same answer. */
|
|
90
|
+
const asking = new Map();
|
|
91
|
+
/** An error the frame turns back into a `DOMException` with that name. */
|
|
92
|
+
function refusal(name, message) {
|
|
93
|
+
return new Error(`${name}: ${message}`);
|
|
94
|
+
}
|
|
95
|
+
function list(variable) {
|
|
96
|
+
const value = variable();
|
|
97
|
+
return Array.isArray(value) ? value : [];
|
|
98
|
+
}
|
|
99
|
+
async function loaded(variable) {
|
|
100
|
+
await variable.loadingPromise;
|
|
101
|
+
}
|
|
102
|
+
function savedAnswer(packageId) {
|
|
103
|
+
if (list((0, frame_permissions_1.microphoneRefusedList)()).includes(packageId))
|
|
104
|
+
return false;
|
|
105
|
+
if (list((0, frame_permissions_1.microphoneAllowedList)()).includes(packageId))
|
|
106
|
+
return true;
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
/** A pending stream can be closed by its screen, by a refusal, or by resetting permission. */
|
|
110
|
+
function cancelledOpen(packageId) {
|
|
111
|
+
return savedAnswer(packageId) === false
|
|
112
|
+
? refusal("NotAllowedError", "Microphone permission was revoked")
|
|
113
|
+
: refusal("AbortError", "The microphone request was cancelled");
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Whether a package may use the microphone on this device: the person's answer, or, the first
|
|
117
|
+
* time, the one they give now. Closing the question refuses this once, without keeping it.
|
|
118
|
+
*
|
|
119
|
+
* @param packageId - The package.
|
|
120
|
+
* @param packageName - Its name, for the question.
|
|
121
|
+
* @param reason - Why it listens, from its declaration.
|
|
122
|
+
*/
|
|
123
|
+
async function microphoneAllowedFor(packageId, packageName, reason) {
|
|
124
|
+
await Promise.all([loaded((0, frame_permissions_1.microphoneAllowedList)()), loaded((0, frame_permissions_1.microphoneRefusedList)())]);
|
|
125
|
+
const answer = savedAnswer(packageId);
|
|
126
|
+
if (answer !== undefined)
|
|
127
|
+
return answer;
|
|
128
|
+
let pending = asking.get(packageId);
|
|
129
|
+
if (!pending) {
|
|
130
|
+
pending = (0, microphone_prompt_1.askMicrophone)(packageName, reason)
|
|
131
|
+
.then((answer) => {
|
|
132
|
+
if (answer !== "dismiss")
|
|
133
|
+
(0, frame_permissions_1.setMicrophoneAllowed)(packageId, answer === "allow");
|
|
134
|
+
return answer === "allow";
|
|
135
|
+
})
|
|
136
|
+
.finally(() => asking.delete(packageId));
|
|
137
|
+
asking.set(packageId, pending);
|
|
138
|
+
}
|
|
139
|
+
return pending;
|
|
140
|
+
}
|
|
141
|
+
/** Keeps what a screen may choose: the processing switches and a sensible rate. */
|
|
142
|
+
function normalizeMicrophoneRequest(value) {
|
|
143
|
+
const input = (value && typeof value === "object" ? value : {});
|
|
144
|
+
const request = {};
|
|
145
|
+
for (const key of ["echoCancellation", "noiseSuppression", "autoGainControl"]) {
|
|
146
|
+
if (typeof input[key] === "boolean")
|
|
147
|
+
request[key] = input[key];
|
|
148
|
+
}
|
|
149
|
+
const rate = input.sampleRate;
|
|
150
|
+
if (typeof rate === "number" && Number.isInteger(rate) && rate >= 8_000 && rate <= 96_000) {
|
|
151
|
+
request.sampleRate = rate;
|
|
152
|
+
}
|
|
153
|
+
return request;
|
|
154
|
+
}
|
|
155
|
+
/** Screens that ask for the same processing share a capture. Left out means on, as in browsers. */
|
|
156
|
+
function captureKey(request) {
|
|
157
|
+
const on = (flag) => (flag === false ? "0" : "1");
|
|
158
|
+
return `${on(request.echoCancellation)}${on(request.noiseSuppression)}${on(request.autoGainControl)}:${request.sampleRate ?? ""}`;
|
|
159
|
+
}
|
|
160
|
+
function streamKey(frameId, streamId) {
|
|
161
|
+
return `${frameId}:${streamId}`;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Open the microphone for one of a frame's `getUserMedia` streams, and send its sound down
|
|
165
|
+
* `port`. Refused, with the port closed, unless the package declares the microphone and the
|
|
166
|
+
* person allows it on this device.
|
|
167
|
+
*
|
|
168
|
+
* @param input.frameId - The frame.
|
|
169
|
+
* @param input.packageId - Its package.
|
|
170
|
+
* @param input.packageName - The package's name, for the question.
|
|
171
|
+
* @param input.reason - Why it listens, from its stored manifest; `undefined` when it doesn't
|
|
172
|
+
* declare the microphone.
|
|
173
|
+
* @param input.streamId - The frame's id for the stream.
|
|
174
|
+
* @param input.request - The processing it asked for, as the frame sent it.
|
|
175
|
+
* @param input.port - Where the sound goes.
|
|
176
|
+
* @returns the rate the sound is at
|
|
177
|
+
*/
|
|
178
|
+
async function openFrameMicrophone(input) {
|
|
179
|
+
const { port } = input;
|
|
180
|
+
if (!port)
|
|
181
|
+
throw new Error("The microphone needs a port for its sound");
|
|
182
|
+
const id = streamKey(input.frameId, String(input.streamId));
|
|
183
|
+
let reserved = false;
|
|
184
|
+
try {
|
|
185
|
+
if (!input.reason) {
|
|
186
|
+
throw refusal("NotAllowedError", `${input.packageName} doesn't declare the microphone (pkg.microphone)`);
|
|
187
|
+
}
|
|
188
|
+
if (requested.has(id))
|
|
189
|
+
throw new Error(`Stream ${input.streamId} is already open`);
|
|
190
|
+
requested.add(id);
|
|
191
|
+
streamOwners.set(id, {
|
|
192
|
+
packageId: input.packageId,
|
|
193
|
+
frameId: input.frameId,
|
|
194
|
+
streamId: String(input.streamId),
|
|
195
|
+
});
|
|
196
|
+
reserved = true;
|
|
197
|
+
const allowed = await microphoneAllowedFor(input.packageId, input.packageName, input.reason);
|
|
198
|
+
if (!requested.has(id))
|
|
199
|
+
throw cancelledOpen(input.packageId);
|
|
200
|
+
if (!allowed) {
|
|
201
|
+
throw refusal("NotAllowedError", `${input.packageName} isn't allowed the microphone on this device`);
|
|
202
|
+
}
|
|
203
|
+
const request = normalizeMicrophoneRequest(input.request);
|
|
204
|
+
const key = captureKey(request);
|
|
205
|
+
let open = captures.get(key);
|
|
206
|
+
if (!open) {
|
|
207
|
+
const opening = { key, capture: openCapture(request), streams: new Set() };
|
|
208
|
+
opening.capture.then(
|
|
209
|
+
// A microphone that stops by itself isn't shared again: the next stream opens it anew.
|
|
210
|
+
(capture) => capture.onEnded?.(() => {
|
|
211
|
+
if (captures.get(key) === opening)
|
|
212
|
+
captures.delete(key);
|
|
213
|
+
}), () => {
|
|
214
|
+
if (captures.get(key) === opening)
|
|
215
|
+
captures.delete(key);
|
|
216
|
+
for (const stream of opening.streams)
|
|
217
|
+
streamCaptures.delete(stream);
|
|
218
|
+
});
|
|
219
|
+
captures.set(key, opening);
|
|
220
|
+
open = opening;
|
|
221
|
+
}
|
|
222
|
+
// Reserved before the capture opens, so a stream closing meanwhile doesn't close it.
|
|
223
|
+
open.streams.add(id);
|
|
224
|
+
streamCaptures.set(id, open);
|
|
225
|
+
let capture;
|
|
226
|
+
try {
|
|
227
|
+
capture = await open.capture;
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
if (!open.streams.has(id))
|
|
231
|
+
throw cancelledOpen(input.packageId);
|
|
232
|
+
const name = error instanceof Error && error.name !== "Error" ? error.name : "NotReadableError";
|
|
233
|
+
throw refusal(name, error instanceof Error ? error.message : String(error));
|
|
234
|
+
}
|
|
235
|
+
// The screen closed, or stopped the stream, while the person was asked or the microphone opened.
|
|
236
|
+
if (!open.streams.has(id))
|
|
237
|
+
throw cancelledOpen(input.packageId);
|
|
238
|
+
if (savedAnswer(input.packageId) !== true) {
|
|
239
|
+
throw refusal("NotAllowedError", "Microphone permission changed while the microphone opened");
|
|
240
|
+
}
|
|
241
|
+
capture.add(id, port);
|
|
242
|
+
return { sampleRate: capture.sampleRate, settings: capture.settings };
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
port.close();
|
|
246
|
+
if (reserved)
|
|
247
|
+
closeFrameMicrophone(input.frameId, String(input.streamId));
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Stop sending sound to one of a frame's streams. The microphone closes with its last stream.
|
|
253
|
+
*
|
|
254
|
+
* @param frameId - The frame.
|
|
255
|
+
* @param streamId - The frame's id for the stream.
|
|
256
|
+
*/
|
|
257
|
+
function closeFrameMicrophone(frameId, streamId) {
|
|
258
|
+
const id = streamKey(frameId, String(streamId));
|
|
259
|
+
requested.delete(id);
|
|
260
|
+
streamOwners.delete(id);
|
|
261
|
+
const open = streamCaptures.get(id);
|
|
262
|
+
if (!open)
|
|
263
|
+
return;
|
|
264
|
+
streamCaptures.delete(id);
|
|
265
|
+
if (!open.streams.delete(id))
|
|
266
|
+
return;
|
|
267
|
+
void open.capture.then((capture) => capture.remove(id), () => undefined);
|
|
268
|
+
if (open.streams.size === 0) {
|
|
269
|
+
if (captures.get(open.key) === open)
|
|
270
|
+
captures.delete(open.key);
|
|
271
|
+
void open.capture.then((capture) => capture.close(), () => undefined);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Stop every stream a frame has open, as its screen closes.
|
|
276
|
+
*
|
|
277
|
+
* @param frameId - The frame.
|
|
278
|
+
*/
|
|
279
|
+
function closeFrameMicrophones(frameId) {
|
|
280
|
+
const prefix = `${frameId}:`;
|
|
281
|
+
for (const id of [...requested, ...streamCaptures.keys()]) {
|
|
282
|
+
if (id.startsWith(prefix))
|
|
283
|
+
closeFrameMicrophone(frameId, id.slice(prefix.length));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Change a package's answer on this device, as its details' switch and Ask again do. Unless it's
|
|
288
|
+
* now allowed, every stream its screens have open or are opening stops: the screen hears silence.
|
|
289
|
+
*
|
|
290
|
+
* @param packageId - The package.
|
|
291
|
+
* @param allowed - `true` to allow, `false` to refuse, `undefined` to ask again.
|
|
292
|
+
*/
|
|
293
|
+
function changeMicrophoneAnswer(packageId, allowed) {
|
|
294
|
+
(0, frame_permissions_1.setMicrophoneAllowed)(packageId, allowed);
|
|
295
|
+
if (allowed === true)
|
|
296
|
+
return;
|
|
297
|
+
for (const owner of [...streamOwners.values()]) {
|
|
298
|
+
if (owner.packageId === packageId)
|
|
299
|
+
closeFrameMicrophone(owner.frameId, owner.streamId);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/** Whether any screen's stream has the microphone open. */
|
|
303
|
+
function microphoneInUse() {
|
|
304
|
+
return streamCaptures.size > 0;
|
|
305
|
+
}
|
|
306
|
+
/** The track settings a screen's stream reports as its own: what the microphone is and does. */
|
|
307
|
+
const SHARED_TRACK_SETTINGS = [
|
|
308
|
+
"deviceId",
|
|
309
|
+
"groupId",
|
|
310
|
+
"channelCount",
|
|
311
|
+
"echoCancellation",
|
|
312
|
+
"noiseSuppression",
|
|
313
|
+
"autoGainControl",
|
|
314
|
+
"sampleRate",
|
|
315
|
+
"sampleSize",
|
|
316
|
+
];
|
|
317
|
+
/**
|
|
318
|
+
* The microphone track's settings that a screen's stream reports, so a screen that keeps settings
|
|
319
|
+
* per microphone (Voice Hub's acoustic profiles) finds the same device id as in the window.
|
|
320
|
+
*
|
|
321
|
+
* @param track - The host's microphone track.
|
|
322
|
+
*/
|
|
323
|
+
function sharedTrackSettings(track) {
|
|
324
|
+
const all = (track?.getSettings?.() ?? {});
|
|
325
|
+
const shared = {};
|
|
326
|
+
for (const key of SHARED_TRACK_SETTINGS) {
|
|
327
|
+
if (all[key] !== undefined)
|
|
328
|
+
shared[key] = all[key];
|
|
329
|
+
}
|
|
330
|
+
return shared;
|
|
331
|
+
}
|
|
332
|
+
/** Opens the microphone in the host's window, and an audio graph that taps it. */
|
|
333
|
+
async function openAudioCapture(request) {
|
|
334
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
335
|
+
audio: {
|
|
336
|
+
channelCount: 1,
|
|
337
|
+
echoCancellation: request.echoCancellation ?? true,
|
|
338
|
+
noiseSuppression: request.noiseSuppression ?? true,
|
|
339
|
+
autoGainControl: request.autoGainControl ?? true,
|
|
340
|
+
...(request.sampleRate ? { sampleRate: { ideal: request.sampleRate } } : {}),
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
let context;
|
|
344
|
+
try {
|
|
345
|
+
context = new AudioContext(request.sampleRate ? { sampleRate: request.sampleRate } : {});
|
|
346
|
+
const url = URL.createObjectURL(new Blob([exports.TAP_MODULE], { type: "text/javascript" }));
|
|
347
|
+
try {
|
|
348
|
+
await context.audioWorklet.addModule(url);
|
|
349
|
+
}
|
|
350
|
+
finally {
|
|
351
|
+
URL.revokeObjectURL(url);
|
|
352
|
+
}
|
|
353
|
+
const track = stream.getAudioTracks()[0];
|
|
354
|
+
if (!track || track.readyState === "ended") {
|
|
355
|
+
throw new DOMException("The microphone stopped while opening", "NotReadableError");
|
|
356
|
+
}
|
|
357
|
+
const source = context.createMediaStreamSource(stream);
|
|
358
|
+
const tap = new AudioWorkletNode(context, "peers-microphone-tap");
|
|
359
|
+
// Connected to the output, silenced, so the graph runs.
|
|
360
|
+
const mute = context.createGain();
|
|
361
|
+
mute.gain.value = 0;
|
|
362
|
+
source.connect(tap);
|
|
363
|
+
tap.connect(mute);
|
|
364
|
+
mute.connect(context.destination);
|
|
365
|
+
const audio = context;
|
|
366
|
+
// A browser may hold the context until the person interacts; each new stream tries again.
|
|
367
|
+
void audio.resume().catch(() => undefined);
|
|
368
|
+
return {
|
|
369
|
+
sampleRate: audio.sampleRate,
|
|
370
|
+
settings: sharedTrackSettings(track),
|
|
371
|
+
add(id, port) {
|
|
372
|
+
void audio.resume().catch(() => undefined);
|
|
373
|
+
tap.port.postMessage({ type: "add", id, port }, [port]);
|
|
374
|
+
},
|
|
375
|
+
remove(id) {
|
|
376
|
+
tap.port.postMessage({ type: "remove", id });
|
|
377
|
+
},
|
|
378
|
+
onEnded(listener) {
|
|
379
|
+
track.addEventListener("ended", listener, { once: true });
|
|
380
|
+
},
|
|
381
|
+
close() {
|
|
382
|
+
source.disconnect();
|
|
383
|
+
tap.disconnect();
|
|
384
|
+
mute.disconnect();
|
|
385
|
+
for (const track of stream.getTracks())
|
|
386
|
+
track.stop();
|
|
387
|
+
void audio.close().catch(() => undefined);
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
for (const track of stream.getTracks())
|
|
393
|
+
track.stop();
|
|
394
|
+
void context?.close().catch(() => undefined);
|
|
395
|
+
throw error;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The question Peers asks before a package's screen gets the microphone: once per package on each
|
|
3
|
+
* device. The answer is kept either way (`microphoneAllowed`, `microphoneRefused`), and the
|
|
4
|
+
* package's details change it.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* How long Allow ignores clicks after the question appears, as browsers' own permission prompts
|
|
8
|
+
* do: a screen can't time a button of its own under where Allow will be.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ALLOW_DELAY_MS = 500;
|
|
11
|
+
/** What the person said: allow, refuse, or neither (closed the question). */
|
|
12
|
+
export type MicrophoneAnswer = "allow" | "refuse" | "dismiss";
|
|
13
|
+
/**
|
|
14
|
+
* Ask the person whether a package may use the microphone on this device.
|
|
15
|
+
*
|
|
16
|
+
* @param packageName - The package's name.
|
|
17
|
+
* @param reason - Why it listens, from its declaration (`pkg.microphone`).
|
|
18
|
+
* @returns what they said
|
|
19
|
+
*/
|
|
20
|
+
export declare function askMicrophone(packageName: string, reason: string): Promise<MicrophoneAnswer>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALLOW_DELAY_MS = void 0;
|
|
4
|
+
exports.askMicrophone = askMicrophone;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
/**
|
|
7
|
+
* The question Peers asks before a package's screen gets the microphone: once per package on each
|
|
8
|
+
* device. The answer is kept either way (`microphoneAllowed`, `microphoneRefused`), and the
|
|
9
|
+
* package's details change it.
|
|
10
|
+
*/
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const client_1 = require("react-dom/client");
|
|
13
|
+
const mention_chooser_1 = require("../mentions/mention-chooser");
|
|
14
|
+
/**
|
|
15
|
+
* How long Allow ignores clicks after the question appears, as browsers' own permission prompts
|
|
16
|
+
* do: a screen can't time a button of its own under where Allow will be.
|
|
17
|
+
*/
|
|
18
|
+
exports.ALLOW_DELAY_MS = 500;
|
|
19
|
+
/**
|
|
20
|
+
* Ask the person whether a package may use the microphone on this device.
|
|
21
|
+
*
|
|
22
|
+
* @param packageName - The package's name.
|
|
23
|
+
* @param reason - Why it listens, from its declaration (`pkg.microphone`).
|
|
24
|
+
* @returns what they said
|
|
25
|
+
*/
|
|
26
|
+
function askMicrophone(packageName, reason) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
const host = document.createElement("div");
|
|
29
|
+
document.body.appendChild(host);
|
|
30
|
+
const root = (0, client_1.createRoot)(host);
|
|
31
|
+
const close = (answer) => {
|
|
32
|
+
root.unmount();
|
|
33
|
+
host.remove();
|
|
34
|
+
resolve(answer);
|
|
35
|
+
};
|
|
36
|
+
root.render((0, jsx_runtime_1.jsx)(MicrophonePrompt, { packageName: packageName, reason: reason, onClose: close }));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function MicrophonePrompt(props) {
|
|
40
|
+
const { packageName, reason, onClose } = props;
|
|
41
|
+
// Don't allow takes the focus, so a key pressed as the question appears doesn't allow it.
|
|
42
|
+
const refuseButton = (0, react_1.useRef)(null);
|
|
43
|
+
const [allowReady, setAllowReady] = (0, react_1.useState)(false);
|
|
44
|
+
(0, react_1.useEffect)(() => {
|
|
45
|
+
const timer = setTimeout(() => setAllowReady(true), exports.ALLOW_DELAY_MS);
|
|
46
|
+
return () => clearTimeout(timer);
|
|
47
|
+
}, []);
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
refuseButton.current?.focus();
|
|
50
|
+
return (0, mention_chooser_1.handleFrontDialogKeys)(() => refuseButton.current, () => onClose("dismiss"));
|
|
51
|
+
}, [onClose]);
|
|
52
|
+
return (
|
|
53
|
+
// The mention chooser's overlay and card: one look for the shell's small questions.
|
|
54
|
+
(0, jsx_runtime_1.jsx)("div", { className: "peers-mention-chooser peers-microphone-prompt", role: "dialog", "aria-modal": "true", "aria-label": "Use the microphone?", onMouseDown: (e) => {
|
|
55
|
+
if (e.target === e.currentTarget)
|
|
56
|
+
onClose("dismiss");
|
|
57
|
+
},
|
|
58
|
+
// Keys pressed here stay here, so the screen behind doesn't act on them too.
|
|
59
|
+
onKeyDown: (e) => e.stopPropagation(), children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-head", children: [(0, jsx_runtime_1.jsxs)("strong", { children: ["Let ", packageName, " use the microphone?"] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: () => onClose("dismiss") })] }), (0, jsx_runtime_1.jsxs)("div", { className: "px-3 pb-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-2 text-break", children: reason }), (0, jsx_runtime_1.jsx)("div", { className: "small text-body-secondary mb-3", children: "On this device. You can change it in the package's details." }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex justify-content-end gap-2", children: [(0, jsx_runtime_1.jsx)("button", { ref: refuseButton, type: "button", className: "btn btn-secondary", "data-microphone-answer": "refuse", onClick: () => onClose("refuse"), children: "Don't allow" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary", "data-microphone-answer": "allow", disabled: !allowReady, onClick: () => onClose("allow"), children: "Allow" })] })] })] }) }));
|
|
60
|
+
}
|
|
@@ -15,6 +15,7 @@ const focus_relay_1 = require("./focus-relay");
|
|
|
15
15
|
const frame_component_1 = require("./frame-component");
|
|
16
16
|
const frame_protocol_1 = require("./frame-protocol");
|
|
17
17
|
const frame_realm_1 = require("./frame-realm");
|
|
18
|
+
const slot_rect_1 = require("./slot-rect");
|
|
18
19
|
const wheel_relay_1 = require("./wheel-relay");
|
|
19
20
|
/**
|
|
20
21
|
* Inside a framed screen: ask the host who draws a piece.
|
|
@@ -150,43 +151,6 @@ function inlinePieceComponent(available, name) {
|
|
|
150
151
|
inlineComponents.set(key, component);
|
|
151
152
|
return component;
|
|
152
153
|
}
|
|
153
|
-
/** The part of a slot that shows: its rectangle cut by every scrolling box around it. */
|
|
154
|
-
function visibleClip(element, rect) {
|
|
155
|
-
let top = rect.top;
|
|
156
|
-
let left = rect.left;
|
|
157
|
-
let bottom = rect.bottom;
|
|
158
|
-
let right = rect.right;
|
|
159
|
-
for (let parent = element.parentElement; parent; parent = parent.parentElement) {
|
|
160
|
-
const style = getComputedStyle(parent);
|
|
161
|
-
if (style.overflowX === "visible" && style.overflowY === "visible")
|
|
162
|
-
continue;
|
|
163
|
-
const box = parent.getBoundingClientRect();
|
|
164
|
-
if (style.overflowY !== "visible") {
|
|
165
|
-
top = Math.max(top, box.top);
|
|
166
|
-
bottom = Math.min(bottom, box.bottom);
|
|
167
|
-
}
|
|
168
|
-
if (style.overflowX !== "visible") {
|
|
169
|
-
left = Math.max(left, box.left);
|
|
170
|
-
right = Math.min(right, box.right);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
top = Math.max(top, 0);
|
|
174
|
-
left = Math.max(left, 0);
|
|
175
|
-
bottom = Math.min(bottom, window.innerHeight);
|
|
176
|
-
right = Math.min(right, window.innerWidth);
|
|
177
|
-
return {
|
|
178
|
-
top: Math.max(0, top - rect.top),
|
|
179
|
-
left: Math.max(0, left - rect.left),
|
|
180
|
-
bottom: Math.max(0, rect.bottom - bottom),
|
|
181
|
-
right: Math.max(0, rect.right - right),
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Events, heard on the way down to their target, after which a slot may have moved without the
|
|
186
|
-
* screen's DOM changing: an image (or other element) that loaded, a CSS transition or animation
|
|
187
|
-
* that ended.
|
|
188
|
-
*/
|
|
189
|
-
const LAYOUT_EVENTS = ["load", "transitionend", "animationend"];
|
|
190
154
|
const slotComponents = new Map();
|
|
191
155
|
/** The embedder's loading view, over a piece's frame until the frame has drawn the piece. */
|
|
192
156
|
const LOADING_OVER_FRAME = { position: "absolute", inset: 0 };
|
|
@@ -225,6 +189,8 @@ function slotPieceComponent(available, name) {
|
|
|
225
189
|
// Each mount is a slot of its own, so a late answer to an earlier one never touches it.
|
|
226
190
|
const slotId = (0, peers_sdk_1.newid)();
|
|
227
191
|
let active = true;
|
|
192
|
+
// Where the slot is, sent to the host once it holds the slot.
|
|
193
|
+
let stopWatching;
|
|
228
194
|
setDrawn(false);
|
|
229
195
|
const mine = (payload) => payload?.slotId === slotId;
|
|
230
196
|
const stops = [
|
|
@@ -293,59 +259,11 @@ function slotPieceComponent(available, name) {
|
|
|
293
259
|
if (!active)
|
|
294
260
|
return host.notify(frame_protocol_1.FrameNotice.pieceUnmount, { slotId });
|
|
295
261
|
mounted.current = slotId;
|
|
296
|
-
|
|
297
|
-
if (slotRef.current)
|
|
298
|
-
resize.observe(slotRef.current);
|
|
299
|
-
resize.observe(document.body);
|
|
300
|
-
window.addEventListener("resize", schedule);
|
|
301
|
-
document.addEventListener("scroll", schedule, true);
|
|
302
|
-
// The whole document: a class on <html> or a style in <head> can move it too.
|
|
303
|
-
changes.observe(document.documentElement, {
|
|
304
|
-
subtree: true,
|
|
305
|
-
childList: true,
|
|
306
|
-
attributes: true,
|
|
307
|
-
characterData: true,
|
|
308
|
-
});
|
|
309
|
-
for (const type of LAYOUT_EVENTS)
|
|
310
|
-
document.addEventListener(type, check, true);
|
|
262
|
+
stopWatching = (0, slot_rect_1.watchSlotRect)(() => slotRef.current, (rect, clip) => host.notify(frame_protocol_1.FrameNotice.pieceRect, { slotId, rect, clip }));
|
|
311
263
|
if (JSON.stringify(latest.current.props) !== propsKey) {
|
|
312
264
|
host.notify(frame_protocol_1.FrameNotice.pieceProps, { slotId, props: latest.current.props });
|
|
313
265
|
}
|
|
314
266
|
}, (error) => active && setFailed(errorText(error)));
|
|
315
|
-
// Where the slot is, sent once per animation frame while anything moves it. A resize or a
|
|
316
|
-
// scroll always sends it. Content above the slot that grows or shrinks moves the slot
|
|
317
|
-
// without resizing it, so any other change in the screen (its document, an image that
|
|
318
|
-
// loaded, a transition that ended) measures the slot again, and sends only if it moved.
|
|
319
|
-
let scheduled = 0;
|
|
320
|
-
let always = false;
|
|
321
|
-
let sent = "";
|
|
322
|
-
const report = () => {
|
|
323
|
-
scheduled = 0;
|
|
324
|
-
const send = always;
|
|
325
|
-
always = false;
|
|
326
|
-
const element = slotRef.current;
|
|
327
|
-
if (!element)
|
|
328
|
-
return;
|
|
329
|
-
const rect = element.getBoundingClientRect();
|
|
330
|
-
const box = { x: rect.left, y: rect.top, width: rect.width, height: rect.height };
|
|
331
|
-
const clip = visibleClip(element, rect);
|
|
332
|
-
const key = JSON.stringify([box, clip]);
|
|
333
|
-
if (!send && key === sent)
|
|
334
|
-
return;
|
|
335
|
-
sent = key;
|
|
336
|
-
host.notify(frame_protocol_1.FrameNotice.pieceRect, { slotId, rect: box, clip });
|
|
337
|
-
};
|
|
338
|
-
const schedule = () => {
|
|
339
|
-
always = true;
|
|
340
|
-
if (!scheduled)
|
|
341
|
-
scheduled = requestAnimationFrame(report);
|
|
342
|
-
};
|
|
343
|
-
const check = () => {
|
|
344
|
-
if (!scheduled)
|
|
345
|
-
scheduled = requestAnimationFrame(report);
|
|
346
|
-
};
|
|
347
|
-
const resize = new ResizeObserver(schedule);
|
|
348
|
-
const changes = new MutationObserver(check);
|
|
349
267
|
return () => {
|
|
350
268
|
active = false;
|
|
351
269
|
if (mounted.current === slotId) {
|
|
@@ -354,14 +272,7 @@ function slotPieceComponent(available, name) {
|
|
|
354
272
|
}
|
|
355
273
|
for (const stop of stops)
|
|
356
274
|
stop();
|
|
357
|
-
|
|
358
|
-
cancelAnimationFrame(scheduled);
|
|
359
|
-
resize.disconnect();
|
|
360
|
-
changes.disconnect();
|
|
361
|
-
window.removeEventListener("resize", schedule);
|
|
362
|
-
document.removeEventListener("scroll", schedule, true);
|
|
363
|
-
for (const type of LAYOUT_EVENTS)
|
|
364
|
-
document.removeEventListener(type, check, true);
|
|
275
|
+
stopWatching?.();
|
|
365
276
|
};
|
|
366
277
|
}, [host, mode, inPopover, maxWidth]);
|
|
367
278
|
// Until the host holds the slot, its mount sends the props that are current when it does.
|
|
@@ -6,24 +6,34 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/** The smallest port the channel needs: a `MessagePort`, or one end of a test pair. */
|
|
8
8
|
export interface IPortLike {
|
|
9
|
-
postMessage(message: unknown): void;
|
|
10
|
-
addEventListener(type: "message", listener: (event:
|
|
11
|
-
|
|
12
|
-
}) => void): void;
|
|
13
|
-
removeEventListener(type: "message", listener: (event: {
|
|
14
|
-
data: unknown;
|
|
15
|
-
}) => void): void;
|
|
9
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
10
|
+
addEventListener(type: "message", listener: (event: IPortMessageEvent) => void): void;
|
|
11
|
+
removeEventListener(type: "message", listener: (event: IPortMessageEvent) => void): void;
|
|
16
12
|
start?(): void;
|
|
17
13
|
close?(): void;
|
|
18
14
|
}
|
|
19
|
-
/**
|
|
20
|
-
export
|
|
15
|
+
/** What a port's listener gets: the message, and the ports it carried. */
|
|
16
|
+
export interface IPortMessageEvent {
|
|
17
|
+
data: unknown;
|
|
18
|
+
/** Ports the sender transferred with the message. */
|
|
19
|
+
ports?: readonly MessagePort[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A request handler: its result, or what it throws, goes back to the asker. `ports` are the ports
|
|
23
|
+
* the asker transferred with the request (`request`'s `transfer`), given only when there are some.
|
|
24
|
+
*/
|
|
25
|
+
export type PortRequestHandler = (payload: any, ports?: readonly MessagePort[]) => unknown | Promise<unknown>;
|
|
21
26
|
/** A notification handler. */
|
|
22
27
|
export type PortNotifyHandler = (payload: any) => void;
|
|
23
28
|
/** Requests and notifications over one port. */
|
|
24
29
|
export interface IPortChannel {
|
|
25
|
-
/**
|
|
26
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Ask the other side, and wait for its answer. Rejects with the error it threw.
|
|
32
|
+
*
|
|
33
|
+
* @param transfer - Ports to hand over with the request, which its handler gets as `ports`
|
|
34
|
+
* (a `MessageChannel` end for a stream that shouldn't pass through the main threads).
|
|
35
|
+
*/
|
|
36
|
+
request<T = unknown>(type: string, payload?: unknown, transfer?: MessagePort[]): Promise<T>;
|
|
27
37
|
/** Tell the other side something, without waiting. */
|
|
28
38
|
notify(type: string, payload?: unknown): void;
|
|
29
39
|
/** Answer one type of request. Returns a function that stops answering. */
|