@7365admin1/layer-common 4.97.1-staging.625 → 4.97.1-staging.627

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.
@@ -49,6 +49,7 @@ const notice = computed(() => cctvNotice(failure.value));
49
49
 
50
50
  let pc: RTCPeerConnection | null = null;
51
51
  let timer: ReturnType<typeof setTimeout> | null = null;
52
+ const LIVE_START_MS = 10000;
52
53
  let run = 0; // bumps on every start/stop so a late answer from an old attempt is ignored
53
54
 
54
55
  function stop() {
@@ -87,16 +88,19 @@ async function tryWebrtc(token: number) {
87
88
  conn.addTransceiver("video", { direction: "recvonly" });
88
89
  conn.addTransceiver("audio", { direction: "recvonly" });
89
90
  const connected = new Promise<void>((resolve, reject) => {
91
+ // A track is announced as soon as the answer is read, before any picture can arrive (the engine
92
+ // may be unreachable for video). "Live" waits for the first decoded frame; otherwise stills.
90
93
  conn.ontrack = (ev) => {
91
94
  if (token !== run || !video.value) return;
92
95
  video.value.srcObject = ev.streams[0] ?? new MediaStream([ev.track]);
93
- resolve();
96
+ video.value.addEventListener("loadeddata", () => resolve(), { once: true });
94
97
  };
95
98
  conn.onconnectionstatechange = () => {
96
99
  if (token !== run) return;
97
- if (conn.connectionState === "failed") reject(new Error("webrtc-failed"));
98
- if (conn.connectionState === "disconnected" || conn.connectionState === "closed") {
100
+ const state = conn.connectionState;
101
+ if (state === "failed" || state === "disconnected" || state === "closed") {
99
102
  if (mode.value === "live") fallbackToStill(token);
103
+ else reject(new Error("webrtc-failed"));
100
104
  }
101
105
  };
102
106
  setTimeout(() => reject(new Error("webrtc-timeout")), 10000);
@@ -107,7 +111,7 @@ async function tryWebrtc(token: number) {
107
111
  if (token !== run) return;
108
112
  await conn.setRemoteDescription({ type: "answer", sdp: answer.sdp });
109
113
  await connected;
110
- if (token === run) mode.value = "live";
114
+ if (token === run && mode.value === "connecting") mode.value = "live";
111
115
  }
112
116
 
113
117
  async function pollStill(token: number) {
@@ -144,7 +148,11 @@ async function start() {
144
148
  mode.value = "connecting";
145
149
  failure.value = null;
146
150
  try {
147
- await tryWebrtc(token);
151
+ // One limit for the whole attempt, the answer request included: a recorder that will not open
152
+ // another stream can keep that request waiting for half a minute.
153
+ const attempt = tryWebrtc(token);
154
+ attempt.catch(() => undefined); // a late failure after the limit is already handled below
155
+ await Promise.race([attempt, new Promise<never>((_, reject) => setTimeout(() => reject(new Error("webrtc-timeout")), LIVE_START_MS))]);
148
156
  } catch (e: any) {
149
157
  if (token !== run) return;
150
158
  // The engine being offline is the same for the still picture, so say it instead of pretending to fall back.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.97.1-staging.625",
5
+ "version": "4.97.1-staging.627",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",