@reactor-team/js-sdk 2.9.2 → 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.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +452 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +452 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
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.
|
|
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
|
-
|
|
710
|
-
yield pc.
|
|
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
|
|
795
|
-
let
|
|
796
|
-
let
|
|
797
|
-
let
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
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 (
|
|
819
|
-
|
|
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
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
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 =
|
|
1678
|
+
this.stats = statsExtractor(report);
|
|
1273
1679
|
this.emit("statsUpdate", this.stats);
|
|
1274
1680
|
} catch (e) {
|
|
1275
1681
|
}
|