@lavitre/apps 1.65.0 → 1.65.1
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.
|
@@ -32,10 +32,24 @@ const tuneSenders = async (pc) => {
|
|
|
32
32
|
export function offerStreamToHost(port, stream, onClosed) {
|
|
33
33
|
const pc = new RTCPeerConnection();
|
|
34
34
|
let closed = false;
|
|
35
|
-
|
|
35
|
+
// A source track that ends (camera unplugged, track stopped) closes the
|
|
36
|
+
// share: the host only sees the remote track go silent, never `ended`, and
|
|
37
|
+
// would keep the share and its slot on a frozen picture.
|
|
38
|
+
let watched = [];
|
|
39
|
+
const onSourceEnded = () => close(true, 'a shared track ended');
|
|
40
|
+
const watch = (tracks) => {
|
|
41
|
+
for (const t of watched)
|
|
42
|
+
t.removeEventListener('ended', onSourceEnded);
|
|
43
|
+
watched = tracks;
|
|
44
|
+
for (const t of watched)
|
|
45
|
+
t.addEventListener('ended', onSourceEnded);
|
|
46
|
+
};
|
|
47
|
+
const close = (notifyHost, reason) => {
|
|
36
48
|
if (closed)
|
|
37
49
|
return;
|
|
38
50
|
closed = true;
|
|
51
|
+
console.info('[lavitre/apps] shareStream peer closed:', reason);
|
|
52
|
+
watch([]);
|
|
39
53
|
if (notifyHost) {
|
|
40
54
|
try {
|
|
41
55
|
port.postMessage({ type: 'close' });
|
|
@@ -51,6 +65,7 @@ export function offerStreamToHost(port, stream, onClosed) {
|
|
|
51
65
|
for (const track of stream.getTracks()) {
|
|
52
66
|
pc.addTransceiver(track, { direction: 'sendonly', streams: [stream] });
|
|
53
67
|
}
|
|
68
|
+
watch(stream.getTracks());
|
|
54
69
|
pc.onicecandidate = (e) => {
|
|
55
70
|
if (e.candidate && !closed) {
|
|
56
71
|
port.postMessage({
|
|
@@ -61,7 +76,7 @@ export function offerStreamToHost(port, stream, onClosed) {
|
|
|
61
76
|
};
|
|
62
77
|
pc.onconnectionstatechange = () => {
|
|
63
78
|
if (pc.connectionState === 'failed')
|
|
64
|
-
close(true);
|
|
79
|
+
close(true, 'connection failed');
|
|
65
80
|
};
|
|
66
81
|
// Candidates must not overtake the answer they belong to: handle in order.
|
|
67
82
|
let chain = Promise.resolve();
|
|
@@ -79,11 +94,11 @@ export function offerStreamToHost(port, stream, onClosed) {
|
|
|
79
94
|
await pc.addIceCandidate(signal.candidate);
|
|
80
95
|
break;
|
|
81
96
|
case 'close':
|
|
82
|
-
close(false);
|
|
97
|
+
close(false, 'closed by the host');
|
|
83
98
|
break;
|
|
84
99
|
}
|
|
85
100
|
})
|
|
86
|
-
.catch(() => close(true));
|
|
101
|
+
.catch((err) => close(true, `signaling failed: ${err?.message ?? err}`));
|
|
87
102
|
};
|
|
88
103
|
void (async () => {
|
|
89
104
|
try {
|
|
@@ -96,8 +111,8 @@ export function offerStreamToHost(port, stream, onClosed) {
|
|
|
96
111
|
});
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
|
-
catch {
|
|
100
|
-
close(true);
|
|
114
|
+
catch (err) {
|
|
115
|
+
close(true, `offer failed: ${err?.message ?? err}`);
|
|
101
116
|
}
|
|
102
117
|
})();
|
|
103
118
|
return {
|
|
@@ -113,9 +128,13 @@ export function offerStreamToHost(port, stream, onClosed) {
|
|
|
113
128
|
}
|
|
114
129
|
await sender.replaceTrack(track);
|
|
115
130
|
}
|
|
131
|
+
watch(pc
|
|
132
|
+
.getSenders()
|
|
133
|
+
.map((s) => s.track)
|
|
134
|
+
.filter((t) => t != null));
|
|
116
135
|
await tuneSenders(pc);
|
|
117
136
|
},
|
|
118
|
-
close: () => close(true),
|
|
137
|
+
close: () => close(true, 'stopped by the app'),
|
|
119
138
|
};
|
|
120
139
|
}
|
|
121
140
|
//# sourceMappingURL=OutgoingStreamPeer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutgoingStreamPeer.js","sourceRoot":"","sources":["../../Frame/OutgoingStreamPeer.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,8EAA8E;AAC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.shareStream`'s fallback). Track readables only\n/// reach the Vitre page when the frame is on the same site: from another site\n/// the first `VideoFrame` chunk fails with `DataCloneError` and the share dies.\n/// Browsers without `MediaStreamTrackProcessor` cannot transfer them at all.\n/// Re-encoded once, on the same machine.\n///\n/// Signaling runs over the `MessagePort` whose twin travels in the\n/// `shareStream` message (`ShareStreamPeerTransport`). Mirror of\n/// `SharedStreamPeer.ts`, roles swapped:\n/// frame → host { type: 'offer', sdp } | { type: 'candidate', candidate } | { type: 'close' }\n/// host → frame { type: 'answer', sdp } | { type: 'candidate', candidate } | { type: 'close' }\n\nimport type { SharedStreamSignal } from './SharedStreamPeer.js'\n\nexport type OutgoingStreamPeer = {\n /** Swap the tracks sent without renegotiating (`replaceTrack`). Only kinds the\n * share already carries: a new kind would need a new negotiation. */\n replaceTracks: (stream: MediaStream) => Promise<void>\n /** Close from this side, telling the host. */\n close: () => void\n}\n\n/** Same ceiling as the host's reverse direction: the encoder and the decoder\n * run on the same machine, the link is local. */\nconst MAX_BITRATE = 8_000_000\n\nconst tuneSenders = async (pc: RTCPeerConnection) => {\n for (const sender of pc.getSenders()) {\n if (sender.track?.kind !== 'video') continue\n const params = sender.getParameters()\n const encoding = params.encodings?.[0]\n if (!encoding) continue\n encoding.maxBitrate = MAX_BITRATE\n encoding.maxFramerate = 30\n ;(\n params as RTCRtpSendParameters & { degradationPreference?: string }\n ).degradationPreference = 'maintain-resolution'\n await sender.setParameters(params).catch(() => {\n // A browser refusing a field keeps its defaults.\n })\n }\n}\n\nexport function offerStreamToHost(\n port: MessagePort,\n stream: MediaStream,\n onClosed: () => void,\n): OutgoingStreamPeer {\n const pc = new RTCPeerConnection()\n let closed = false\n // A source track that ends (camera unplugged, track stopped) closes the\n // share: the host only sees the remote track go silent, never `ended`, and\n // would keep the share and its slot on a frozen picture.\n let watched: MediaStreamTrack[] = []\n const onSourceEnded = () => close(true, 'a shared track ended')\n const watch = (tracks: MediaStreamTrack[]) => {\n for (const t of watched) t.removeEventListener('ended', onSourceEnded)\n watched = tracks\n for (const t of watched) t.addEventListener('ended', onSourceEnded)\n }\n const close = (notifyHost: boolean, reason: string) => {\n if (closed) return\n closed = true\n console.info('[lavitre/apps] shareStream peer closed:', reason)\n watch([])\n if (notifyHost) {\n try {\n port.postMessage({ type: 'close' } satisfies SharedStreamSignal)\n } catch {\n // Port already gone.\n }\n }\n port.close()\n pc.close()\n onClosed()\n }\n\n for (const track of stream.getTracks()) {\n pc.addTransceiver(track, { direction: 'sendonly', streams: [stream] })\n }\n watch(stream.getTracks())\n pc.onicecandidate = (e) => {\n if (e.candidate && !closed) {\n port.postMessage({\n type: 'candidate',\n candidate: e.candidate.toJSON(),\n } satisfies SharedStreamSignal)\n }\n }\n pc.onconnectionstatechange = () => {\n if (pc.connectionState === 'failed') close(true, 'connection failed')\n }\n\n // Candidates must not overtake the answer they belong to: handle in order.\n let chain = Promise.resolve()\n port.onmessage = (e: MessageEvent<SharedStreamSignal | null>) => {\n const signal = e.data\n chain = chain\n .then(async () => {\n if (closed || signal == null) return\n switch (signal.type) {\n case 'answer':\n await pc.setRemoteDescription({ type: 'answer', sdp: signal.sdp })\n break\n case 'candidate':\n await pc.addIceCandidate(signal.candidate)\n break\n case 'close':\n close(false, 'closed by the host')\n break\n }\n })\n .catch((err) => close(true, `signaling failed: ${err?.message ?? err}`))\n }\n\n void (async () => {\n try {\n await pc.setLocalDescription(await pc.createOffer())\n await tuneSenders(pc)\n if (!closed) {\n port.postMessage({\n type: 'offer',\n sdp: pc.localDescription?.sdp ?? '',\n } satisfies SharedStreamSignal)\n }\n } catch (err) {\n close(true, `offer failed: ${(err as Error)?.message ?? err}`)\n }\n })()\n\n return {\n replaceTracks: async (next: MediaStream) => {\n if (closed) throw new Error('replaceShareStream: the share is closed')\n for (const track of next.getTracks()) {\n const sender = pc\n .getTransceivers()\n .find((t) => t.receiver.track.kind === track.kind)?.sender\n if (!sender) {\n throw new Error(\n `replaceShareStream: this share carries no ${track.kind} track`,\n )\n }\n await sender.replaceTrack(track)\n }\n watch(\n pc\n .getSenders()\n .map((s) => s.track)\n .filter((t): t is MediaStreamTrack => t != null),\n )\n await tuneSenders(pc)\n },\n close: () => close(true, 'stopped by the app'),\n }\n}\n"]}
|
package/dist/Version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const apiVersion = "1.65.
|
|
1
|
+
export declare const apiVersion = "1.65.1";
|
package/dist/Version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const apiVersion = '1.65.
|
|
1
|
+
export const apiVersion = '1.65.1';
|
|
2
2
|
//# sourceMappingURL=Version.js.map
|
package/dist/Version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Version.js","sourceRoot":"","sources":["../Version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAA","sourcesContent":["export const apiVersion = '1.65.
|
|
1
|
+
{"version":3,"file":"Version.js","sourceRoot":"","sources":["../Version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAA","sourcesContent":["export const apiVersion = '1.65.1'"]}
|