@reactor-team/js-sdk 2.9.1 → 2.9.3

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/index.mjs CHANGED
@@ -83,7 +83,7 @@ import { z } from "zod";
83
83
  // package.json
84
84
  var package_default = {
85
85
  name: "@reactor-team/js-sdk",
86
- version: "2.9.1",
86
+ version: "2.9.3",
87
87
  description: "Reactor JavaScript frontend SDK",
88
88
  main: "dist/index.js",
89
89
  module: "dist/index.mjs",
@@ -130,6 +130,7 @@ var package_default = {
130
130
  "@types/inquirer": "^9.0.9",
131
131
  "@types/node": "^20",
132
132
  "@types/react": "^18.2.8",
133
+ "@types/sdp-transform": "^2.15.0",
133
134
  "@types/ws": "^8.18.1",
134
135
  prettier: "^3.6.2",
135
136
  tsup: "^8.5.0",
@@ -140,6 +141,7 @@ var package_default = {
140
141
  "@bufbuild/protobuf": "^2.0.0",
141
142
  chalk: "^5.3.0",
142
143
  inquirer: "^9.3.0",
144
+ "sdp-transform": "^3.0.0",
143
145
  "simple-git": "^3.24.0",
144
146
  ws: "^8.18.3",
145
147
  zod: "^4.0.5"
@@ -691,6 +693,377 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
691
693
  }
692
694
  };
693
695
 
696
+ // src/utils/sdp.ts
697
+ import { parse, parsePayloads } from "sdp-transform";
698
+ function sdpLineSeparator(sdp) {
699
+ return sdp.includes("\r\n") ? "\r\n" : "\n";
700
+ }
701
+ function splitSdpLines(sdp) {
702
+ return sdp.split(/\r?\n/);
703
+ }
704
+ function joinSdpLines(lines, sep) {
705
+ return lines.join(sep);
706
+ }
707
+ var DYNAMIC_PT_MIN = 96;
708
+ var DYNAMIC_PT_MAX = 127;
709
+ function isSanitizedVideoCodecRtpmapEncoding(name) {
710
+ const u = name.toUpperCase();
711
+ if (/^(H265|HEVC|HEV1|HVC1)/.test(u)) return true;
712
+ if (/^VP8(\/|$)/.test(u)) return true;
713
+ if (/^VP9(\/|$)/.test(u)) return true;
714
+ if (/^H264(\/|$)/.test(u)) return true;
715
+ return false;
716
+ }
717
+ function isOpusRtpmapEncoding(name) {
718
+ return /^OPUS(\/|$)/i.test(name);
719
+ }
720
+ function mediaMLinePayloadTypes(media) {
721
+ var _a;
722
+ return parsePayloads(String((_a = media.payloads) != null ? _a : ""));
723
+ }
724
+ function collectRtpmap(media) {
725
+ var _a;
726
+ const rtpmap = /* @__PURE__ */ new Map();
727
+ for (const r of (_a = media.rtp) != null ? _a : []) {
728
+ rtpmap.set(Number(r.payload), String(r.codec));
729
+ }
730
+ return rtpmap;
731
+ }
732
+ function collectSanitizedCodecPayloadSet(media) {
733
+ const rtpmap = collectRtpmap(media);
734
+ const tracked = /* @__PURE__ */ new Set();
735
+ if (media.type === "video") {
736
+ for (const [pt, enc] of rtpmap) {
737
+ if (isSanitizedVideoCodecRtpmapEncoding(enc)) tracked.add(pt);
738
+ }
739
+ } else if (media.type === "audio") {
740
+ for (const [pt, enc] of rtpmap) {
741
+ if (isOpusRtpmapEncoding(enc)) tracked.add(pt);
742
+ }
743
+ }
744
+ return tracked.size > 0 ? tracked : null;
745
+ }
746
+ function mediaSectionNeedsSanitizedPtRelocate(media) {
747
+ const pts = collectSanitizedCodecPayloadSet(media);
748
+ if (!pts) {
749
+ return false;
750
+ }
751
+ return [...pts].some((p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX);
752
+ }
753
+ function codecRelocationPriority(enc) {
754
+ const u = (enc != null ? enc : "").toUpperCase();
755
+ if (/^(H265|HEVC|HEV1|HVC1)/.test(u)) return 0;
756
+ if (/^H264(\/|$)/.test(u)) return 1;
757
+ if (/^VP9(\/|$)/.test(u)) return 2;
758
+ if (/^VP8(\/|$)/.test(u)) return 3;
759
+ if (/^OPUS(\/|$)/.test(u)) return 4;
760
+ return 5;
761
+ }
762
+ function sortedRelocate(relocate, rtpmap) {
763
+ return [...relocate].sort(
764
+ (a, b) => codecRelocationPriority(rtpmap.get(a)) - codecRelocationPriority(rtpmap.get(b))
765
+ );
766
+ }
767
+ function remapFmtpConfigForPayloadMap(config, remap) {
768
+ let s = config;
769
+ const pairs = [...remap.entries()].sort((a, b) => b[0] - a[0]);
770
+ for (const [oldP, newP] of pairs) {
771
+ if (oldP === newP) continue;
772
+ s = s.replace(new RegExp(`apt=${oldP}([^0-9]|$)`, "g"), `apt=${newP}$1`);
773
+ }
774
+ return s;
775
+ }
776
+ function computeCodecRemapForMedia(media, forbidden) {
777
+ const remap = /* @__PURE__ */ new Map();
778
+ if (media.type !== "video" && media.type !== "audio") {
779
+ return remap;
780
+ }
781
+ const tracked = collectSanitizedCodecPayloadSet(media);
782
+ if (!tracked) {
783
+ return remap;
784
+ }
785
+ const relocate = [...tracked].filter(
786
+ (p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX
787
+ );
788
+ if (relocate.length === 0) {
789
+ return remap;
790
+ }
791
+ const rtpmap = collectRtpmap(media);
792
+ const ordered = sortedRelocate(relocate, rtpmap);
793
+ const usedPts = new Set(forbidden);
794
+ for (const p of mediaMLinePayloadTypes(media)) {
795
+ if (p >= DYNAMIC_PT_MIN && p <= DYNAMIC_PT_MAX) usedPts.add(p);
796
+ }
797
+ let candidate = DYNAMIC_PT_MIN;
798
+ for (const oldPt of ordered) {
799
+ while (candidate <= DYNAMIC_PT_MAX && usedPts.has(candidate)) candidate++;
800
+ if (candidate > DYNAMIC_PT_MAX) break;
801
+ remap.set(oldPt, candidate);
802
+ usedPts.add(candidate);
803
+ candidate++;
804
+ }
805
+ return remap;
806
+ }
807
+ function rewriteRtpSavpfMPayloads(mLine, mapPt) {
808
+ if (!/\bRTP\/SAVPF\b/.test(mLine)) {
809
+ return mLine;
810
+ }
811
+ const tokens = mLine.split(/\s+/);
812
+ if (tokens.length < 4) {
813
+ return mLine;
814
+ }
815
+ const head = tokens.slice(0, 3).join(" ");
816
+ const tail = tokens.slice(3).map((t) => /^\d+$/.test(t) ? String(mapPt(Number(t))) : t);
817
+ return `${head} ${tail.join(" ")}`;
818
+ }
819
+ function payloadTypesFromSavpfMLine(mLine) {
820
+ const m = /\bRTP\/SAVPF\s+(.+)$/i.exec(mLine);
821
+ return m ? parsePayloads(m[1].trim()) : [];
822
+ }
823
+ function payloadTypeFromPtBoundAttributeLine(line) {
824
+ if (line.startsWith("a=rtpmap:")) {
825
+ const x = /^a=rtpmap:(\d+)/i.exec(line);
826
+ return x ? Number(x[1]) : null;
827
+ }
828
+ if (line.startsWith("a=fmtp:")) {
829
+ const x = /^a=fmtp:(\d+)/i.exec(line);
830
+ return x ? Number(x[1]) : null;
831
+ }
832
+ if (line.startsWith("a=rtcp-fb:")) {
833
+ const x = /^a=rtcp-fb:(\*|(\d+))/i.exec(line);
834
+ if (!x || x[1] === "*") return null;
835
+ return Number(x[2]);
836
+ }
837
+ if (line.startsWith("a=rtcp-fb-trr-int:")) {
838
+ const x = /^a=rtcp-fb-trr-int:(\*|(\d+))/i.exec(line);
839
+ if (!x || x[1] === "*") return null;
840
+ return Number(x[2]);
841
+ }
842
+ if (line.startsWith("a=imageattrs:")) {
843
+ const x = /^a=imageattrs:(\*|(\d+))/i.exec(line);
844
+ if (!x || x[1] === "*") return null;
845
+ return Number(x[2]);
846
+ }
847
+ return null;
848
+ }
849
+ function isPtBoundCodecAttributeLine(line) {
850
+ return payloadTypeFromPtBoundAttributeLine(line) !== null;
851
+ }
852
+ function reorderSingleRtpSavpfSection(sec) {
853
+ const mLine = sec[0];
854
+ if (!/\bRTP\/SAVPF\b/.test(mLine)) {
855
+ return sec;
856
+ }
857
+ const body = sec.slice(1);
858
+ let first = -1;
859
+ let last = -1;
860
+ for (let j = 0; j < body.length; j++) {
861
+ if (isPtBoundCodecAttributeLine(body[j])) {
862
+ if (first === -1) first = j;
863
+ last = j;
864
+ }
865
+ }
866
+ if (first === -1) {
867
+ return sec;
868
+ }
869
+ const prefix = body.slice(0, first);
870
+ const codecLines = body.slice(first, last + 1);
871
+ const suffix = body.slice(last + 1);
872
+ const mPts = payloadTypesFromSavpfMLine(mLine);
873
+ const buckets = /* @__PURE__ */ new Map();
874
+ for (const line of codecLines) {
875
+ const pt = payloadTypeFromPtBoundAttributeLine(line);
876
+ if (pt === null) continue;
877
+ const arr = buckets.get(pt);
878
+ if (arr) arr.push(line);
879
+ else buckets.set(pt, [line]);
880
+ }
881
+ const seenOrder = [];
882
+ for (const line of codecLines) {
883
+ const pt = payloadTypeFromPtBoundAttributeLine(line);
884
+ if (pt !== null && !seenOrder.includes(pt)) seenOrder.push(pt);
885
+ }
886
+ const outCodec = [];
887
+ for (const pt of mPts) {
888
+ const arr = buckets.get(pt);
889
+ if (!arr) continue;
890
+ outCodec.push(...arr);
891
+ buckets.delete(pt);
892
+ }
893
+ for (const pt of seenOrder) {
894
+ const arr = buckets.get(pt);
895
+ if (!arr) continue;
896
+ outCodec.push(...arr);
897
+ buckets.delete(pt);
898
+ }
899
+ for (const arr of buckets.values()) {
900
+ outCodec.push(...arr);
901
+ }
902
+ return [mLine, ...prefix, ...outCodec, ...suffix];
903
+ }
904
+ function reorderCodecAttributes(sdp) {
905
+ const sep = sdpLineSeparator(sdp);
906
+ const lines = splitSdpLines(sdp);
907
+ const out = [];
908
+ let i = 0;
909
+ while (i < lines.length) {
910
+ const line = lines[i];
911
+ if (!line.startsWith("m=")) {
912
+ out.push(line);
913
+ i++;
914
+ continue;
915
+ }
916
+ const mLine = line;
917
+ i++;
918
+ const rest = [];
919
+ while (i < lines.length && !lines[i].startsWith("m=")) {
920
+ rest.push(lines[i]);
921
+ i++;
922
+ }
923
+ out.push(...reorderSingleRtpSavpfSection([mLine, ...rest]));
924
+ }
925
+ return joinSdpLines(out, sep);
926
+ }
927
+ function applyRemapToMediaAttributeLine(line, remap) {
928
+ var _a, _b, _c, _d, _e, _f, _g, _h;
929
+ if (!line.startsWith("a=")) {
930
+ return line;
931
+ }
932
+ if (line.startsWith("a=rtpmap:")) {
933
+ const m = /^a=rtpmap:(\d+)/.exec(line);
934
+ if (!m) return line;
935
+ const pt = Number(m[1]);
936
+ const np = (_a = remap.get(pt)) != null ? _a : pt;
937
+ return np === pt ? line : line.replace(/^a=rtpmap:\d+/, `a=rtpmap:${np}`);
938
+ }
939
+ if (line.startsWith("a=fmtp:")) {
940
+ const m = /^a=fmtp:(\d+)\s(.*)$/.exec(line);
941
+ if (!m) return line;
942
+ const pt = Number(m[1]);
943
+ const np = (_b = remap.get(pt)) != null ? _b : pt;
944
+ const cfg = remapFmtpConfigForPayloadMap(m[2], remap);
945
+ return `a=fmtp:${np} ${cfg}`;
946
+ }
947
+ if (line.startsWith("a=rtcp-fb:")) {
948
+ const m = /^a=rtcp-fb:(\*|\d+)(\s.*)?$/.exec(line);
949
+ if (!m || m[1] === "*") return line;
950
+ const pt = Number(m[1]);
951
+ const np = (_c = remap.get(pt)) != null ? _c : pt;
952
+ return np === pt ? line : `a=rtcp-fb:${np}${(_d = m[2]) != null ? _d : ""}`;
953
+ }
954
+ if (line.startsWith("a=rtcp-fb-trr-int:")) {
955
+ const m = /^a=rtcp-fb-trr-int:(\*|\d+)(\s.*)?$/.exec(line);
956
+ if (!m || m[1] === "*") return line;
957
+ const pt = Number(m[1]);
958
+ const np = (_e = remap.get(pt)) != null ? _e : pt;
959
+ return np === pt ? line : `a=rtcp-fb-trr-int:${np}${(_f = m[2]) != null ? _f : ""}`;
960
+ }
961
+ if (line.startsWith("a=imageattrs:")) {
962
+ const m = /^a=imageattrs:(\*|\d+)(\s.*)?$/.exec(line);
963
+ if (!m || m[1] === "*") return line;
964
+ const pt = Number(m[1]);
965
+ const np = (_g = remap.get(pt)) != null ? _g : pt;
966
+ return np === pt ? line : `a=imageattrs:${np}${(_h = m[2]) != null ? _h : ""}`;
967
+ }
968
+ return line;
969
+ }
970
+ function stripTelephoneEventsPreserveOrder(sdp) {
971
+ const session = parse(sdp);
972
+ const telPerSection = session.media.map((media) => {
973
+ var _a;
974
+ const tel = /* @__PURE__ */ new Set();
975
+ for (const r of (_a = media.rtp) != null ? _a : []) {
976
+ if (/^telephone-event$/i.test(String(r.codec))) {
977
+ tel.add(Number(r.payload));
978
+ }
979
+ }
980
+ return tel;
981
+ });
982
+ if (!telPerSection.some((s) => s.size > 0)) {
983
+ return sdp;
984
+ }
985
+ const sep = sdpLineSeparator(sdp);
986
+ const lines = splitSdpLines(sdp);
987
+ let secIdx = -1;
988
+ const out = [];
989
+ for (const line of lines) {
990
+ if (line.startsWith("m=")) {
991
+ secIdx++;
992
+ const drop = telPerSection[secIdx];
993
+ if (!drop || drop.size === 0 || !/\bRTP\/SAVPF\b/.test(line)) {
994
+ out.push(line);
995
+ continue;
996
+ }
997
+ const tokens = line.split(/\s+/);
998
+ const head = tokens.slice(0, 3).join(" ");
999
+ const nums = tokens.slice(3).filter((t) => /^\d+$/.test(t)).map(Number).filter((p) => !drop.has(p));
1000
+ out.push(`${head} ${nums.join(" ")}`);
1001
+ continue;
1002
+ }
1003
+ if (secIdx >= 0) {
1004
+ const drop = telPerSection[secIdx];
1005
+ if (drop && drop.size > 0) {
1006
+ const rtp = /^a=rtpmap:(\d+)\s/i.exec(line);
1007
+ if (rtp && drop.has(Number(rtp[1]))) continue;
1008
+ const fmtp = /^a=fmtp:(\d+)\s/i.exec(line);
1009
+ if (fmtp && drop.has(Number(fmtp[1]))) continue;
1010
+ const rfb = /^a=rtcp-fb:(\d+)\s/i.exec(line);
1011
+ if (rfb && drop.has(Number(rfb[1]))) continue;
1012
+ const trr = /^a=rtcp-fb-trr-int:(\d+)\s/i.exec(line);
1013
+ if (trr && drop.has(Number(trr[1]))) continue;
1014
+ }
1015
+ }
1016
+ out.push(line);
1017
+ }
1018
+ return joinSdpLines(out, sep);
1019
+ }
1020
+ function transformOfferSdpCodecDynamicPts(sdp) {
1021
+ var _a;
1022
+ const session = parse(sdp);
1023
+ if (!session.media.some(mediaSectionNeedsSanitizedPtRelocate)) {
1024
+ return sdp;
1025
+ }
1026
+ const remaps = [];
1027
+ const forbidden = /* @__PURE__ */ new Set();
1028
+ for (const media of session.media) {
1029
+ const R = computeCodecRemapForMedia(media, forbidden);
1030
+ remaps.push(R);
1031
+ for (const p of mediaMLinePayloadTypes(media)) {
1032
+ forbidden.add((_a = R.get(p)) != null ? _a : p);
1033
+ }
1034
+ }
1035
+ const sep = sdpLineSeparator(sdp);
1036
+ const lines = splitSdpLines(sdp);
1037
+ let secIdx = -1;
1038
+ const out = [];
1039
+ for (let line of lines) {
1040
+ if (line.startsWith("m=")) {
1041
+ secIdx++;
1042
+ const R2 = remaps[secIdx];
1043
+ if (R2.size > 0 && /\bRTP\/SAVPF\b/.test(line)) {
1044
+ line = rewriteRtpSavpfMPayloads(line, (p) => {
1045
+ var _a2;
1046
+ return (_a2 = R2.get(p)) != null ? _a2 : p;
1047
+ });
1048
+ }
1049
+ out.push(line);
1050
+ continue;
1051
+ }
1052
+ const R = secIdx >= 0 ? remaps[secIdx] : null;
1053
+ if (!R || R.size === 0) {
1054
+ out.push(line);
1055
+ continue;
1056
+ }
1057
+ out.push(applyRemapToMediaAttributeLine(line, R));
1058
+ }
1059
+ return joinSdpLines(out, sep);
1060
+ }
1061
+ function sanitize(sdp) {
1062
+ const stripped = stripTelephoneEventsPreserveOrder(sdp);
1063
+ const remapped = transformOfferSdpCodecDynamicPts(stripped);
1064
+ return reorderCodecAttributes(remapped);
1065
+ }
1066
+
694
1067
  // src/utils/webrtc.ts
695
1068
  var DEFAULT_DATA_CHANNEL_LABEL = "data";
696
1069
  var FORCE_RELAY_MODE = false;
@@ -706,8 +1079,12 @@ function createDataChannel(pc, label) {
706
1079
  }
707
1080
  function createOffer(pc) {
708
1081
  return __async(this, null, function* () {
709
- const offer = yield pc.createOffer();
710
- yield pc.setLocalDescription(offer);
1082
+ var _a;
1083
+ const initial = yield pc.createOffer();
1084
+ const sdp = sanitize((_a = initial.sdp) != null ? _a : "");
1085
+ yield pc.setLocalDescription(
1086
+ new RTCSessionDescription({ type: initial.type, sdp })
1087
+ );
711
1088
  yield waitForIceGathering(pc);
712
1089
  const localDescription = pc.localDescription;
713
1090
  if (!localDescription) {
@@ -791,50 +1168,78 @@ function parseMessage(data) {
791
1168
  function closePeerConnection(pc) {
792
1169
  pc.close();
793
1170
  }
794
- function extractConnectionStats(report) {
795
- let rtt;
796
- let availableOutgoingBitrate;
797
- let localCandidateId;
798
- let framesPerSecond;
799
- let jitter;
800
- let packetLossRatio;
801
- report.forEach((stat) => {
802
- if (stat.type === "candidate-pair" && stat.state === "succeeded") {
803
- if (stat.currentRoundTripTime !== void 0) {
804
- rtt = stat.currentRoundTripTime * 1e3;
805
- }
806
- if (stat.availableOutgoingBitrate !== void 0) {
807
- availableOutgoingBitrate = stat.availableOutgoingBitrate;
808
- }
809
- localCandidateId = stat.localCandidateId;
810
- }
811
- if (stat.type === "inbound-rtp" && stat.kind === "video") {
812
- if (stat.framesPerSecond !== void 0) {
813
- framesPerSecond = stat.framesPerSecond;
814
- }
815
- if (stat.jitter !== void 0) {
816
- jitter = stat.jitter;
1171
+ function createRTCStatsExtractor() {
1172
+ let lastBytesReceived;
1173
+ let lastBytesSent;
1174
+ let lastCandPairTimestamp;
1175
+ return (report) => {
1176
+ let candPairId;
1177
+ let rtt;
1178
+ let availableOutgoingBitrate;
1179
+ let availableIncomingBitrate;
1180
+ let incomingBitrate;
1181
+ let outgoingBitrate;
1182
+ let videoInboundRtpId;
1183
+ let framesPerSecond;
1184
+ let jitter;
1185
+ let packetLossRatio;
1186
+ let candidateType;
1187
+ report.forEach((stat) => {
1188
+ if (candPairId === void 0 && stat.type === "candidate-pair" && stat.state === "succeeded" && stat.nominated) {
1189
+ candPairId = stat.id;
1190
+ if (stat.currentRoundTripTime !== void 0) {
1191
+ rtt = stat.currentRoundTripTime * 1e3;
1192
+ }
1193
+ if (stat.availableOutgoingBitrate !== void 0) {
1194
+ availableOutgoingBitrate = stat.availableOutgoingBitrate;
1195
+ }
1196
+ if (stat.availableIncomingBitrate != void 0) {
1197
+ availableIncomingBitrate = stat.availableIncomingBitrate;
1198
+ }
1199
+ const localCandidate = report.get(stat.localCandidateId);
1200
+ if (localCandidate == null ? void 0 : localCandidate.candidateType) {
1201
+ candidateType = localCandidate.candidateType;
1202
+ }
1203
+ const timeDiff = lastCandPairTimestamp !== void 0 ? stat.timestamp - lastCandPairTimestamp : 0;
1204
+ if (stat.bytesReceived !== void 0) {
1205
+ if (lastBytesReceived !== void 0 && timeDiff > 0) {
1206
+ incomingBitrate = (stat.bytesReceived - lastBytesReceived) * 8 / timeDiff * 1e3;
1207
+ }
1208
+ lastBytesReceived = stat.bytesReceived;
1209
+ }
1210
+ if (stat.bytesSent !== void 0) {
1211
+ if (lastBytesSent !== void 0 && timeDiff > 0) {
1212
+ outgoingBitrate = (stat.bytesSent - lastBytesSent) * 8 / timeDiff * 1e3;
1213
+ }
1214
+ lastBytesSent = stat.bytesSent;
1215
+ }
1216
+ lastCandPairTimestamp = stat.timestamp;
817
1217
  }
818
- if (stat.packetsReceived !== void 0 && stat.packetsLost !== void 0 && stat.packetsReceived + stat.packetsLost > 0) {
819
- packetLossRatio = stat.packetsLost / (stat.packetsReceived + stat.packetsLost);
1218
+ if (videoInboundRtpId === void 0 && stat.type === "inbound-rtp" && stat.kind === "video") {
1219
+ videoInboundRtpId = stat.id;
1220
+ if (stat.framesPerSecond !== void 0) {
1221
+ framesPerSecond = stat.framesPerSecond;
1222
+ }
1223
+ if (stat.jitter !== void 0) {
1224
+ jitter = stat.jitter;
1225
+ }
1226
+ if (stat.packetsReceived !== void 0 && stat.packetsLost !== void 0 && stat.packetsReceived + stat.packetsLost > 0) {
1227
+ packetLossRatio = stat.packetsLost / (stat.packetsReceived + stat.packetsLost);
1228
+ }
820
1229
  }
821
- }
822
- });
823
- let candidateType;
824
- if (localCandidateId) {
825
- const localCandidate = report.get(localCandidateId);
826
- if (localCandidate == null ? void 0 : localCandidate.candidateType) {
827
- candidateType = localCandidate.candidateType;
828
- }
829
- }
830
- return {
831
- rtt,
832
- candidateType,
833
- availableOutgoingBitrate,
834
- framesPerSecond,
835
- packetLossRatio,
836
- jitter,
837
- timestamp: Date.now()
1230
+ });
1231
+ return {
1232
+ rtt,
1233
+ candidateType,
1234
+ availableIncomingBitrate,
1235
+ availableOutgoingBitrate,
1236
+ incomingBitrate,
1237
+ outgoingBitrate,
1238
+ framesPerSecond,
1239
+ packetLossRatio,
1240
+ jitter,
1241
+ timestamp: Date.now()
1242
+ };
838
1243
  };
839
1244
  }
840
1245
 
@@ -1265,11 +1670,12 @@ var WebRTCTransportClient = class {
1265
1670
  }
1266
1671
  startStatsPolling() {
1267
1672
  this.stopStatsPolling();
1673
+ const statsExtractor = createRTCStatsExtractor();
1268
1674
  this.statsInterval = setInterval(() => __async(this, null, function* () {
1269
1675
  if (!this.peerConnection) return;
1270
1676
  try {
1271
1677
  const report = yield this.peerConnection.getStats();
1272
- this.stats = extractConnectionStats(report);
1678
+ this.stats = statsExtractor(report);
1273
1679
  this.emit("statsUpdate", this.stats);
1274
1680
  } catch (e) {
1275
1681
  }
@@ -1367,7 +1773,7 @@ var WebRTCTransportClient = class {
1367
1773
  }
1368
1774
  };
1369
1775
  this.peerConnection.onicecandidateerror = (event) => {
1370
- console.warn("[WebRTCTransport] ICE candidate error:", event);
1776
+ console.debug("[WebRTCTransport] ICE candidate error:", event);
1371
1777
  };
1372
1778
  this.peerConnection.ondatachannel = (event) => {
1373
1779
  console.debug("[WebRTCTransport] Data channel received from remote");
@@ -2301,7 +2707,7 @@ function useStats() {
2301
2707
 
2302
2708
  // src/react/ReactorView.tsx
2303
2709
  import { useEffect as useEffect3, useMemo, useRef as useRef3 } from "react";
2304
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
2710
+ import { jsx as jsx2 } from "react/jsx-runtime";
2305
2711
  function ReactorView({
2306
2712
  track = "main_video",
2307
2713
  audioTrack,
@@ -2312,12 +2718,11 @@ function ReactorView({
2312
2718
  videoObjectFit = "contain",
2313
2719
  muted = true
2314
2720
  }) {
2315
- const { videoMediaTrack, audioMediaTrack, status } = useReactor((state) => {
2721
+ const { videoMediaTrack, audioMediaTrack } = useReactor((state) => {
2316
2722
  var _a, _b;
2317
2723
  return {
2318
2724
  videoMediaTrack: (_a = state.tracks[track]) != null ? _a : null,
2319
- audioMediaTrack: audioTrack ? (_b = state.tracks[audioTrack]) != null ? _b : null : null,
2320
- status: state.status
2725
+ audioMediaTrack: audioTrack ? (_b = state.tracks[audioTrack]) != null ? _b : null : null
2321
2726
  };
2322
2727
  });
2323
2728
  const videoRef = useRef3(null);
@@ -2356,8 +2761,7 @@ function ReactorView({
2356
2761
  console.debug("[ReactorView] No tracks or element to attach");
2357
2762
  }
2358
2763
  }, [mediaStream]);
2359
- const showPlaceholder = !videoMediaTrack;
2360
- return /* @__PURE__ */ jsxs(
2764
+ return /* @__PURE__ */ jsx2(
2361
2765
  "div",
2362
2766
  {
2363
2767
  style: __spreadValues(__spreadValues(__spreadValues({
@@ -2365,51 +2769,27 @@ function ReactorView({
2365
2769
  background: "#000"
2366
2770
  }, width && { width }), height && { height }), style),
2367
2771
  className,
2368
- children: [
2369
- /* @__PURE__ */ jsx2(
2370
- "video",
2371
- {
2372
- ref: videoRef,
2373
- style: {
2374
- width: "100%",
2375
- height: "100%",
2376
- objectFit: videoObjectFit,
2377
- display: showPlaceholder ? "none" : "block"
2378
- },
2379
- muted,
2380
- playsInline: true
2381
- }
2382
- ),
2383
- showPlaceholder && /* @__PURE__ */ jsx2(
2384
- "div",
2385
- {
2386
- style: {
2387
- position: "absolute",
2388
- top: 0,
2389
- left: 0,
2390
- width: "100%",
2391
- height: "100%",
2392
- color: "#fff",
2393
- display: "flex",
2394
- alignItems: "center",
2395
- justifyContent: "center",
2396
- fontSize: "16px",
2397
- fontFamily: "monospace",
2398
- textAlign: "center",
2399
- padding: "20px",
2400
- boxSizing: "border-box"
2401
- },
2402
- children: status
2403
- }
2404
- )
2405
- ]
2772
+ children: /* @__PURE__ */ jsx2(
2773
+ "video",
2774
+ {
2775
+ ref: videoRef,
2776
+ style: {
2777
+ width: "100%",
2778
+ height: "100%",
2779
+ objectFit: videoObjectFit,
2780
+ display: videoMediaTrack ? "block" : "none"
2781
+ },
2782
+ muted,
2783
+ playsInline: true
2784
+ }
2785
+ )
2406
2786
  }
2407
2787
  );
2408
2788
  }
2409
2789
 
2410
2790
  // src/react/ReactorController.tsx
2411
2791
  import React, { useState as useState3, useCallback, useRef as useRef4 } from "react";
2412
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
2792
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
2413
2793
  function isFileParam(ps) {
2414
2794
  return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
2415
2795
  }
@@ -2565,8 +2945,8 @@ function ReactorController({
2565
2945
  const step = isInteger ? 1 : 0.1;
2566
2946
  const parseValue = isInteger ? parseInt : parseFloat;
2567
2947
  if (typeof paramSchema.minimum === "number" && typeof paramSchema.maximum === "number") {
2568
- return /* @__PURE__ */ jsxs2("div", { style: { marginBottom: "8px" }, children: [
2569
- /* @__PURE__ */ jsxs2(
2948
+ return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
2949
+ /* @__PURE__ */ jsxs(
2570
2950
  "label",
2571
2951
  {
2572
2952
  style: { fontSize: "12px", color: "#666", display: "block" },
@@ -2598,14 +2978,14 @@ function ReactorController({
2598
2978
  style: { width: "100%", marginBottom: "4px" }
2599
2979
  }
2600
2980
  ),
2601
- /* @__PURE__ */ jsxs2("div", { style: { fontSize: "11px", color: "#888" }, children: [
2981
+ /* @__PURE__ */ jsxs("div", { style: { fontSize: "11px", color: "#888" }, children: [
2602
2982
  "Value: ",
2603
2983
  value
2604
2984
  ] })
2605
2985
  ] });
2606
2986
  } else {
2607
- return /* @__PURE__ */ jsxs2("div", { style: { marginBottom: "8px" }, children: [
2608
- /* @__PURE__ */ jsxs2(
2987
+ return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
2988
+ /* @__PURE__ */ jsxs(
2609
2989
  "label",
2610
2990
  {
2611
2991
  style: { fontSize: "12px", color: "#666", display: "block" },
@@ -2655,8 +3035,8 @@ function ReactorController({
2655
3035
  }
2656
3036
  } else if (paramSchema.type === "string") {
2657
3037
  if (paramSchema.enum) {
2658
- return /* @__PURE__ */ jsxs2("div", { style: { marginBottom: "8px" }, children: [
2659
- /* @__PURE__ */ jsxs2(
3038
+ return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
3039
+ /* @__PURE__ */ jsxs(
2660
3040
  "label",
2661
3041
  {
2662
3042
  style: { fontSize: "12px", color: "#666", display: "block" },
@@ -2667,7 +3047,7 @@ function ReactorController({
2667
3047
  ]
2668
3048
  }
2669
3049
  ),
2670
- /* @__PURE__ */ jsxs2(
3050
+ /* @__PURE__ */ jsxs(
2671
3051
  "select",
2672
3052
  {
2673
3053
  value,
@@ -2687,8 +3067,8 @@ function ReactorController({
2687
3067
  )
2688
3068
  ] });
2689
3069
  } else {
2690
- return /* @__PURE__ */ jsxs2("div", { style: { marginBottom: "8px" }, children: [
2691
- /* @__PURE__ */ jsxs2(
3070
+ return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
3071
+ /* @__PURE__ */ jsxs(
2692
3072
  "label",
2693
3073
  {
2694
3074
  style: { fontSize: "12px", color: "#666", display: "block" },
@@ -2717,7 +3097,7 @@ function ReactorController({
2717
3097
  ] });
2718
3098
  }
2719
3099
  } else if (paramSchema.type === "boolean") {
2720
- return /* @__PURE__ */ jsx3("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ jsxs2(
3100
+ return /* @__PURE__ */ jsx3("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ jsxs(
2721
3101
  "label",
2722
3102
  {
2723
3103
  style: {
@@ -2753,7 +3133,7 @@ function ReactorController({
2753
3133
  (ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
2754
3134
  );
2755
3135
  const showExecuteButton = !allSliders;
2756
- return /* @__PURE__ */ jsxs2(
3136
+ return /* @__PURE__ */ jsxs(
2757
3137
  "div",
2758
3138
  {
2759
3139
  style: {
@@ -2763,7 +3143,7 @@ function ReactorController({
2763
3143
  backgroundColor: "#fafafa"
2764
3144
  },
2765
3145
  children: [
2766
- /* @__PURE__ */ jsxs2(
3146
+ /* @__PURE__ */ jsxs(
2767
3147
  "div",
2768
3148
  {
2769
3149
  onClick: () => toggleCommandExpanded(commandName),
@@ -2776,7 +3156,7 @@ function ReactorController({
2776
3156
  alignItems: "center"
2777
3157
  },
2778
3158
  children: [
2779
- /* @__PURE__ */ jsxs2("div", { children: [
3159
+ /* @__PURE__ */ jsxs("div", { children: [
2780
3160
  /* @__PURE__ */ jsx3(
2781
3161
  "h4",
2782
3162
  {
@@ -2811,8 +3191,8 @@ function ReactorController({
2811
3191
  ]
2812
3192
  }
2813
3193
  ),
2814
- isExpanded && /* @__PURE__ */ jsxs2("div", { style: { padding: "12px", paddingTop: "0" }, children: [
2815
- hasParams && /* @__PURE__ */ jsxs2("div", { style: { marginBottom: showExecuteButton ? "12px" : "0" }, children: [
3194
+ isExpanded && /* @__PURE__ */ jsxs("div", { style: { padding: "12px", paddingTop: "0" }, children: [
3195
+ hasParams && /* @__PURE__ */ jsxs("div", { style: { marginBottom: showExecuteButton ? "12px" : "0" }, children: [
2816
3196
  /* @__PURE__ */ jsx3(
2817
3197
  "div",
2818
3198
  {
@@ -2849,7 +3229,7 @@ function ReactorController({
2849
3229
  children: "No parameters required"
2850
3230
  }
2851
3231
  ),
2852
- showExecuteButton && /* @__PURE__ */ jsxs2(
3232
+ showExecuteButton && /* @__PURE__ */ jsxs(
2853
3233
  "button",
2854
3234
  {
2855
3235
  onClick: () => handleCommandSubmit(commandName),
@@ -2875,7 +3255,7 @@ function ReactorController({
2875
3255
  commandName
2876
3256
  );
2877
3257
  };
2878
- return /* @__PURE__ */ jsx3("div", { className, style, children: /* @__PURE__ */ jsx3("div", { style: { fontFamily: "monospace", fontSize: "12px" }, children: Object.keys(commands).length === 0 ? /* @__PURE__ */ jsx3("div", { style: { padding: "12px", color: "#666", fontStyle: "italic" }, children: "Waiting for commands schema..." }) : /* @__PURE__ */ jsxs2("div", { children: [
3258
+ return /* @__PURE__ */ jsx3("div", { className, style, children: /* @__PURE__ */ jsx3("div", { style: { fontFamily: "monospace", fontSize: "12px" }, children: Object.keys(commands).length === 0 ? /* @__PURE__ */ jsx3("div", { style: { padding: "12px", color: "#666", fontStyle: "italic" }, children: "Waiting for commands schema..." }) : /* @__PURE__ */ jsxs("div", { children: [
2879
3259
  /* @__PURE__ */ jsx3(
2880
3260
  "h3",
2881
3261
  {
@@ -2917,13 +3297,13 @@ function FileParamInput({
2917
3297
  setUploading(false);
2918
3298
  }
2919
3299
  });
2920
- return /* @__PURE__ */ jsxs2("div", { style: { marginBottom: "8px" }, children: [
2921
- /* @__PURE__ */ jsxs2("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
3300
+ return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
3301
+ /* @__PURE__ */ jsxs("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
2922
3302
  paramName,
2923
3303
  /* @__PURE__ */ jsx3("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
2924
3304
  description && ` - ${description}`
2925
3305
  ] }),
2926
- /* @__PURE__ */ jsxs2(
3306
+ /* @__PURE__ */ jsxs(
2927
3307
  "div",
2928
3308
  {
2929
3309
  style: {
@@ -2964,7 +3344,7 @@ function FileParamInput({
2964
3344
  children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
2965
3345
  }
2966
3346
  ),
2967
- fileRef && /* @__PURE__ */ jsxs2("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
3347
+ fileRef && /* @__PURE__ */ jsxs("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
2968
3348
  "\\u2713 ",
2969
3349
  fileRef.name
2970
3350
  ] })
@@ -2976,7 +3356,7 @@ function FileParamInput({
2976
3356
 
2977
3357
  // src/react/WebcamStream.tsx
2978
3358
  import { useEffect as useEffect4, useRef as useRef5, useState as useState4 } from "react";
2979
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
3359
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
2980
3360
  function WebcamStream({
2981
3361
  track,
2982
3362
  className,
@@ -3110,7 +3490,7 @@ function WebcamStream({
3110
3490
  };
3111
3491
  }, []);
3112
3492
  const showPlaceholder = !stream;
3113
- return /* @__PURE__ */ jsxs3(
3493
+ return /* @__PURE__ */ jsxs2(
3114
3494
  "div",
3115
3495
  {
3116
3496
  style: __spreadValues({
@@ -3156,7 +3536,7 @@ function WebcamStream({
3156
3536
  flexDirection: "column",
3157
3537
  gap: "12px"
3158
3538
  },
3159
- children: permissionDenied ? /* @__PURE__ */ jsxs3("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
3539
+ children: permissionDenied ? /* @__PURE__ */ jsxs2("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
3160
3540
  "Camera access denied.",
3161
3541
  /* @__PURE__ */ jsx4("br", {}),
3162
3542
  "Please allow access in your browser settings."