@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.d.mts
CHANGED
|
@@ -158,8 +158,14 @@ interface ConnectionStats {
|
|
|
158
158
|
rtt?: number;
|
|
159
159
|
/** ICE candidate type: "host", "srflx", "prflx", or "relay" (TURN) */
|
|
160
160
|
candidateType?: string;
|
|
161
|
+
/** Estimated available incoming bitrate in bits/second */
|
|
162
|
+
availableIncomingBitrate?: number;
|
|
161
163
|
/** Estimated available outgoing bitrate in bits/second */
|
|
162
164
|
availableOutgoingBitrate?: number;
|
|
165
|
+
/** Real-time Incoming bitrate in bits/second */
|
|
166
|
+
incomingBitrate?: number;
|
|
167
|
+
/** Real-time Outgoing bitrate in bits/second */
|
|
168
|
+
outgoingBitrate?: number;
|
|
163
169
|
/** Received video frames per second */
|
|
164
170
|
framesPerSecond?: number;
|
|
165
171
|
/** Ratio of packets lost (0-1) */
|
|
@@ -324,7 +330,7 @@ interface ReactorConnectOptions extends ConnectOptions {
|
|
|
324
330
|
interface ReactorProviderProps extends ReactorInitializationProps {
|
|
325
331
|
connectOptions?: ReactorConnectOptions;
|
|
326
332
|
jwtToken?: string;
|
|
327
|
-
children
|
|
333
|
+
children?: ReactNode;
|
|
328
334
|
}
|
|
329
335
|
declare function ReactorProvider({ children, connectOptions, jwtToken, ...props }: ReactorProviderProps): react_jsx_runtime.JSX.Element;
|
|
330
336
|
declare function useReactorStore<T = ReactorStore>(selector: (state: ReactorStore) => T): T;
|
package/dist/index.d.ts
CHANGED
|
@@ -158,8 +158,14 @@ interface ConnectionStats {
|
|
|
158
158
|
rtt?: number;
|
|
159
159
|
/** ICE candidate type: "host", "srflx", "prflx", or "relay" (TURN) */
|
|
160
160
|
candidateType?: string;
|
|
161
|
+
/** Estimated available incoming bitrate in bits/second */
|
|
162
|
+
availableIncomingBitrate?: number;
|
|
161
163
|
/** Estimated available outgoing bitrate in bits/second */
|
|
162
164
|
availableOutgoingBitrate?: number;
|
|
165
|
+
/** Real-time Incoming bitrate in bits/second */
|
|
166
|
+
incomingBitrate?: number;
|
|
167
|
+
/** Real-time Outgoing bitrate in bits/second */
|
|
168
|
+
outgoingBitrate?: number;
|
|
163
169
|
/** Received video frames per second */
|
|
164
170
|
framesPerSecond?: number;
|
|
165
171
|
/** Ratio of packets lost (0-1) */
|
|
@@ -324,7 +330,7 @@ interface ReactorConnectOptions extends ConnectOptions {
|
|
|
324
330
|
interface ReactorProviderProps extends ReactorInitializationProps {
|
|
325
331
|
connectOptions?: ReactorConnectOptions;
|
|
326
332
|
jwtToken?: string;
|
|
327
|
-
children
|
|
333
|
+
children?: ReactNode;
|
|
328
334
|
}
|
|
329
335
|
declare function ReactorProvider({ children, connectOptions, jwtToken, ...props }: ReactorProviderProps): react_jsx_runtime.JSX.Element;
|
|
330
336
|
declare function useReactorStore<T = ReactorStore>(selector: (state: ReactorStore) => T): T;
|
package/dist/index.js
CHANGED
|
@@ -130,7 +130,7 @@ var import_zod = require("zod");
|
|
|
130
130
|
// package.json
|
|
131
131
|
var package_default = {
|
|
132
132
|
name: "@reactor-team/js-sdk",
|
|
133
|
-
version: "2.9.
|
|
133
|
+
version: "2.9.3",
|
|
134
134
|
description: "Reactor JavaScript frontend SDK",
|
|
135
135
|
main: "dist/index.js",
|
|
136
136
|
module: "dist/index.mjs",
|
|
@@ -177,6 +177,7 @@ var package_default = {
|
|
|
177
177
|
"@types/inquirer": "^9.0.9",
|
|
178
178
|
"@types/node": "^20",
|
|
179
179
|
"@types/react": "^18.2.8",
|
|
180
|
+
"@types/sdp-transform": "^2.15.0",
|
|
180
181
|
"@types/ws": "^8.18.1",
|
|
181
182
|
prettier: "^3.6.2",
|
|
182
183
|
tsup: "^8.5.0",
|
|
@@ -187,6 +188,7 @@ var package_default = {
|
|
|
187
188
|
"@bufbuild/protobuf": "^2.0.0",
|
|
188
189
|
chalk: "^5.3.0",
|
|
189
190
|
inquirer: "^9.3.0",
|
|
191
|
+
"sdp-transform": "^3.0.0",
|
|
190
192
|
"simple-git": "^3.24.0",
|
|
191
193
|
ws: "^8.18.3",
|
|
192
194
|
zod: "^4.0.5"
|
|
@@ -738,6 +740,377 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
|
|
|
738
740
|
}
|
|
739
741
|
};
|
|
740
742
|
|
|
743
|
+
// src/utils/sdp.ts
|
|
744
|
+
var import_sdp_transform = require("sdp-transform");
|
|
745
|
+
function sdpLineSeparator(sdp) {
|
|
746
|
+
return sdp.includes("\r\n") ? "\r\n" : "\n";
|
|
747
|
+
}
|
|
748
|
+
function splitSdpLines(sdp) {
|
|
749
|
+
return sdp.split(/\r?\n/);
|
|
750
|
+
}
|
|
751
|
+
function joinSdpLines(lines, sep) {
|
|
752
|
+
return lines.join(sep);
|
|
753
|
+
}
|
|
754
|
+
var DYNAMIC_PT_MIN = 96;
|
|
755
|
+
var DYNAMIC_PT_MAX = 127;
|
|
756
|
+
function isSanitizedVideoCodecRtpmapEncoding(name) {
|
|
757
|
+
const u = name.toUpperCase();
|
|
758
|
+
if (/^(H265|HEVC|HEV1|HVC1)/.test(u)) return true;
|
|
759
|
+
if (/^VP8(\/|$)/.test(u)) return true;
|
|
760
|
+
if (/^VP9(\/|$)/.test(u)) return true;
|
|
761
|
+
if (/^H264(\/|$)/.test(u)) return true;
|
|
762
|
+
return false;
|
|
763
|
+
}
|
|
764
|
+
function isOpusRtpmapEncoding(name) {
|
|
765
|
+
return /^OPUS(\/|$)/i.test(name);
|
|
766
|
+
}
|
|
767
|
+
function mediaMLinePayloadTypes(media) {
|
|
768
|
+
var _a;
|
|
769
|
+
return (0, import_sdp_transform.parsePayloads)(String((_a = media.payloads) != null ? _a : ""));
|
|
770
|
+
}
|
|
771
|
+
function collectRtpmap(media) {
|
|
772
|
+
var _a;
|
|
773
|
+
const rtpmap = /* @__PURE__ */ new Map();
|
|
774
|
+
for (const r of (_a = media.rtp) != null ? _a : []) {
|
|
775
|
+
rtpmap.set(Number(r.payload), String(r.codec));
|
|
776
|
+
}
|
|
777
|
+
return rtpmap;
|
|
778
|
+
}
|
|
779
|
+
function collectSanitizedCodecPayloadSet(media) {
|
|
780
|
+
const rtpmap = collectRtpmap(media);
|
|
781
|
+
const tracked = /* @__PURE__ */ new Set();
|
|
782
|
+
if (media.type === "video") {
|
|
783
|
+
for (const [pt, enc] of rtpmap) {
|
|
784
|
+
if (isSanitizedVideoCodecRtpmapEncoding(enc)) tracked.add(pt);
|
|
785
|
+
}
|
|
786
|
+
} else if (media.type === "audio") {
|
|
787
|
+
for (const [pt, enc] of rtpmap) {
|
|
788
|
+
if (isOpusRtpmapEncoding(enc)) tracked.add(pt);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return tracked.size > 0 ? tracked : null;
|
|
792
|
+
}
|
|
793
|
+
function mediaSectionNeedsSanitizedPtRelocate(media) {
|
|
794
|
+
const pts = collectSanitizedCodecPayloadSet(media);
|
|
795
|
+
if (!pts) {
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
return [...pts].some((p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX);
|
|
799
|
+
}
|
|
800
|
+
function codecRelocationPriority(enc) {
|
|
801
|
+
const u = (enc != null ? enc : "").toUpperCase();
|
|
802
|
+
if (/^(H265|HEVC|HEV1|HVC1)/.test(u)) return 0;
|
|
803
|
+
if (/^H264(\/|$)/.test(u)) return 1;
|
|
804
|
+
if (/^VP9(\/|$)/.test(u)) return 2;
|
|
805
|
+
if (/^VP8(\/|$)/.test(u)) return 3;
|
|
806
|
+
if (/^OPUS(\/|$)/.test(u)) return 4;
|
|
807
|
+
return 5;
|
|
808
|
+
}
|
|
809
|
+
function sortedRelocate(relocate, rtpmap) {
|
|
810
|
+
return [...relocate].sort(
|
|
811
|
+
(a, b) => codecRelocationPriority(rtpmap.get(a)) - codecRelocationPriority(rtpmap.get(b))
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
function remapFmtpConfigForPayloadMap(config, remap) {
|
|
815
|
+
let s = config;
|
|
816
|
+
const pairs = [...remap.entries()].sort((a, b) => b[0] - a[0]);
|
|
817
|
+
for (const [oldP, newP] of pairs) {
|
|
818
|
+
if (oldP === newP) continue;
|
|
819
|
+
s = s.replace(new RegExp(`apt=${oldP}([^0-9]|$)`, "g"), `apt=${newP}$1`);
|
|
820
|
+
}
|
|
821
|
+
return s;
|
|
822
|
+
}
|
|
823
|
+
function computeCodecRemapForMedia(media, forbidden) {
|
|
824
|
+
const remap = /* @__PURE__ */ new Map();
|
|
825
|
+
if (media.type !== "video" && media.type !== "audio") {
|
|
826
|
+
return remap;
|
|
827
|
+
}
|
|
828
|
+
const tracked = collectSanitizedCodecPayloadSet(media);
|
|
829
|
+
if (!tracked) {
|
|
830
|
+
return remap;
|
|
831
|
+
}
|
|
832
|
+
const relocate = [...tracked].filter(
|
|
833
|
+
(p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX
|
|
834
|
+
);
|
|
835
|
+
if (relocate.length === 0) {
|
|
836
|
+
return remap;
|
|
837
|
+
}
|
|
838
|
+
const rtpmap = collectRtpmap(media);
|
|
839
|
+
const ordered = sortedRelocate(relocate, rtpmap);
|
|
840
|
+
const usedPts = new Set(forbidden);
|
|
841
|
+
for (const p of mediaMLinePayloadTypes(media)) {
|
|
842
|
+
if (p >= DYNAMIC_PT_MIN && p <= DYNAMIC_PT_MAX) usedPts.add(p);
|
|
843
|
+
}
|
|
844
|
+
let candidate = DYNAMIC_PT_MIN;
|
|
845
|
+
for (const oldPt of ordered) {
|
|
846
|
+
while (candidate <= DYNAMIC_PT_MAX && usedPts.has(candidate)) candidate++;
|
|
847
|
+
if (candidate > DYNAMIC_PT_MAX) break;
|
|
848
|
+
remap.set(oldPt, candidate);
|
|
849
|
+
usedPts.add(candidate);
|
|
850
|
+
candidate++;
|
|
851
|
+
}
|
|
852
|
+
return remap;
|
|
853
|
+
}
|
|
854
|
+
function rewriteRtpSavpfMPayloads(mLine, mapPt) {
|
|
855
|
+
if (!/\bRTP\/SAVPF\b/.test(mLine)) {
|
|
856
|
+
return mLine;
|
|
857
|
+
}
|
|
858
|
+
const tokens = mLine.split(/\s+/);
|
|
859
|
+
if (tokens.length < 4) {
|
|
860
|
+
return mLine;
|
|
861
|
+
}
|
|
862
|
+
const head = tokens.slice(0, 3).join(" ");
|
|
863
|
+
const tail = tokens.slice(3).map((t) => /^\d+$/.test(t) ? String(mapPt(Number(t))) : t);
|
|
864
|
+
return `${head} ${tail.join(" ")}`;
|
|
865
|
+
}
|
|
866
|
+
function payloadTypesFromSavpfMLine(mLine) {
|
|
867
|
+
const m = /\bRTP\/SAVPF\s+(.+)$/i.exec(mLine);
|
|
868
|
+
return m ? (0, import_sdp_transform.parsePayloads)(m[1].trim()) : [];
|
|
869
|
+
}
|
|
870
|
+
function payloadTypeFromPtBoundAttributeLine(line) {
|
|
871
|
+
if (line.startsWith("a=rtpmap:")) {
|
|
872
|
+
const x = /^a=rtpmap:(\d+)/i.exec(line);
|
|
873
|
+
return x ? Number(x[1]) : null;
|
|
874
|
+
}
|
|
875
|
+
if (line.startsWith("a=fmtp:")) {
|
|
876
|
+
const x = /^a=fmtp:(\d+)/i.exec(line);
|
|
877
|
+
return x ? Number(x[1]) : null;
|
|
878
|
+
}
|
|
879
|
+
if (line.startsWith("a=rtcp-fb:")) {
|
|
880
|
+
const x = /^a=rtcp-fb:(\*|(\d+))/i.exec(line);
|
|
881
|
+
if (!x || x[1] === "*") return null;
|
|
882
|
+
return Number(x[2]);
|
|
883
|
+
}
|
|
884
|
+
if (line.startsWith("a=rtcp-fb-trr-int:")) {
|
|
885
|
+
const x = /^a=rtcp-fb-trr-int:(\*|(\d+))/i.exec(line);
|
|
886
|
+
if (!x || x[1] === "*") return null;
|
|
887
|
+
return Number(x[2]);
|
|
888
|
+
}
|
|
889
|
+
if (line.startsWith("a=imageattrs:")) {
|
|
890
|
+
const x = /^a=imageattrs:(\*|(\d+))/i.exec(line);
|
|
891
|
+
if (!x || x[1] === "*") return null;
|
|
892
|
+
return Number(x[2]);
|
|
893
|
+
}
|
|
894
|
+
return null;
|
|
895
|
+
}
|
|
896
|
+
function isPtBoundCodecAttributeLine(line) {
|
|
897
|
+
return payloadTypeFromPtBoundAttributeLine(line) !== null;
|
|
898
|
+
}
|
|
899
|
+
function reorderSingleRtpSavpfSection(sec) {
|
|
900
|
+
const mLine = sec[0];
|
|
901
|
+
if (!/\bRTP\/SAVPF\b/.test(mLine)) {
|
|
902
|
+
return sec;
|
|
903
|
+
}
|
|
904
|
+
const body = sec.slice(1);
|
|
905
|
+
let first = -1;
|
|
906
|
+
let last = -1;
|
|
907
|
+
for (let j = 0; j < body.length; j++) {
|
|
908
|
+
if (isPtBoundCodecAttributeLine(body[j])) {
|
|
909
|
+
if (first === -1) first = j;
|
|
910
|
+
last = j;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (first === -1) {
|
|
914
|
+
return sec;
|
|
915
|
+
}
|
|
916
|
+
const prefix = body.slice(0, first);
|
|
917
|
+
const codecLines = body.slice(first, last + 1);
|
|
918
|
+
const suffix = body.slice(last + 1);
|
|
919
|
+
const mPts = payloadTypesFromSavpfMLine(mLine);
|
|
920
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
921
|
+
for (const line of codecLines) {
|
|
922
|
+
const pt = payloadTypeFromPtBoundAttributeLine(line);
|
|
923
|
+
if (pt === null) continue;
|
|
924
|
+
const arr = buckets.get(pt);
|
|
925
|
+
if (arr) arr.push(line);
|
|
926
|
+
else buckets.set(pt, [line]);
|
|
927
|
+
}
|
|
928
|
+
const seenOrder = [];
|
|
929
|
+
for (const line of codecLines) {
|
|
930
|
+
const pt = payloadTypeFromPtBoundAttributeLine(line);
|
|
931
|
+
if (pt !== null && !seenOrder.includes(pt)) seenOrder.push(pt);
|
|
932
|
+
}
|
|
933
|
+
const outCodec = [];
|
|
934
|
+
for (const pt of mPts) {
|
|
935
|
+
const arr = buckets.get(pt);
|
|
936
|
+
if (!arr) continue;
|
|
937
|
+
outCodec.push(...arr);
|
|
938
|
+
buckets.delete(pt);
|
|
939
|
+
}
|
|
940
|
+
for (const pt of seenOrder) {
|
|
941
|
+
const arr = buckets.get(pt);
|
|
942
|
+
if (!arr) continue;
|
|
943
|
+
outCodec.push(...arr);
|
|
944
|
+
buckets.delete(pt);
|
|
945
|
+
}
|
|
946
|
+
for (const arr of buckets.values()) {
|
|
947
|
+
outCodec.push(...arr);
|
|
948
|
+
}
|
|
949
|
+
return [mLine, ...prefix, ...outCodec, ...suffix];
|
|
950
|
+
}
|
|
951
|
+
function reorderCodecAttributes(sdp) {
|
|
952
|
+
const sep = sdpLineSeparator(sdp);
|
|
953
|
+
const lines = splitSdpLines(sdp);
|
|
954
|
+
const out = [];
|
|
955
|
+
let i = 0;
|
|
956
|
+
while (i < lines.length) {
|
|
957
|
+
const line = lines[i];
|
|
958
|
+
if (!line.startsWith("m=")) {
|
|
959
|
+
out.push(line);
|
|
960
|
+
i++;
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
const mLine = line;
|
|
964
|
+
i++;
|
|
965
|
+
const rest = [];
|
|
966
|
+
while (i < lines.length && !lines[i].startsWith("m=")) {
|
|
967
|
+
rest.push(lines[i]);
|
|
968
|
+
i++;
|
|
969
|
+
}
|
|
970
|
+
out.push(...reorderSingleRtpSavpfSection([mLine, ...rest]));
|
|
971
|
+
}
|
|
972
|
+
return joinSdpLines(out, sep);
|
|
973
|
+
}
|
|
974
|
+
function applyRemapToMediaAttributeLine(line, remap) {
|
|
975
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
976
|
+
if (!line.startsWith("a=")) {
|
|
977
|
+
return line;
|
|
978
|
+
}
|
|
979
|
+
if (line.startsWith("a=rtpmap:")) {
|
|
980
|
+
const m = /^a=rtpmap:(\d+)/.exec(line);
|
|
981
|
+
if (!m) return line;
|
|
982
|
+
const pt = Number(m[1]);
|
|
983
|
+
const np = (_a = remap.get(pt)) != null ? _a : pt;
|
|
984
|
+
return np === pt ? line : line.replace(/^a=rtpmap:\d+/, `a=rtpmap:${np}`);
|
|
985
|
+
}
|
|
986
|
+
if (line.startsWith("a=fmtp:")) {
|
|
987
|
+
const m = /^a=fmtp:(\d+)\s(.*)$/.exec(line);
|
|
988
|
+
if (!m) return line;
|
|
989
|
+
const pt = Number(m[1]);
|
|
990
|
+
const np = (_b = remap.get(pt)) != null ? _b : pt;
|
|
991
|
+
const cfg = remapFmtpConfigForPayloadMap(m[2], remap);
|
|
992
|
+
return `a=fmtp:${np} ${cfg}`;
|
|
993
|
+
}
|
|
994
|
+
if (line.startsWith("a=rtcp-fb:")) {
|
|
995
|
+
const m = /^a=rtcp-fb:(\*|\d+)(\s.*)?$/.exec(line);
|
|
996
|
+
if (!m || m[1] === "*") return line;
|
|
997
|
+
const pt = Number(m[1]);
|
|
998
|
+
const np = (_c = remap.get(pt)) != null ? _c : pt;
|
|
999
|
+
return np === pt ? line : `a=rtcp-fb:${np}${(_d = m[2]) != null ? _d : ""}`;
|
|
1000
|
+
}
|
|
1001
|
+
if (line.startsWith("a=rtcp-fb-trr-int:")) {
|
|
1002
|
+
const m = /^a=rtcp-fb-trr-int:(\*|\d+)(\s.*)?$/.exec(line);
|
|
1003
|
+
if (!m || m[1] === "*") return line;
|
|
1004
|
+
const pt = Number(m[1]);
|
|
1005
|
+
const np = (_e = remap.get(pt)) != null ? _e : pt;
|
|
1006
|
+
return np === pt ? line : `a=rtcp-fb-trr-int:${np}${(_f = m[2]) != null ? _f : ""}`;
|
|
1007
|
+
}
|
|
1008
|
+
if (line.startsWith("a=imageattrs:")) {
|
|
1009
|
+
const m = /^a=imageattrs:(\*|\d+)(\s.*)?$/.exec(line);
|
|
1010
|
+
if (!m || m[1] === "*") return line;
|
|
1011
|
+
const pt = Number(m[1]);
|
|
1012
|
+
const np = (_g = remap.get(pt)) != null ? _g : pt;
|
|
1013
|
+
return np === pt ? line : `a=imageattrs:${np}${(_h = m[2]) != null ? _h : ""}`;
|
|
1014
|
+
}
|
|
1015
|
+
return line;
|
|
1016
|
+
}
|
|
1017
|
+
function stripTelephoneEventsPreserveOrder(sdp) {
|
|
1018
|
+
const session = (0, import_sdp_transform.parse)(sdp);
|
|
1019
|
+
const telPerSection = session.media.map((media) => {
|
|
1020
|
+
var _a;
|
|
1021
|
+
const tel = /* @__PURE__ */ new Set();
|
|
1022
|
+
for (const r of (_a = media.rtp) != null ? _a : []) {
|
|
1023
|
+
if (/^telephone-event$/i.test(String(r.codec))) {
|
|
1024
|
+
tel.add(Number(r.payload));
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
return tel;
|
|
1028
|
+
});
|
|
1029
|
+
if (!telPerSection.some((s) => s.size > 0)) {
|
|
1030
|
+
return sdp;
|
|
1031
|
+
}
|
|
1032
|
+
const sep = sdpLineSeparator(sdp);
|
|
1033
|
+
const lines = splitSdpLines(sdp);
|
|
1034
|
+
let secIdx = -1;
|
|
1035
|
+
const out = [];
|
|
1036
|
+
for (const line of lines) {
|
|
1037
|
+
if (line.startsWith("m=")) {
|
|
1038
|
+
secIdx++;
|
|
1039
|
+
const drop = telPerSection[secIdx];
|
|
1040
|
+
if (!drop || drop.size === 0 || !/\bRTP\/SAVPF\b/.test(line)) {
|
|
1041
|
+
out.push(line);
|
|
1042
|
+
continue;
|
|
1043
|
+
}
|
|
1044
|
+
const tokens = line.split(/\s+/);
|
|
1045
|
+
const head = tokens.slice(0, 3).join(" ");
|
|
1046
|
+
const nums = tokens.slice(3).filter((t) => /^\d+$/.test(t)).map(Number).filter((p) => !drop.has(p));
|
|
1047
|
+
out.push(`${head} ${nums.join(" ")}`);
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
if (secIdx >= 0) {
|
|
1051
|
+
const drop = telPerSection[secIdx];
|
|
1052
|
+
if (drop && drop.size > 0) {
|
|
1053
|
+
const rtp = /^a=rtpmap:(\d+)\s/i.exec(line);
|
|
1054
|
+
if (rtp && drop.has(Number(rtp[1]))) continue;
|
|
1055
|
+
const fmtp = /^a=fmtp:(\d+)\s/i.exec(line);
|
|
1056
|
+
if (fmtp && drop.has(Number(fmtp[1]))) continue;
|
|
1057
|
+
const rfb = /^a=rtcp-fb:(\d+)\s/i.exec(line);
|
|
1058
|
+
if (rfb && drop.has(Number(rfb[1]))) continue;
|
|
1059
|
+
const trr = /^a=rtcp-fb-trr-int:(\d+)\s/i.exec(line);
|
|
1060
|
+
if (trr && drop.has(Number(trr[1]))) continue;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
out.push(line);
|
|
1064
|
+
}
|
|
1065
|
+
return joinSdpLines(out, sep);
|
|
1066
|
+
}
|
|
1067
|
+
function transformOfferSdpCodecDynamicPts(sdp) {
|
|
1068
|
+
var _a;
|
|
1069
|
+
const session = (0, import_sdp_transform.parse)(sdp);
|
|
1070
|
+
if (!session.media.some(mediaSectionNeedsSanitizedPtRelocate)) {
|
|
1071
|
+
return sdp;
|
|
1072
|
+
}
|
|
1073
|
+
const remaps = [];
|
|
1074
|
+
const forbidden = /* @__PURE__ */ new Set();
|
|
1075
|
+
for (const media of session.media) {
|
|
1076
|
+
const R = computeCodecRemapForMedia(media, forbidden);
|
|
1077
|
+
remaps.push(R);
|
|
1078
|
+
for (const p of mediaMLinePayloadTypes(media)) {
|
|
1079
|
+
forbidden.add((_a = R.get(p)) != null ? _a : p);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
const sep = sdpLineSeparator(sdp);
|
|
1083
|
+
const lines = splitSdpLines(sdp);
|
|
1084
|
+
let secIdx = -1;
|
|
1085
|
+
const out = [];
|
|
1086
|
+
for (let line of lines) {
|
|
1087
|
+
if (line.startsWith("m=")) {
|
|
1088
|
+
secIdx++;
|
|
1089
|
+
const R2 = remaps[secIdx];
|
|
1090
|
+
if (R2.size > 0 && /\bRTP\/SAVPF\b/.test(line)) {
|
|
1091
|
+
line = rewriteRtpSavpfMPayloads(line, (p) => {
|
|
1092
|
+
var _a2;
|
|
1093
|
+
return (_a2 = R2.get(p)) != null ? _a2 : p;
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
out.push(line);
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
const R = secIdx >= 0 ? remaps[secIdx] : null;
|
|
1100
|
+
if (!R || R.size === 0) {
|
|
1101
|
+
out.push(line);
|
|
1102
|
+
continue;
|
|
1103
|
+
}
|
|
1104
|
+
out.push(applyRemapToMediaAttributeLine(line, R));
|
|
1105
|
+
}
|
|
1106
|
+
return joinSdpLines(out, sep);
|
|
1107
|
+
}
|
|
1108
|
+
function sanitize(sdp) {
|
|
1109
|
+
const stripped = stripTelephoneEventsPreserveOrder(sdp);
|
|
1110
|
+
const remapped = transformOfferSdpCodecDynamicPts(stripped);
|
|
1111
|
+
return reorderCodecAttributes(remapped);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
741
1114
|
// src/utils/webrtc.ts
|
|
742
1115
|
var DEFAULT_DATA_CHANNEL_LABEL = "data";
|
|
743
1116
|
var FORCE_RELAY_MODE = false;
|
|
@@ -753,8 +1126,12 @@ function createDataChannel(pc, label) {
|
|
|
753
1126
|
}
|
|
754
1127
|
function createOffer(pc) {
|
|
755
1128
|
return __async(this, null, function* () {
|
|
756
|
-
|
|
757
|
-
yield pc.
|
|
1129
|
+
var _a;
|
|
1130
|
+
const initial = yield pc.createOffer();
|
|
1131
|
+
const sdp = sanitize((_a = initial.sdp) != null ? _a : "");
|
|
1132
|
+
yield pc.setLocalDescription(
|
|
1133
|
+
new RTCSessionDescription({ type: initial.type, sdp })
|
|
1134
|
+
);
|
|
758
1135
|
yield waitForIceGathering(pc);
|
|
759
1136
|
const localDescription = pc.localDescription;
|
|
760
1137
|
if (!localDescription) {
|
|
@@ -838,50 +1215,78 @@ function parseMessage(data) {
|
|
|
838
1215
|
function closePeerConnection(pc) {
|
|
839
1216
|
pc.close();
|
|
840
1217
|
}
|
|
841
|
-
function
|
|
842
|
-
let
|
|
843
|
-
let
|
|
844
|
-
let
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
1218
|
+
function createRTCStatsExtractor() {
|
|
1219
|
+
let lastBytesReceived;
|
|
1220
|
+
let lastBytesSent;
|
|
1221
|
+
let lastCandPairTimestamp;
|
|
1222
|
+
return (report) => {
|
|
1223
|
+
let candPairId;
|
|
1224
|
+
let rtt;
|
|
1225
|
+
let availableOutgoingBitrate;
|
|
1226
|
+
let availableIncomingBitrate;
|
|
1227
|
+
let incomingBitrate;
|
|
1228
|
+
let outgoingBitrate;
|
|
1229
|
+
let videoInboundRtpId;
|
|
1230
|
+
let framesPerSecond;
|
|
1231
|
+
let jitter;
|
|
1232
|
+
let packetLossRatio;
|
|
1233
|
+
let candidateType;
|
|
1234
|
+
report.forEach((stat) => {
|
|
1235
|
+
if (candPairId === void 0 && stat.type === "candidate-pair" && stat.state === "succeeded" && stat.nominated) {
|
|
1236
|
+
candPairId = stat.id;
|
|
1237
|
+
if (stat.currentRoundTripTime !== void 0) {
|
|
1238
|
+
rtt = stat.currentRoundTripTime * 1e3;
|
|
1239
|
+
}
|
|
1240
|
+
if (stat.availableOutgoingBitrate !== void 0) {
|
|
1241
|
+
availableOutgoingBitrate = stat.availableOutgoingBitrate;
|
|
1242
|
+
}
|
|
1243
|
+
if (stat.availableIncomingBitrate != void 0) {
|
|
1244
|
+
availableIncomingBitrate = stat.availableIncomingBitrate;
|
|
1245
|
+
}
|
|
1246
|
+
const localCandidate = report.get(stat.localCandidateId);
|
|
1247
|
+
if (localCandidate == null ? void 0 : localCandidate.candidateType) {
|
|
1248
|
+
candidateType = localCandidate.candidateType;
|
|
1249
|
+
}
|
|
1250
|
+
const timeDiff = lastCandPairTimestamp !== void 0 ? stat.timestamp - lastCandPairTimestamp : 0;
|
|
1251
|
+
if (stat.bytesReceived !== void 0) {
|
|
1252
|
+
if (lastBytesReceived !== void 0 && timeDiff > 0) {
|
|
1253
|
+
incomingBitrate = (stat.bytesReceived - lastBytesReceived) * 8 / timeDiff * 1e3;
|
|
1254
|
+
}
|
|
1255
|
+
lastBytesReceived = stat.bytesReceived;
|
|
1256
|
+
}
|
|
1257
|
+
if (stat.bytesSent !== void 0) {
|
|
1258
|
+
if (lastBytesSent !== void 0 && timeDiff > 0) {
|
|
1259
|
+
outgoingBitrate = (stat.bytesSent - lastBytesSent) * 8 / timeDiff * 1e3;
|
|
1260
|
+
}
|
|
1261
|
+
lastBytesSent = stat.bytesSent;
|
|
1262
|
+
}
|
|
1263
|
+
lastCandPairTimestamp = stat.timestamp;
|
|
864
1264
|
}
|
|
865
|
-
if (
|
|
866
|
-
|
|
1265
|
+
if (videoInboundRtpId === void 0 && stat.type === "inbound-rtp" && stat.kind === "video") {
|
|
1266
|
+
videoInboundRtpId = stat.id;
|
|
1267
|
+
if (stat.framesPerSecond !== void 0) {
|
|
1268
|
+
framesPerSecond = stat.framesPerSecond;
|
|
1269
|
+
}
|
|
1270
|
+
if (stat.jitter !== void 0) {
|
|
1271
|
+
jitter = stat.jitter;
|
|
1272
|
+
}
|
|
1273
|
+
if (stat.packetsReceived !== void 0 && stat.packetsLost !== void 0 && stat.packetsReceived + stat.packetsLost > 0) {
|
|
1274
|
+
packetLossRatio = stat.packetsLost / (stat.packetsReceived + stat.packetsLost);
|
|
1275
|
+
}
|
|
867
1276
|
}
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
framesPerSecond,
|
|
882
|
-
packetLossRatio,
|
|
883
|
-
jitter,
|
|
884
|
-
timestamp: Date.now()
|
|
1277
|
+
});
|
|
1278
|
+
return {
|
|
1279
|
+
rtt,
|
|
1280
|
+
candidateType,
|
|
1281
|
+
availableIncomingBitrate,
|
|
1282
|
+
availableOutgoingBitrate,
|
|
1283
|
+
incomingBitrate,
|
|
1284
|
+
outgoingBitrate,
|
|
1285
|
+
framesPerSecond,
|
|
1286
|
+
packetLossRatio,
|
|
1287
|
+
jitter,
|
|
1288
|
+
timestamp: Date.now()
|
|
1289
|
+
};
|
|
885
1290
|
};
|
|
886
1291
|
}
|
|
887
1292
|
|
|
@@ -1312,11 +1717,12 @@ var WebRTCTransportClient = class {
|
|
|
1312
1717
|
}
|
|
1313
1718
|
startStatsPolling() {
|
|
1314
1719
|
this.stopStatsPolling();
|
|
1720
|
+
const statsExtractor = createRTCStatsExtractor();
|
|
1315
1721
|
this.statsInterval = setInterval(() => __async(this, null, function* () {
|
|
1316
1722
|
if (!this.peerConnection) return;
|
|
1317
1723
|
try {
|
|
1318
1724
|
const report = yield this.peerConnection.getStats();
|
|
1319
|
-
this.stats =
|
|
1725
|
+
this.stats = statsExtractor(report);
|
|
1320
1726
|
this.emit("statsUpdate", this.stats);
|
|
1321
1727
|
} catch (e) {
|
|
1322
1728
|
}
|