@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,55 @@
|
|
|
1
|
+
import { type IFrameMicrophoneRequest } from "./frame-protocol";
|
|
2
|
+
import type { IPortChannel } from "./port-channel";
|
|
3
|
+
/**
|
|
4
|
+
* A screen's `navigator.mediaDevices.getUserMedia` in its frame. The frame's opaque origin can't
|
|
5
|
+
* open the microphone, so the host does (`microphone-host.ts`) and sends its sound here, 128
|
|
6
|
+
* samples at a time, from its audio thread to this frame's over a `MessagePort`. A small
|
|
7
|
+
* AudioWorklet plays them into a `MediaStreamAudioDestinationNode`, and the screen gets that
|
|
8
|
+
* node's stream: it works with an `AudioContext`, a `MediaRecorder` or a WebRTC connection as a
|
|
9
|
+
* microphone's stream does. Only audio: the camera is refused.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The frame's AudioWorklet module: plays the host's blocks. It waits for two before it starts,
|
|
13
|
+
* and again after it runs dry; past 60 ms queued it drops the oldest down to 30 ms, so a stall
|
|
14
|
+
* doesn't leave the sound late. A whole block is copied out without a view, so playing one
|
|
15
|
+
* allocates nothing. Exported for its tests.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SOURCE_MODULE = "\nclass PeersMicrophoneSource extends AudioWorkletProcessor {\n constructor() {\n super();\n this.queue = [];\n this.offset = 0;\n this.primed = false;\n this.most = Math.ceil((0.06 * sampleRate) / 128);\n this.keep = Math.ceil(this.most / 2);\n this.port.onmessage = (event) => {\n const port = event.data && event.data.port;\n if (!port) return;\n port.onmessage = (message) => {\n this.queue.push(message.data);\n if (this.queue.length > this.most) {\n this.queue.splice(0, this.queue.length - this.keep);\n this.offset = 0;\n }\n };\n };\n }\n process(_inputs, outputs) {\n const out = outputs[0][0];\n if (!this.primed) {\n if (this.queue.length < 2) return true;\n this.primed = true;\n }\n let written = 0;\n while (written < out.length && this.queue.length) {\n const block = this.queue[0];\n const count = Math.min(out.length - written, block.length - this.offset);\n if (this.offset === 0 && count === block.length) out.set(block, written);\n else out.set(block.subarray(this.offset, this.offset + count), written);\n written += count;\n this.offset += count;\n if (this.offset >= block.length) {\n this.queue.shift();\n this.offset = 0;\n }\n }\n if (written < out.length) this.primed = false;\n return true;\n }\n}\nregisterProcessor(\"peers-microphone-source\", PeersMicrophoneSource);\n";
|
|
18
|
+
/**
|
|
19
|
+
* Give the frame's `getUserMedia` the host's microphone. The frame runtime calls it once, with
|
|
20
|
+
* its channel to the host.
|
|
21
|
+
*
|
|
22
|
+
* @param channel - The frame's channel to the host.
|
|
23
|
+
*/
|
|
24
|
+
export declare function installFrameMicrophone(channel: IPortChannel): void;
|
|
25
|
+
/**
|
|
26
|
+
* What a screen's audio constraints ask the host for.
|
|
27
|
+
*
|
|
28
|
+
* @param audio - `true`, or the audio track's constraints.
|
|
29
|
+
*/
|
|
30
|
+
export declare function frameMicrophoneRequest(audio: boolean | MediaTrackConstraints): IFrameMicrophoneRequest;
|
|
31
|
+
/**
|
|
32
|
+
* The host's refusal as the `DOMException` a browser's `getUserMedia` throws: its message starts
|
|
33
|
+
* with the exception's name (`NotAllowedError: …`).
|
|
34
|
+
*
|
|
35
|
+
* @param error - What the host's request rejected with.
|
|
36
|
+
*/
|
|
37
|
+
export declare function microphoneError(error: unknown): DOMException;
|
|
38
|
+
/**
|
|
39
|
+
* Open a stream of the host's microphone, as `getUserMedia({ audio })` does.
|
|
40
|
+
*
|
|
41
|
+
* @param channel - The frame's channel to the host.
|
|
42
|
+
* @param constraints - What the screen passed `getUserMedia`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function openFrameMicrophoneStream(channel: IPortChannel, constraints?: MediaStreamConstraints): Promise<MediaStream>;
|
|
45
|
+
/**
|
|
46
|
+
* Call `release` once every track of `stream`, and every copy made of one (`clone`, the stream's
|
|
47
|
+
* `clone`), has stopped. Stopping a track of a destination node's stream doesn't tell anyone, so
|
|
48
|
+
* `stop` is wrapped. Each track, copies too, reports the host microphone's `settings` from
|
|
49
|
+
* `getSettings` as its own.
|
|
50
|
+
*
|
|
51
|
+
* @param stream - The stream the screen gets.
|
|
52
|
+
* @param release - Called once, when the last track stops.
|
|
53
|
+
* @param settings - The host microphone track's settings.
|
|
54
|
+
*/
|
|
55
|
+
export declare function releaseWhenStopped(stream: MediaStream, release: () => void, settings?: MediaTrackSettings): void;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOURCE_MODULE = void 0;
|
|
4
|
+
exports.installFrameMicrophone = installFrameMicrophone;
|
|
5
|
+
exports.frameMicrophoneRequest = frameMicrophoneRequest;
|
|
6
|
+
exports.microphoneError = microphoneError;
|
|
7
|
+
exports.openFrameMicrophoneStream = openFrameMicrophoneStream;
|
|
8
|
+
exports.releaseWhenStopped = releaseWhenStopped;
|
|
9
|
+
const frame_protocol_1 = require("./frame-protocol");
|
|
10
|
+
/**
|
|
11
|
+
* A screen's `navigator.mediaDevices.getUserMedia` in its frame. The frame's opaque origin can't
|
|
12
|
+
* open the microphone, so the host does (`microphone-host.ts`) and sends its sound here, 128
|
|
13
|
+
* samples at a time, from its audio thread to this frame's over a `MessagePort`. A small
|
|
14
|
+
* AudioWorklet plays them into a `MediaStreamAudioDestinationNode`, and the screen gets that
|
|
15
|
+
* node's stream: it works with an `AudioContext`, a `MediaRecorder` or a WebRTC connection as a
|
|
16
|
+
* microphone's stream does. Only audio: the camera is refused.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The frame's AudioWorklet module: plays the host's blocks. It waits for two before it starts,
|
|
20
|
+
* and again after it runs dry; past 60 ms queued it drops the oldest down to 30 ms, so a stall
|
|
21
|
+
* doesn't leave the sound late. A whole block is copied out without a view, so playing one
|
|
22
|
+
* allocates nothing. Exported for its tests.
|
|
23
|
+
*/
|
|
24
|
+
exports.SOURCE_MODULE = `
|
|
25
|
+
class PeersMicrophoneSource extends AudioWorkletProcessor {
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
this.queue = [];
|
|
29
|
+
this.offset = 0;
|
|
30
|
+
this.primed = false;
|
|
31
|
+
this.most = Math.ceil((0.06 * sampleRate) / 128);
|
|
32
|
+
this.keep = Math.ceil(this.most / 2);
|
|
33
|
+
this.port.onmessage = (event) => {
|
|
34
|
+
const port = event.data && event.data.port;
|
|
35
|
+
if (!port) return;
|
|
36
|
+
port.onmessage = (message) => {
|
|
37
|
+
this.queue.push(message.data);
|
|
38
|
+
if (this.queue.length > this.most) {
|
|
39
|
+
this.queue.splice(0, this.queue.length - this.keep);
|
|
40
|
+
this.offset = 0;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
process(_inputs, outputs) {
|
|
46
|
+
const out = outputs[0][0];
|
|
47
|
+
if (!this.primed) {
|
|
48
|
+
if (this.queue.length < 2) return true;
|
|
49
|
+
this.primed = true;
|
|
50
|
+
}
|
|
51
|
+
let written = 0;
|
|
52
|
+
while (written < out.length && this.queue.length) {
|
|
53
|
+
const block = this.queue[0];
|
|
54
|
+
const count = Math.min(out.length - written, block.length - this.offset);
|
|
55
|
+
if (this.offset === 0 && count === block.length) out.set(block, written);
|
|
56
|
+
else out.set(block.subarray(this.offset, this.offset + count), written);
|
|
57
|
+
written += count;
|
|
58
|
+
this.offset += count;
|
|
59
|
+
if (this.offset >= block.length) {
|
|
60
|
+
this.queue.shift();
|
|
61
|
+
this.offset = 0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (written < out.length) this.primed = false;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
registerProcessor("peers-microphone-source", PeersMicrophoneSource);
|
|
69
|
+
`;
|
|
70
|
+
/**
|
|
71
|
+
* As a `data:` URL: WebKit refuses a `blob:` worklet module in an opaque-origin frame ("Cross-origin
|
|
72
|
+
* script load denied"). The frame's policy allows `data:` scripts for it.
|
|
73
|
+
*/
|
|
74
|
+
const SOURCE_URL = `data:text/javascript;base64,${btoa(exports.SOURCE_MODULE)}`;
|
|
75
|
+
let nextStreamId = 1;
|
|
76
|
+
/**
|
|
77
|
+
* Give the frame's `getUserMedia` the host's microphone. The frame runtime calls it once, with
|
|
78
|
+
* its channel to the host.
|
|
79
|
+
*
|
|
80
|
+
* @param channel - The frame's channel to the host.
|
|
81
|
+
*/
|
|
82
|
+
function installFrameMicrophone(channel) {
|
|
83
|
+
const devices = globalThis.navigator?.mediaDevices;
|
|
84
|
+
if (!devices)
|
|
85
|
+
return;
|
|
86
|
+
const getUserMedia = (constraints) => openFrameMicrophoneStream(channel, constraints);
|
|
87
|
+
Object.defineProperty(devices, "getUserMedia", {
|
|
88
|
+
value: getUserMedia,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/** A boolean constraint: `true`, or `{ exact: true }`, or `{ ideal: true }`. */
|
|
94
|
+
function booleanConstraint(value) {
|
|
95
|
+
if (typeof value === "boolean")
|
|
96
|
+
return value;
|
|
97
|
+
if (value && typeof value === "object") {
|
|
98
|
+
const { exact, ideal } = value;
|
|
99
|
+
if (typeof exact === "boolean")
|
|
100
|
+
return exact;
|
|
101
|
+
if (typeof ideal === "boolean")
|
|
102
|
+
return ideal;
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
/** A number constraint: `16000`, or `{ exact }`, or `{ ideal }`. */
|
|
107
|
+
function numberConstraint(value) {
|
|
108
|
+
if (typeof value === "number")
|
|
109
|
+
return value;
|
|
110
|
+
if (value && typeof value === "object") {
|
|
111
|
+
const { exact, ideal } = value;
|
|
112
|
+
if (typeof exact === "number")
|
|
113
|
+
return exact;
|
|
114
|
+
if (typeof ideal === "number")
|
|
115
|
+
return ideal;
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* What a screen's audio constraints ask the host for.
|
|
121
|
+
*
|
|
122
|
+
* @param audio - `true`, or the audio track's constraints.
|
|
123
|
+
*/
|
|
124
|
+
function frameMicrophoneRequest(audio) {
|
|
125
|
+
if (typeof audio !== "object")
|
|
126
|
+
return {};
|
|
127
|
+
const request = {};
|
|
128
|
+
for (const key of ["echoCancellation", "noiseSuppression", "autoGainControl"]) {
|
|
129
|
+
const flag = booleanConstraint(audio[key]);
|
|
130
|
+
if (flag !== undefined)
|
|
131
|
+
request[key] = flag;
|
|
132
|
+
}
|
|
133
|
+
const rate = numberConstraint(audio.sampleRate);
|
|
134
|
+
if (rate !== undefined)
|
|
135
|
+
request.sampleRate = rate;
|
|
136
|
+
return request;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The host's refusal as the `DOMException` a browser's `getUserMedia` throws: its message starts
|
|
140
|
+
* with the exception's name (`NotAllowedError: …`).
|
|
141
|
+
*
|
|
142
|
+
* @param error - What the host's request rejected with.
|
|
143
|
+
*/
|
|
144
|
+
function microphoneError(error) {
|
|
145
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
146
|
+
const named = /^([A-Za-z]+Error): ([\s\S]*)$/.exec(message);
|
|
147
|
+
return named ? new DOMException(named[2], named[1]) : new DOMException(message, "AbortError");
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Open a stream of the host's microphone, as `getUserMedia({ audio })` does.
|
|
151
|
+
*
|
|
152
|
+
* @param channel - The frame's channel to the host.
|
|
153
|
+
* @param constraints - What the screen passed `getUserMedia`.
|
|
154
|
+
*/
|
|
155
|
+
async function openFrameMicrophoneStream(channel, constraints) {
|
|
156
|
+
if (constraints?.video) {
|
|
157
|
+
throw new DOMException("A package's screen can use the microphone, not the camera", "NotAllowedError");
|
|
158
|
+
}
|
|
159
|
+
if (!constraints?.audio) {
|
|
160
|
+
throw new TypeError("getUserMedia needs { audio }");
|
|
161
|
+
}
|
|
162
|
+
const streamId = String(nextStreamId++);
|
|
163
|
+
const { port1, port2 } = new MessageChannel();
|
|
164
|
+
let opened;
|
|
165
|
+
try {
|
|
166
|
+
opened = await channel.request(frame_protocol_1.FrameRequest.microphoneOpen, { streamId, request: frameMicrophoneRequest(constraints.audio) }, [port2]);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
port1.close();
|
|
170
|
+
port2.close();
|
|
171
|
+
throw microphoneError(error);
|
|
172
|
+
}
|
|
173
|
+
const closed = () => channel.notify(frame_protocol_1.FrameNotice.microphoneClose, { streamId });
|
|
174
|
+
let context;
|
|
175
|
+
try {
|
|
176
|
+
context = new AudioContext({ sampleRate: opened.sampleRate });
|
|
177
|
+
await context.audioWorklet.addModule(SOURCE_URL);
|
|
178
|
+
const source = new AudioWorkletNode(context, "peers-microphone-source", {
|
|
179
|
+
numberOfInputs: 0,
|
|
180
|
+
outputChannelCount: [1],
|
|
181
|
+
});
|
|
182
|
+
source.port.postMessage({ port: port1 }, [port1]);
|
|
183
|
+
const destination = context.createMediaStreamDestination();
|
|
184
|
+
destination.channelCount = 1;
|
|
185
|
+
source.connect(destination);
|
|
186
|
+
resumeWhenAllowed(context);
|
|
187
|
+
const audio = context;
|
|
188
|
+
releaseWhenStopped(destination.stream, () => {
|
|
189
|
+
source.disconnect();
|
|
190
|
+
void audio.close().catch(() => undefined);
|
|
191
|
+
closed();
|
|
192
|
+
}, opened.settings);
|
|
193
|
+
return destination.stream;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
port1.close();
|
|
197
|
+
void context?.close().catch(() => undefined);
|
|
198
|
+
closed();
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Start the stream's audio now, or, where the browser holds it until the person interacts (WebKit,
|
|
204
|
+
* a browser's autoplay policy), at their next tap or key in the frame.
|
|
205
|
+
*/
|
|
206
|
+
function resumeWhenAllowed(context) {
|
|
207
|
+
if (context.state === "running")
|
|
208
|
+
return;
|
|
209
|
+
const events = ["pointerdown", "keydown", "touchend"];
|
|
210
|
+
const resume = () => void context.resume().catch(() => undefined);
|
|
211
|
+
const stop = () => {
|
|
212
|
+
if (context.state === "suspended")
|
|
213
|
+
return;
|
|
214
|
+
for (const type of events)
|
|
215
|
+
document.removeEventListener(type, resume, true);
|
|
216
|
+
context.removeEventListener("statechange", stop);
|
|
217
|
+
};
|
|
218
|
+
for (const type of events)
|
|
219
|
+
document.addEventListener(type, resume, true);
|
|
220
|
+
context.addEventListener("statechange", stop);
|
|
221
|
+
resume();
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Call `release` once every track of `stream`, and every copy made of one (`clone`, the stream's
|
|
225
|
+
* `clone`), has stopped. Stopping a track of a destination node's stream doesn't tell anyone, so
|
|
226
|
+
* `stop` is wrapped. Each track, copies too, reports the host microphone's `settings` from
|
|
227
|
+
* `getSettings` as its own.
|
|
228
|
+
*
|
|
229
|
+
* @param stream - The stream the screen gets.
|
|
230
|
+
* @param release - Called once, when the last track stops.
|
|
231
|
+
* @param settings - The host microphone track's settings.
|
|
232
|
+
*/
|
|
233
|
+
function releaseWhenStopped(stream, release, settings = {}) {
|
|
234
|
+
const live = new Set();
|
|
235
|
+
const watch = (track) => {
|
|
236
|
+
const clone = track.clone.bind(track);
|
|
237
|
+
const getSettings = track.getSettings?.bind(track);
|
|
238
|
+
track.getSettings = () => ({ ...(getSettings?.() ?? {}), ...settings });
|
|
239
|
+
track.clone = () => {
|
|
240
|
+
const copy = clone();
|
|
241
|
+
watch(copy);
|
|
242
|
+
return copy;
|
|
243
|
+
};
|
|
244
|
+
if (track.readyState === "ended")
|
|
245
|
+
return;
|
|
246
|
+
live.add(track);
|
|
247
|
+
const stop = track.stop.bind(track);
|
|
248
|
+
track.stop = () => {
|
|
249
|
+
stop();
|
|
250
|
+
if (live.delete(track) && live.size === 0)
|
|
251
|
+
release();
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
const watchStream = (target) => {
|
|
255
|
+
target.clone = () => {
|
|
256
|
+
// Tracks added by the screen keep their own settings and lifetime when copied.
|
|
257
|
+
const copy = new MediaStream(target.getTracks().map((track) => track.clone()));
|
|
258
|
+
watchStream(copy);
|
|
259
|
+
return copy;
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
for (const track of stream.getTracks())
|
|
263
|
+
watch(track);
|
|
264
|
+
watchStream(stream);
|
|
265
|
+
}
|
|
@@ -9,3 +9,22 @@ export declare const globalWidgetsOff: Observable<string[]>;
|
|
|
9
9
|
* @param on - Whether it shows.
|
|
10
10
|
*/
|
|
11
11
|
export declare function setGlobalWidgetOn(packageId: string, widgetId: string, on: boolean): void;
|
|
12
|
+
/**
|
|
13
|
+
* Packages allowed the microphone on this device, by id. Read only when a screen asks for the
|
|
14
|
+
* microphone or a package's details open, not as peers-ui loads; each call returns the same
|
|
15
|
+
* variable.
|
|
16
|
+
*/
|
|
17
|
+
export declare function microphoneAllowedList(): Observable<string[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Packages refused the microphone on this device, by id: their screens aren't asked about again.
|
|
20
|
+
* Read only when needed, as {@link microphoneAllowedList} is.
|
|
21
|
+
*/
|
|
22
|
+
export declare function microphoneRefusedList(): Observable<string[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Allow or refuse a package the microphone on this device, or forget the answer, so Peers asks
|
|
25
|
+
* again the next time one of its screens wants it.
|
|
26
|
+
*
|
|
27
|
+
* @param packageId - The package.
|
|
28
|
+
* @param allowed - `true` to allow, `false` to refuse, `undefined` to ask again.
|
|
29
|
+
*/
|
|
30
|
+
export declare function setMicrophoneAllowed(packageId: string, allowed: boolean | undefined): void;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.globalWidgetsOff = void 0;
|
|
4
4
|
exports.setGlobalWidgetOn = setGlobalWidgetOn;
|
|
5
|
+
exports.microphoneAllowedList = microphoneAllowedList;
|
|
6
|
+
exports.microphoneRefusedList = microphoneRefusedList;
|
|
7
|
+
exports.setMicrophoneAllowed = setMicrophoneAllowed;
|
|
5
8
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
9
|
const frame_realm_1 = require("./frame-realm");
|
|
7
10
|
// What the person chose for packages' global widgets on this device. Peers' own variables: a
|
|
@@ -31,3 +34,32 @@ function setGlobalWidgetOn(packageId, widgetId, on) {
|
|
|
31
34
|
const without = current.filter((entry) => entry !== key);
|
|
32
35
|
(0, exports.globalWidgetsOff)(on ? without : [...without, key]);
|
|
33
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Packages allowed the microphone on this device, by id. Read only when a screen asks for the
|
|
39
|
+
* microphone or a package's details open, not as peers-ui loads; each call returns the same
|
|
40
|
+
* variable.
|
|
41
|
+
*/
|
|
42
|
+
function microphoneAllowedList() {
|
|
43
|
+
return hostDeviceList("microphoneAllowed");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Packages refused the microphone on this device, by id: their screens aren't asked about again.
|
|
47
|
+
* Read only when needed, as {@link microphoneAllowedList} is.
|
|
48
|
+
*/
|
|
49
|
+
function microphoneRefusedList() {
|
|
50
|
+
return hostDeviceList("microphoneRefused");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Allow or refuse a package the microphone on this device, or forget the answer, so Peers asks
|
|
54
|
+
* again the next time one of its screens wants it.
|
|
55
|
+
*
|
|
56
|
+
* @param packageId - The package.
|
|
57
|
+
* @param allowed - `true` to allow, `false` to refuse, `undefined` to ask again.
|
|
58
|
+
*/
|
|
59
|
+
function setMicrophoneAllowed(packageId, allowed) {
|
|
60
|
+
const allowedList = microphoneAllowedList();
|
|
61
|
+
const refusedList = microphoneRefusedList();
|
|
62
|
+
const without = (list) => (Array.isArray(list()) ? list() : []).filter((entry) => entry !== packageId);
|
|
63
|
+
allowedList(allowed === true ? [...without(allowedList), packageId] : without(allowedList));
|
|
64
|
+
refusedList(allowed === false ? [...without(refusedList), packageId] : without(refusedList));
|
|
65
|
+
}
|
|
@@ -146,7 +146,31 @@ export declare const FrameRequest: {
|
|
|
146
146
|
* (a screen asking its global widget to open): `{ id }`.
|
|
147
147
|
*/
|
|
148
148
|
readonly commandRun: "command.run";
|
|
149
|
+
/**
|
|
150
|
+
* Open the microphone for one of the frame's `getUserMedia` streams: `{ streamId, request }`
|
|
151
|
+
* (an {@link IFrameMicrophoneRequest}), with one end of a `MessageChannel` transferred. Once the
|
|
152
|
+
* person allows the package, the host's audio thread sends the sound down that port, 128
|
|
153
|
+
* samples at a time, and answers an {@link IFrameMicrophoneOpened}.
|
|
154
|
+
*/
|
|
155
|
+
readonly microphoneOpen: "media.microphone.open";
|
|
149
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* What the host answers when it opens the microphone for a stream: the rate its blocks are at, and
|
|
159
|
+
* the microphone track's own settings (its device id among them, so a screen that keeps settings
|
|
160
|
+
* per microphone finds the ones it kept in the window).
|
|
161
|
+
*/
|
|
162
|
+
export interface IFrameMicrophoneOpened {
|
|
163
|
+
sampleRate: number;
|
|
164
|
+
settings: MediaTrackSettings;
|
|
165
|
+
}
|
|
166
|
+
/** The processing a screen asked for, from its `getUserMedia` audio constraints. */
|
|
167
|
+
export interface IFrameMicrophoneRequest {
|
|
168
|
+
echoCancellation?: boolean;
|
|
169
|
+
noiseSuppression?: boolean;
|
|
170
|
+
autoGainControl?: boolean;
|
|
171
|
+
/** The rate the screen asked for, in Hz, when it asked for one. */
|
|
172
|
+
sampleRate?: number;
|
|
173
|
+
}
|
|
150
174
|
/** A notification the frame sends the host, by name. */
|
|
151
175
|
export declare const FrameNotice: {
|
|
152
176
|
/** The runtime has started and waits for its init. */
|
|
@@ -219,6 +243,8 @@ export declare const FrameNotice: {
|
|
|
219
243
|
* so the drag doesn't lose the pointer at the frame's edge.
|
|
220
244
|
*/
|
|
221
245
|
readonly widgetCapture: "widget.capture";
|
|
246
|
+
/** Every track of one of the frame's microphone streams stopped: `{ streamId }`. */
|
|
247
|
+
readonly microphoneClose: "media.microphone.close";
|
|
222
248
|
};
|
|
223
249
|
/** A request the host makes of the frame, by name. */
|
|
224
250
|
export declare const HostRequest: {
|
|
@@ -59,6 +59,13 @@ exports.FrameRequest = {
|
|
|
59
59
|
* (a screen asking its global widget to open): `{ id }`.
|
|
60
60
|
*/
|
|
61
61
|
commandRun: "command.run",
|
|
62
|
+
/**
|
|
63
|
+
* Open the microphone for one of the frame's `getUserMedia` streams: `{ streamId, request }`
|
|
64
|
+
* (an {@link IFrameMicrophoneRequest}), with one end of a `MessageChannel` transferred. Once the
|
|
65
|
+
* person allows the package, the host's audio thread sends the sound down that port, 128
|
|
66
|
+
* samples at a time, and answers an {@link IFrameMicrophoneOpened}.
|
|
67
|
+
*/
|
|
68
|
+
microphoneOpen: "media.microphone.open",
|
|
62
69
|
};
|
|
63
70
|
/** A notification the frame sends the host, by name. */
|
|
64
71
|
exports.FrameNotice = {
|
|
@@ -132,6 +139,8 @@ exports.FrameNotice = {
|
|
|
132
139
|
* so the drag doesn't lose the pointer at the frame's edge.
|
|
133
140
|
*/
|
|
134
141
|
widgetCapture: "widget.capture",
|
|
142
|
+
/** Every track of one of the frame's microphone streams stopped: `{ streamId }`. */
|
|
143
|
+
microphoneClose: "media.microphone.close",
|
|
135
144
|
};
|
|
136
145
|
/** A request the host makes of the frame, by name. */
|
|
137
146
|
exports.HostRequest = {
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
import { type IPersistentVarBackendRequest, type Observable } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* The host side of an isolated screen's persistent variables.
|
|
4
|
+
*
|
|
5
|
+
* A screen's frame asks the host for every variable its code (and peers-ui's, inside the frame)
|
|
6
|
+
* declares. The host answers in one of three ways:
|
|
7
|
+
*
|
|
8
|
+
* - `mainContentPath` is the screen's tab path; writing it navigates the tab.
|
|
9
|
+
* - A few variables Peers keeps for every screen (this device, the active group, the theme, the
|
|
10
|
+
* open tabs) are the host's own, read only. A write is ignored, and the frame is told the
|
|
11
|
+
* host's value again.
|
|
12
|
+
* - Every other variable is the package's own, stored under the package's id
|
|
13
|
+
* (`<packageId>_<name>`), as a variable its worker declares is. A name that already starts
|
|
14
|
+
* with the package's id is used as it is.
|
|
15
|
+
*
|
|
16
|
+
* A screen can set and delete its package's secret variables (an API key from its settings), but
|
|
17
|
+
* never read one: it reads {@link SECRET_VAR_MASK} while the variable is set, and its value only
|
|
18
|
+
* while it's empty.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* What a screen reads for one of its package's secret variables while it's set, in place of the
|
|
22
|
+
* value. Writing it back changes nothing.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SECRET_VAR_MASK = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
|
|
2
25
|
/** What the pvar service needs from the screen's host. */
|
|
3
26
|
export interface IFramePvarHost {
|
|
4
27
|
/** The screen's package. */
|
|
@@ -12,17 +35,21 @@ export interface IFramePvarHost {
|
|
|
12
35
|
}
|
|
13
36
|
/** One screen's bound variables. */
|
|
14
37
|
export interface IFramePvarService {
|
|
38
|
+
/** Follow a variable the screen declares; resolves to its value as the screen may see it. */
|
|
15
39
|
bind(input: {
|
|
16
40
|
bindingId: string;
|
|
17
41
|
request: IPersistentVarBackendRequest;
|
|
18
42
|
}): Promise<unknown>;
|
|
43
|
+
/** Write a bound variable, as its binding allows. */
|
|
19
44
|
write(input: {
|
|
20
45
|
bindingId: string;
|
|
21
46
|
value: unknown;
|
|
22
47
|
}): Promise<void>;
|
|
48
|
+
/** Delete a bound variable, as its binding allows. */
|
|
23
49
|
delete(input: {
|
|
24
50
|
bindingId: string;
|
|
25
51
|
}): Promise<void>;
|
|
52
|
+
/** Stop following every bound variable, as the screen closes. */
|
|
26
53
|
dispose(): void;
|
|
27
54
|
}
|
|
28
55
|
/**
|