@decentnetwork/beagle 0.1.47 → 0.1.48

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.
@@ -1,4 +1,4 @@
1
- window.__DK_UI_VERSION="0.1.47";
1
+ window.__DK_UI_VERSION="0.1.48";
2
2
  const ICON_PATHS = {
3
3
  // ---- tab bar (the four must feel like one set) ----
4
4
  users: '<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
@@ -3977,43 +3977,6 @@ function RtcFileInbox({ T, peers, ctl }) {
3977
3977
  }));
3978
3978
  }
3979
3979
  Object.assign(window, { useRtcFileController, RtcFileInbox });
3980
- const VIDEO_CODEC_KEEP = /^video\/(H264|VP8|rtx|red|ulpfec)$/i;
3981
- const SDP_BUDGET = 8192;
3982
- function trimVideoCodecs(pc) {
3983
- var _a, _b, _c, _d, _e, _f, _g;
3984
- const supported = (_c = (_b = (_a = window.RTCRtpSender) == null ? void 0 : _a.getCapabilities) == null ? void 0 : _b.call(_a, "video")) == null ? void 0 : _c.codecs;
3985
- if (!supported)
3986
- return;
3987
- const keep = supported.filter((c) => VIDEO_CODEC_KEEP.test(c.mimeType));
3988
- if (!keep.length || keep.length === supported.length)
3989
- return;
3990
- for (const t of pc.getTransceivers()) {
3991
- const kind = ((_e = (_d = t.receiver) == null ? void 0 : _d.track) == null ? void 0 : _e.kind) || ((_g = (_f = t.sender) == null ? void 0 : _f.track) == null ? void 0 : _g.kind);
3992
- if (kind !== "video" || !t.setCodecPreferences)
3993
- continue;
3994
- try {
3995
- t.setCodecPreferences(keep);
3996
- } catch (e) {
3997
- console.warn("[call] setCodecPreferences failed", e);
3998
- }
3999
- }
4000
- }
4001
- function createLeanPeerConnection(config) {
4002
- const pc = new RTCPeerConnection(config);
4003
- for (const method of ["createOffer", "createAnswer"]) {
4004
- const original = pc[method].bind(pc);
4005
- pc[method] = async (...args) => {
4006
- trimVideoCodecs(pc);
4007
- const desc = await original(...args);
4008
- const bytes = new TextEncoder().encode(desc.sdp || "").length;
4009
- console[bytes > SDP_BUDGET ? "warn" : "log"](
4010
- `[call] ${method} SDP ${bytes}B / ${SDP_BUDGET}B budget` + (bytes > SDP_BUDGET ? " \u2014 too large for the Carrier invite channel, falling back to the offline path" : "")
4011
- );
4012
- return desc;
4013
- };
4014
- }
4015
- return pc;
4016
- }
4017
3980
  function useCallController(selfId, onCallLog) {
4018
3981
  const [incoming, setIncoming] = React.useState(null);
4019
3982
  const [active, setActive] = React.useState(null);
@@ -4047,7 +4010,7 @@ function useCallController(selfId, onCallLog) {
4047
4010
  const engine = new CallEngine({
4048
4011
  selfId,
4049
4012
  signaling,
4050
- createPeerConnection: (c) => createLeanPeerConnection(c),
4013
+ createPeerConnection: (c) => new RTCPeerConnection(c),
4051
4014
  getLocalMedia: (k) => navigator.mediaDevices.getUserMedia({ audio: k.audio, video: k.video }),
4052
4015
  getDisplayMedia: (c) => navigator.mediaDevices.getDisplayMedia(c || { video: true, audio: false }),
4053
4016
  iceServers: DK_LIVE_ICE_SERVERS,
@@ -4088,6 +4051,7 @@ function useCallController(selfId, onCallLog) {
4088
4051
  setIncoming((i) => i && i.callId === id ? null : i);
4089
4052
  setLocalStream(null);
4090
4053
  setRemoteStream(null);
4054
+ setSharing(false);
4091
4055
  });
4092
4056
  engineRef.current = engine;
4093
4057
  console.log("[call] CallEngine ready with ICE:", DK_LIVE_ICE_SERVERS.map((s) => s.urls));
@@ -44,15 +44,21 @@ var PeerWebRTC = (() => {
44
44
  __export(dist_exports, {
45
45
  BeaglePushClient: () => BeaglePushClient,
46
46
  BroadcastChannelSignaling: () => BroadcastChannelSignaling,
47
+ CARRIER_MAX_INVITE_DATA_LEN: () => CARRIER_MAX_INVITE_DATA_LEN,
47
48
  CallEngine: () => CallEngine,
48
49
  CarrierSignaling: () => CarrierSignaling,
49
50
  Emitter: () => Emitter,
50
51
  SocketIoSignaling: () => SocketIoSignaling,
52
+ byteLength: () => byteLength,
51
53
  decodeSignal: () => decodeSignal,
52
54
  decodeSignalBytesGuard: () => decodeSignalBytesGuard,
53
55
  encodeSignal: () => encodeSignal,
54
56
  encodeSignalBytes: () => encodeSignalBytes,
55
- looksLikeSignal: () => looksLikeSignal
57
+ fitSignalForInvite: () => fitSignalForInvite,
58
+ looksLikeSignal: () => looksLikeSignal,
59
+ mediaDirection: () => mediaDirection,
60
+ shrinkSdpForInvite: () => shrinkSdpForInvite,
61
+ videoIsSending: () => videoIsSending
56
62
  });
57
63
 
58
64
  // node_modules/@decentnetwork/peer-webrtc/dist/emitter.js
@@ -91,6 +97,82 @@ var PeerWebRTC = (() => {
91
97
  };
92
98
  _handlers = new WeakMap();
93
99
 
100
+ // node_modules/@decentnetwork/peer-webrtc/dist/sdp.js
101
+ var CARRIER_MAX_INVITE_DATA_LEN = 8192;
102
+ function mediaSection(sdp, kind) {
103
+ const norm = sdp.replace(/\r\n/g, "\n");
104
+ const start = norm.indexOf(`m=${kind} `);
105
+ if (start < 0)
106
+ return void 0;
107
+ const next = norm.indexOf("\nm=", start + 1);
108
+ return next < 0 ? norm.slice(start) : norm.slice(start, next);
109
+ }
110
+ function mediaDirection(sdp, kind) {
111
+ const block = mediaSection(sdp, kind);
112
+ if (block === void 0)
113
+ return void 0;
114
+ for (const dir of ["sendrecv", "sendonly", "recvonly", "inactive"]) {
115
+ if (block.includes(`a=${dir}`))
116
+ return dir;
117
+ }
118
+ return "sendrecv";
119
+ }
120
+ function videoIsSending(sdp) {
121
+ const dir = mediaDirection(sdp, "video");
122
+ return dir === "sendrecv" || dir === "sendonly";
123
+ }
124
+ function byteLength(text) {
125
+ return new TextEncoder().encode(text).length;
126
+ }
127
+ var DROPPABLE_CODECS = [
128
+ /^(VP9|AV1|AV1X|H265|HEVC)$/i,
129
+ /^(red|ulpfec|flexfec-03)$/i
130
+ ];
131
+ function payloadTypesFor(lines, codec) {
132
+ const pts = /* @__PURE__ */ new Set();
133
+ for (const line of lines) {
134
+ const m = /^a=rtpmap:(\d+)\s+([A-Za-z0-9-]+)\//.exec(line);
135
+ if (m && codec.test(m[2]))
136
+ pts.add(m[1]);
137
+ }
138
+ for (const line of lines) {
139
+ const m = /^a=fmtp:(\d+)\s+apt=(\d+)/.exec(line);
140
+ if (m && pts.has(m[2]))
141
+ pts.add(m[1]);
142
+ }
143
+ return pts;
144
+ }
145
+ function stripPayloadTypes(lines, pts) {
146
+ if (pts.size === 0)
147
+ return [...lines];
148
+ const out = [];
149
+ for (const line of lines) {
150
+ if (line.startsWith("m=video ")) {
151
+ const parts = line.split(" ");
152
+ out.push([...parts.slice(0, 3), ...parts.slice(3).filter((pt) => !pts.has(pt))].join(" "));
153
+ continue;
154
+ }
155
+ const m = /^a=(?:rtpmap|rtcp-fb|fmtp):(\d+)\b/.exec(line);
156
+ if (m && pts.has(m[1]))
157
+ continue;
158
+ out.push(line);
159
+ }
160
+ return out;
161
+ }
162
+ function shrinkSdpForInvite(sdp, budget = CARRIER_MAX_INVITE_DATA_LEN) {
163
+ if (byteLength(sdp) <= budget)
164
+ return sdp;
165
+ const crlf = sdp.includes("\r\n");
166
+ let lines = sdp.replace(/\r\n/g, "\n").split("\n");
167
+ for (const codec of DROPPABLE_CODECS) {
168
+ lines = stripPayloadTypes(lines, payloadTypesFor(lines, codec));
169
+ const candidate = lines.join(crlf ? "\r\n" : "\n");
170
+ if (byteLength(candidate) <= budget)
171
+ return candidate;
172
+ }
173
+ return lines.join(crlf ? "\r\n" : "\n");
174
+ }
175
+
94
176
  // node_modules/@decentnetwork/peer-webrtc/dist/signal.js
95
177
  var SDP_TYPES = /* @__PURE__ */ new Set([
96
178
  "offer",
@@ -128,6 +210,20 @@ var PeerWebRTC = (() => {
128
210
  function encodeSignalBytes(signal) {
129
211
  return new TextEncoder().encode(encodeSignal(signal));
130
212
  }
213
+ function fitSignalForInvite(signal, budget = CARRIER_MAX_INVITE_DATA_LEN) {
214
+ let bytes = encodeSignalBytes(signal).length;
215
+ if (bytes <= budget)
216
+ return { signal, bytes, shrunk: false };
217
+ let out = signal;
218
+ if (signal.type === "offer" && signal.sdp) {
219
+ out = { ...signal, sdp: shrinkSdpForInvite(signal.sdp, budget - (bytes - byteLength(signal.sdp))) };
220
+ bytes = encodeSignalBytes(out).length;
221
+ }
222
+ if (bytes > budget) {
223
+ throw new Error(`RtcSignal "${signal.type}" is ${bytes}B, over the ${budget}B invite cap \u2014 the peer would never receive it`);
224
+ }
225
+ return { signal: out, bytes, shrunk: true };
226
+ }
131
227
  function decodeSignal(input) {
132
228
  const text = (typeof input === "string" ? input : new TextDecoder().decode(input)).replace(/\0+$/u, "").trim();
133
229
  const obj = JSON.parse(text);
@@ -167,10 +263,11 @@ var PeerWebRTC = (() => {
167
263
  var DEFAULT_ICE_SERVERS = [
168
264
  { urls: "stun:stun.l.google.com:19302" }
169
265
  ];
266
+ var LEAN_VIDEO_CODECS = /^video\/(H264|VP8|rtx|red|ulpfec)$/i;
170
267
  var ICE_RESTART_MAX = 3;
171
268
  var ICE_DISCONNECT_GRACE_MS = 4e3;
172
269
  var ICE_FAILED_GRACE_MS = 12e4;
173
- var _opts, _iceServers, _sessions, _restartOffersEnabled, _setOutgoingVideoTrack, setOutgoingVideoTrack_fn, _renegotiate, renegotiate_fn, _restartIce, restartIce_fn, _handleSignal, handleSignal_fn, _onOffer, onOffer_fn, _answerRenegotiation, answerRenegotiation_fn, _onAnswer, onAnswer_fn, _onCandidate, onCandidate_fn, _onBye, onBye_fn, _onAuxiliary, onAuxiliary_fn, _createSession, createSession_fn, _wirePeerConnection, wirePeerConnection_fn, _ensureRemoteStream, ensureRemoteStream_fn, _attachLocalMedia, attachLocalMedia_fn, _flushLocalCandidates, flushLocalCandidates_fn, _drainRemoteCandidates, drainRemoteCandidates_fn, _send, send_fn, _sendByeSafe, sendByeSafe_fn, _cleanup, cleanup_fn, _setState, setState_fn, _normId, normId_fn, _toInfo, _newCallId, newCallId_fn, _log, log_fn;
270
+ var _opts, _iceServers, _sessions, _restartOffersEnabled, _setOutgoingVideoTrack, setOutgoingVideoTrack_fn, _renegotiate, renegotiate_fn, _createOffer, createOffer_fn, _createAnswer, createAnswer_fn, _preferLeanVideoCodecs, preferLeanVideoCodecs_fn, _restartIce, restartIce_fn, _handleSignal, handleSignal_fn, _onOffer, onOffer_fn, _answerRenegotiation, answerRenegotiation_fn, _onAnswer, onAnswer_fn, _onCandidate, onCandidate_fn, _onBye, onBye_fn, _onAuxiliary, onAuxiliary_fn, _createSession, createSession_fn, _wirePeerConnection, wirePeerConnection_fn, _ensureRemoteStream, ensureRemoteStream_fn, _attachLocalMedia, attachLocalMedia_fn, _flushLocalCandidates, flushLocalCandidates_fn, _drainRemoteCandidates, drainRemoteCandidates_fn, _send, send_fn, _sendByeSafe, sendByeSafe_fn, _cleanup, cleanup_fn, _setState, setState_fn, _normId, normId_fn, _toInfo, _newCallId, newCallId_fn, _log, log_fn;
174
271
  var CallEngine = class extends Emitter {
175
272
  constructor(opts) {
176
273
  var _a, _b;
@@ -182,6 +279,20 @@ var PeerWebRTC = (() => {
182
279
  /** Create + send a fresh offer to renegotiate media (e.g. after adding a
183
280
  * screen-share track). The peer applies it via #onOffer's renegotiation path. */
184
281
  __privateAdd(this, _renegotiate);
282
+ /** createOffer with the lean codec set applied (see #preferLeanVideoCodecs). */
283
+ __privateAdd(this, _createOffer);
284
+ /** createAnswer with the lean codec set applied. */
285
+ __privateAdd(this, _createAnswer);
286
+ /**
287
+ * Restrict video to the codecs the peers actually negotiate, so the SDP fits
288
+ * the 8192-byte Carrier invite channel. Chrome otherwise advertises VP9 and
289
+ * AV1 with their profile/rtx/fmtp lines and the offer lands at 8.4-9.8 KB —
290
+ * over the cap, rejected by the transport, invisible to the peer.
291
+ *
292
+ * setCodecPreferences (not SDP munging) keeps the browser the one producing a
293
+ * valid, self-consistent description. No-ops wherever the API is missing.
294
+ */
295
+ __privateAdd(this, _preferLeanVideoCodecs);
185
296
  /** Recover a dead transport with an ICE restart (RFC 8445 §12): a re-offer
186
297
  * carrying fresh ufrag/pwd, sent over the SAME renegotiation path that
187
298
  * screen-share re-offers use — any peer that answers those (web, iOS,
@@ -279,7 +390,7 @@ var PeerWebRTC = (() => {
279
390
  } catch {
280
391
  }
281
392
  }
282
- const offer = await session.pc.createOffer();
393
+ const offer = await __privateMethod(this, _createOffer, createOffer_fn).call(this, session);
283
394
  await session.pc.setLocalDescription(offer);
284
395
  const options = [];
285
396
  if (audio)
@@ -313,7 +424,7 @@ var PeerWebRTC = (() => {
313
424
  session.hasReceivedSdp = true;
314
425
  session.pendingOffer = void 0;
315
426
  await __privateMethod(this, _drainRemoteCandidates, drainRemoteCandidates_fn).call(this, session);
316
- const answer = await session.pc.createAnswer();
427
+ const answer = await __privateMethod(this, _createAnswer, createAnswer_fn).call(this, session);
317
428
  await session.pc.setLocalDescription(answer);
318
429
  await __privateMethod(this, _send, send_fn).call(this, session.peerId, { type: "answer", sdp: answer.sdp, callId });
319
430
  try {
@@ -376,7 +487,14 @@ var PeerWebRTC = (() => {
376
487
  track.addEventListener("ended", () => {
377
488
  void this.stopScreenShare(callId);
378
489
  });
379
- await __privateMethod(this, _renegotiate, renegotiate_fn).call(this, session);
490
+ try {
491
+ await __privateMethod(this, _renegotiate, renegotiate_fn).call(this, session);
492
+ } catch (err) {
493
+ __privateMethod(this, _log, log_fn).call(this, `shareScreen renegotiation failed: ${err.message}`);
494
+ await this.stopScreenShare(callId).catch(() => {
495
+ });
496
+ throw err;
497
+ }
380
498
  __privateMethod(this, _log, log_fn).call(this, `shareScreen started for ${callId}`);
381
499
  }
382
500
  /** Stop screen sharing; re-acquire the camera if there was one. */
@@ -394,7 +512,9 @@ var PeerWebRTC = (() => {
394
512
  }
395
513
  session.hadCamera = false;
396
514
  await __privateMethod(this, _setOutgoingVideoTrack, setOutgoingVideoTrack_fn).call(this, session, (_a = cam == null ? void 0 : cam.getVideoTracks()[0]) != null ? _a : null, cam);
397
- await __privateMethod(this, _renegotiate, renegotiate_fn).call(this, session);
515
+ await __privateMethod(this, _renegotiate, renegotiate_fn).call(this, session).catch((err) => {
516
+ __privateMethod(this, _log, log_fn).call(this, `stopScreenShare renegotiation failed: ${err.message}`);
517
+ });
398
518
  __privateMethod(this, _log, log_fn).call(this, `shareScreen stopped for ${callId}`);
399
519
  }
400
520
  /** True when the call is currently sharing the screen. */
@@ -426,42 +546,94 @@ var PeerWebRTC = (() => {
426
546
  _restartOffersEnabled = new WeakMap();
427
547
  _setOutgoingVideoTrack = new WeakSet();
428
548
  setOutgoingVideoTrack_fn = async function(session, track, stream) {
429
- var _a;
430
- const transceivers = session.pc.getTransceivers();
431
- const tr = (_a = transceivers.find((t) => {
549
+ var _a, _b, _c, _d;
550
+ const transceivers = (_c = (_b = (_a = session.pc).getTransceivers) == null ? void 0 : _b.call(_a)) != null ? _c : [];
551
+ const tr = (_d = transceivers.find((t) => {
432
552
  var _a2;
433
553
  return ((_a2 = t.sender.track) == null ? void 0 : _a2.kind) === "video";
434
- })) != null ? _a : transceivers.find((t) => {
554
+ })) != null ? _d : transceivers.find((t) => {
435
555
  var _a2;
436
556
  return ((_a2 = t.receiver.track) == null ? void 0 : _a2.kind) === "video";
437
557
  });
438
- if (tr) {
439
- await tr.sender.replaceTrack(track);
440
- if (track) {
441
- if (tr.direction === "recvonly")
442
- tr.direction = "sendrecv";
443
- else if (tr.direction === "inactive")
444
- tr.direction = "sendonly";
558
+ if (track) {
559
+ let sending = false;
560
+ if (tr) {
561
+ try {
562
+ await tr.sender.replaceTrack(track);
563
+ if (tr.direction === "recvonly" || tr.direction === "inactive")
564
+ tr.direction = "sendrecv";
565
+ sending = tr.direction === "sendrecv" || tr.direction === "sendonly";
566
+ } catch (err) {
567
+ __privateMethod(this, _log, log_fn).call(this, `replaceTrack/direction failed: ${err.message}`);
568
+ }
569
+ }
570
+ if (!sending) {
571
+ __privateMethod(this, _log, log_fn).call(this, tr ? `video transceiver stuck at ${tr.direction}; addTrack fallback` : "no video m-line; addTrack");
572
+ if (stream)
573
+ session.pc.addTrack(track, stream);
574
+ else
575
+ session.pc.addTrack(track);
576
+ }
577
+ } else if (tr) {
578
+ try {
579
+ await tr.sender.replaceTrack(null);
580
+ if (tr.direction === "sendrecv")
581
+ tr.direction = "recvonly";
582
+ else if (tr.direction === "sendonly")
583
+ tr.direction = "inactive";
584
+ } catch (err) {
585
+ __privateMethod(this, _log, log_fn).call(this, `clear video track failed: ${err.message}`);
445
586
  }
446
- } else if (track && stream) {
447
- session.pc.addTrack(track, stream);
448
587
  }
449
588
  session.localStream = stream;
450
589
  this.emit("localStream", session.callId, stream != null ? stream : new MediaStream());
451
590
  };
452
591
  _renegotiate = new WeakSet();
453
592
  renegotiate_fn = async function(session) {
454
- try {
455
- const offer = await session.pc.createOffer();
456
- await session.pc.setLocalDescription(offer);
457
- const options = [];
458
- if (session.audio)
459
- options.push("audio");
460
- if (session.video || session.screenStream)
461
- options.push("video");
462
- await __privateMethod(this, _send, send_fn).call(this, session.peerId, { type: "offer", sdp: offer.sdp, options, callId: session.callId });
463
- } catch (err) {
464
- __privateMethod(this, _log, log_fn).call(this, `renegotiate failed: ${err.message}`);
593
+ var _a, _b;
594
+ const offer = await __privateMethod(this, _createOffer, createOffer_fn).call(this, session);
595
+ await session.pc.setLocalDescription(offer);
596
+ const options = [];
597
+ if (session.audio)
598
+ options.push("audio");
599
+ if (session.video || session.screenStream)
600
+ options.push("video");
601
+ const sdp = (_a = offer.sdp) != null ? _a : "";
602
+ __privateMethod(this, _log, log_fn).call(this, `renegotiate callId=${session.callId} video=${(_b = mediaDirection(sdp, "video")) != null ? _b : "none"} sdp=${byteLength(sdp)}B`);
603
+ if (session.screenStream && !videoIsSending(sdp)) {
604
+ __privateMethod(this, _log, log_fn).call(this, "renegotiate: WARNING share offer has no sending video m-line \u2014 peer will see black");
605
+ }
606
+ await __privateMethod(this, _send, send_fn).call(this, session.peerId, { type: "offer", sdp: offer.sdp, options, callId: session.callId });
607
+ };
608
+ _createOffer = new WeakSet();
609
+ createOffer_fn = async function(session, opts) {
610
+ __privateMethod(this, _preferLeanVideoCodecs, preferLeanVideoCodecs_fn).call(this, session.pc);
611
+ return session.pc.createOffer(opts);
612
+ };
613
+ _createAnswer = new WeakSet();
614
+ createAnswer_fn = async function(session) {
615
+ __privateMethod(this, _preferLeanVideoCodecs, preferLeanVideoCodecs_fn).call(this, session.pc);
616
+ return session.pc.createAnswer();
617
+ };
618
+ _preferLeanVideoCodecs = new WeakSet();
619
+ preferLeanVideoCodecs_fn = function(pc) {
620
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
621
+ if (__privateGet(this, _opts).leanVideoCodecs === false)
622
+ return;
623
+ const caps = (_b = (_a = globalThis.RTCRtpSender) == null ? void 0 : _a.getCapabilities) == null ? void 0 : _b.call(_a, "video");
624
+ if (!((_c = caps == null ? void 0 : caps.codecs) == null ? void 0 : _c.length))
625
+ return;
626
+ const keep = caps.codecs.filter((c) => LEAN_VIDEO_CODECS.test(c.mimeType));
627
+ if (!keep.length || keep.length === caps.codecs.length)
628
+ return;
629
+ for (const t of (_e = (_d = pc.getTransceivers) == null ? void 0 : _d.call(pc)) != null ? _e : []) {
630
+ const kind = (_j = (_g = (_f = t.receiver) == null ? void 0 : _f.track) == null ? void 0 : _g.kind) != null ? _j : (_i = (_h = t.sender) == null ? void 0 : _h.track) == null ? void 0 : _i.kind;
631
+ if (kind !== "video" || typeof t.setCodecPreferences !== "function")
632
+ continue;
633
+ try {
634
+ t.setCodecPreferences(keep);
635
+ } catch {
636
+ }
465
637
  }
466
638
  };
467
639
  _restartIce = new WeakSet();
@@ -471,7 +643,7 @@ var PeerWebRTC = (() => {
471
643
  session.restartAttempts += 1;
472
644
  __privateMethod(this, _log, log_fn).call(this, `ICE restart ${session.restartAttempts}/${ICE_RESTART_MAX} for call ${session.callId}`);
473
645
  try {
474
- const offer = await session.pc.createOffer({ iceRestart: true });
646
+ const offer = await __privateMethod(this, _createOffer, createOffer_fn).call(this, session, { iceRestart: true });
475
647
  await session.pc.setLocalDescription(offer);
476
648
  const options = [];
477
649
  if (session.audio)
@@ -532,7 +704,7 @@ var PeerWebRTC = (() => {
532
704
  answerRenegotiation_fn = async function(session, sdp) {
533
705
  try {
534
706
  await session.pc.setRemoteDescription({ type: "offer", sdp });
535
- const answer = await session.pc.createAnswer();
707
+ const answer = await __privateMethod(this, _createAnswer, createAnswer_fn).call(this, session);
536
708
  await session.pc.setLocalDescription(answer);
537
709
  await __privateMethod(this, _send, send_fn).call(this, session.peerId, { type: "answer", sdp: answer.sdp, callId: session.callId });
538
710
  } catch (err) {
@@ -764,8 +936,13 @@ var PeerWebRTC = (() => {
764
936
  };
765
937
  _send = new WeakSet();
766
938
  send_fn = async function(peerId, signal) {
939
+ var _a;
767
940
  try {
768
- await __privateGet(this, _opts).signaling.send(peerId, signal);
941
+ const budget = (_a = __privateGet(this, _opts).maxSignalBytes) != null ? _a : CARRIER_MAX_INVITE_DATA_LEN;
942
+ const fitted = fitSignalForInvite(signal, budget);
943
+ if (fitted.shrunk)
944
+ __privateMethod(this, _log, log_fn).call(this, `signal ${signal.type} shrunk to ${fitted.bytes}B (cap ${budget}B)`);
945
+ await __privateGet(this, _opts).signaling.send(peerId, fitted.signal);
769
946
  } catch (err) {
770
947
  __privateMethod(this, _log, log_fn).call(this, `signal send failed (${signal.type} \u2192 ${peerId}): ${err.message}`);
771
948
  throw err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/beagle",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "description": "Beagle — P2P chat, file transfer and calls for regular users, on the Decent Network. No admin privilege required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "@decentnetwork/chat-components": "^0.1.3",
29
29
  "@decentnetwork/lan": "^0.1.276",
30
30
  "@decentnetwork/peer": "^0.1.139",
31
- "@decentnetwork/peer-webrtc": "^0.2.14",
31
+ "@decentnetwork/peer-webrtc": "^0.2.15",
32
32
  "js-yaml": "^4.1.0",
33
33
  "yargs": "^17.7.2"
34
34
  },