@peers-app/peers-ui 0.34.13 → 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/delegates/acts-for-you-panel.d.ts +2 -1
- package/dist/delegates/acts-for-you-panel.js +46 -17
- package/dist/delegates/delegate-request-dialog.d.ts +3 -1
- package/dist/delegates/delegate-request-dialog.js +6 -3
- 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,110 @@
|
|
|
1
|
+
import type { IFrameMicrophoneOpened, IFrameMicrophoneRequest } from "./frame-protocol";
|
|
2
|
+
/**
|
|
3
|
+
* The microphone for package screens in frames.
|
|
4
|
+
*
|
|
5
|
+
* A frame's opaque origin can't open the microphone: Chromium and WebKit refuse `getUserMedia`
|
|
6
|
+
* there, even with `allow="microphone"`. So the host opens it, once for each set of processing
|
|
7
|
+
* options however many screens listen, and an AudioWorklet copies each block of 128 samples into
|
|
8
|
+
* every screen stream's `MessagePort`. The blocks go from the host's audio thread to the frame's,
|
|
9
|
+
* so neither main thread handles the sound. The frame plays them into a `MediaStream`, which its
|
|
10
|
+
* `getUserMedia` returns (`frame-microphone.ts`).
|
|
11
|
+
*
|
|
12
|
+
* A package gets it only when its manifest declares it (`pkg.microphone`, with a reason) and the
|
|
13
|
+
* person allows it on this device. Peers asks once per package and keeps the answer either way.
|
|
14
|
+
* The microphone closes when the last stream on it stops, or its screen closes.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The host's AudioWorklet module, the tap: copies each block of the microphone to every stream's
|
|
18
|
+
* port, since the engine reuses its input buffers. The copy is transferred, with one transfer
|
|
19
|
+
* list reused, so a block allocates only its copies. Exported for its tests.
|
|
20
|
+
*/
|
|
21
|
+
export declare const TAP_MODULE = "\nclass PeersMicrophoneTap extends AudioWorkletProcessor {\n constructor() {\n super();\n this.outs = new Map();\n this.transfer = [null];\n this.port.onmessage = (event) => {\n const message = event.data;\n if (message.type === \"add\") {\n this.outs.set(message.id, message.port);\n } else if (message.type === \"remove\") {\n const port = this.outs.get(message.id);\n this.outs.delete(message.id);\n if (port) port.close();\n }\n };\n }\n process(inputs) {\n const channel = inputs[0] && inputs[0][0];\n if (channel) {\n for (const port of this.outs.values()) {\n const copy = channel.slice();\n this.transfer[0] = copy.buffer;\n port.postMessage(copy, this.transfer);\n }\n }\n return true;\n }\n}\nregisterProcessor(\"peers-microphone-tap\", PeersMicrophoneTap);\n";
|
|
22
|
+
/** One open microphone, and the audio graph that taps it. */
|
|
23
|
+
export interface IMicrophoneCapture {
|
|
24
|
+
/** The rate its blocks are at, in Hz. */
|
|
25
|
+
readonly sampleRate: number;
|
|
26
|
+
/** The microphone track's settings a screen may read ({@link sharedTrackSettings}). */
|
|
27
|
+
readonly settings: MediaTrackSettings;
|
|
28
|
+
/** Send its sound down `port`, as stream `id`. */
|
|
29
|
+
add(id: string, port: MessagePort): void;
|
|
30
|
+
/** Stop sending to stream `id`, and close its port. */
|
|
31
|
+
remove(id: string): void;
|
|
32
|
+
/** Stop the microphone. */
|
|
33
|
+
close(): void;
|
|
34
|
+
/** Call `listener` once if the microphone stops by itself (unplugged, or taken away). */
|
|
35
|
+
onEnded?(listener: () => void): void;
|
|
36
|
+
}
|
|
37
|
+
/** Opens the microphone with a screen's processing options. */
|
|
38
|
+
export type MicrophoneCaptureFactory = (request: IFrameMicrophoneRequest) => Promise<IMicrophoneCapture>;
|
|
39
|
+
/**
|
|
40
|
+
* A test seam: replace how the host opens the microphone. Without an argument, the real one is
|
|
41
|
+
* back.
|
|
42
|
+
*
|
|
43
|
+
* @param factory - Opens a capture for a request.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setMicrophoneCaptureForTests(factory?: MicrophoneCaptureFactory): void;
|
|
46
|
+
/**
|
|
47
|
+
* Whether a package may use the microphone on this device: the person's answer, or, the first
|
|
48
|
+
* time, the one they give now. Closing the question refuses this once, without keeping it.
|
|
49
|
+
*
|
|
50
|
+
* @param packageId - The package.
|
|
51
|
+
* @param packageName - Its name, for the question.
|
|
52
|
+
* @param reason - Why it listens, from its declaration.
|
|
53
|
+
*/
|
|
54
|
+
export declare function microphoneAllowedFor(packageId: string, packageName: string, reason: string): Promise<boolean>;
|
|
55
|
+
/** Keeps what a screen may choose: the processing switches and a sensible rate. */
|
|
56
|
+
export declare function normalizeMicrophoneRequest(value: unknown): IFrameMicrophoneRequest;
|
|
57
|
+
/**
|
|
58
|
+
* Open the microphone for one of a frame's `getUserMedia` streams, and send its sound down
|
|
59
|
+
* `port`. Refused, with the port closed, unless the package declares the microphone and the
|
|
60
|
+
* person allows it on this device.
|
|
61
|
+
*
|
|
62
|
+
* @param input.frameId - The frame.
|
|
63
|
+
* @param input.packageId - Its package.
|
|
64
|
+
* @param input.packageName - The package's name, for the question.
|
|
65
|
+
* @param input.reason - Why it listens, from its stored manifest; `undefined` when it doesn't
|
|
66
|
+
* declare the microphone.
|
|
67
|
+
* @param input.streamId - The frame's id for the stream.
|
|
68
|
+
* @param input.request - The processing it asked for, as the frame sent it.
|
|
69
|
+
* @param input.port - Where the sound goes.
|
|
70
|
+
* @returns the rate the sound is at
|
|
71
|
+
*/
|
|
72
|
+
export declare function openFrameMicrophone(input: {
|
|
73
|
+
frameId: string;
|
|
74
|
+
packageId: string;
|
|
75
|
+
packageName: string;
|
|
76
|
+
reason: string | undefined;
|
|
77
|
+
streamId: string;
|
|
78
|
+
request: unknown;
|
|
79
|
+
port: MessagePort | undefined;
|
|
80
|
+
}): Promise<IFrameMicrophoneOpened>;
|
|
81
|
+
/**
|
|
82
|
+
* Stop sending sound to one of a frame's streams. The microphone closes with its last stream.
|
|
83
|
+
*
|
|
84
|
+
* @param frameId - The frame.
|
|
85
|
+
* @param streamId - The frame's id for the stream.
|
|
86
|
+
*/
|
|
87
|
+
export declare function closeFrameMicrophone(frameId: string, streamId: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Stop every stream a frame has open, as its screen closes.
|
|
90
|
+
*
|
|
91
|
+
* @param frameId - The frame.
|
|
92
|
+
*/
|
|
93
|
+
export declare function closeFrameMicrophones(frameId: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Change a package's answer on this device, as its details' switch and Ask again do. Unless it's
|
|
96
|
+
* now allowed, every stream its screens have open or are opening stops: the screen hears silence.
|
|
97
|
+
*
|
|
98
|
+
* @param packageId - The package.
|
|
99
|
+
* @param allowed - `true` to allow, `false` to refuse, `undefined` to ask again.
|
|
100
|
+
*/
|
|
101
|
+
export declare function changeMicrophoneAnswer(packageId: string, allowed: boolean | undefined): void;
|
|
102
|
+
/** Whether any screen's stream has the microphone open. */
|
|
103
|
+
export declare function microphoneInUse(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* The microphone track's settings that a screen's stream reports, so a screen that keeps settings
|
|
106
|
+
* per microphone (Voice Hub's acoustic profiles) finds the same device id as in the window.
|
|
107
|
+
*
|
|
108
|
+
* @param track - The host's microphone track.
|
|
109
|
+
*/
|
|
110
|
+
export declare function sharedTrackSettings(track: MediaStreamTrack | undefined): MediaTrackSettings;
|
|
@@ -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
|
+
}
|