@whereby.com/media 1.32.1 → 2.0.0

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.cjs CHANGED
@@ -9,17 +9,6 @@ var ipAddress = require('ip-address');
9
9
  var checkIp = require('check-ip');
10
10
  var validate = require('uuid-validate');
11
11
  var mediasoupClient = require('mediasoup-client');
12
- var uaParserJs = require('ua-parser-js');
13
- var Logger_js = require('mediasoup-client/lib/Logger.js');
14
- var utils = require('mediasoup-client/lib/utils.js');
15
- var ortc = require('mediasoup-client/lib/ortc.js');
16
- var sdpCommonUtils = require('mediasoup-client/lib/handlers/sdp/commonUtils.js');
17
- var ortcUtils = require('mediasoup-client/lib/handlers/ortc/utils.js');
18
- var errors_js = require('mediasoup-client/lib/errors.js');
19
- var HandlerInterface_js = require('mediasoup-client/lib/handlers/HandlerInterface.js');
20
- var RemoteSdp_js = require('mediasoup-client/lib/handlers/sdp/RemoteSdp.js');
21
- var scalabilityModes_js = require('mediasoup-client/lib/scalabilityModes.js');
22
- var Safari12_js = require('mediasoup-client/lib/handlers/Safari12.js');
23
12
  var EventEmitter = require('events');
24
13
  var socket_ioClient = require('socket.io-client');
25
14
 
@@ -41,10 +30,6 @@ function _interopNamespaceDefault(e) {
41
30
  }
42
31
 
43
32
  var sdpTransform__namespace = /*#__PURE__*/_interopNamespaceDefault(sdpTransform);
44
- var utils__namespace = /*#__PURE__*/_interopNamespaceDefault(utils);
45
- var ortc__namespace = /*#__PURE__*/_interopNamespaceDefault(ortc);
46
- var sdpCommonUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(sdpCommonUtils);
47
- var ortcUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(ortcUtils);
48
33
 
49
34
  const debugOn = process.env.NODE_ENV === "development" || new URLSearchParams(window.location.search).has("debug");
50
35
  class Logger {
@@ -867,7 +852,7 @@ function subscribeStats(subscription, options = OPTIONS, state = STATE) {
867
852
 
868
853
  var _a$6;
869
854
  const adapter$6 = (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
870
- const logger$b = new Logger();
855
+ const logger$a = new Logger();
871
856
  const browserName$2 = adapter$6.browserDetails.browser;
872
857
  const browserVersion$1 = adapter$6.browserDetails.version;
873
858
  function setCodecPreferenceSDP(sdp, redOn) {
@@ -908,7 +893,7 @@ function setCodecPreferenceSDP(sdp, redOn) {
908
893
  return newSdp;
909
894
  }
910
895
  catch (error) {
911
- logger$b.error("setCodecPreferenceSDP error:", error);
896
+ logger$a.error("setCodecPreferenceSDP error:", error);
912
897
  }
913
898
  }
914
899
  function cleanSdp(sdp) {
@@ -1094,7 +1079,7 @@ function setVideoBandwidthUsingSetParameters(pc, bandwidth, logger = console) {
1094
1079
 
1095
1080
  var _a$5;
1096
1081
  const adapter$5 = (_a$5 = adapterRaw.default) !== null && _a$5 !== void 0 ? _a$5 : adapterRaw;
1097
- const logger$a = new Logger();
1082
+ const logger$9 = new Logger();
1098
1083
  class Session {
1099
1084
  constructor({ peerConnectionId, bandwidth, deprioritizeH264Encoding, }) {
1100
1085
  this.peerConnectionId = peerConnectionId;
@@ -1238,7 +1223,7 @@ class Session {
1238
1223
  return this._setRemoteDescription(desc).then(() => {
1239
1224
  return setVideoBandwidthUsingSetParameters(this.pc, this.bandwidth);
1240
1225
  }, (e) => {
1241
- logger$a.warn("Could not set remote description from remote answer: ", e);
1226
+ logger$9.warn("Could not set remote description from remote answer: ", e);
1242
1227
  });
1243
1228
  }
1244
1229
  addIceCandidate(candidate) {
@@ -1254,7 +1239,7 @@ class Session {
1254
1239
  return;
1255
1240
  }
1256
1241
  this.pc.addIceCandidate(candidate).catch((e) => {
1257
- logger$a.warn("Failed to add ICE candidate ('%s'): %s", candidate ? candidate.candidate : null, e);
1242
+ logger$9.warn("Failed to add ICE candidate ('%s'): %s", candidate ? candidate.candidate : null, e);
1258
1243
  });
1259
1244
  });
1260
1245
  }
@@ -1273,7 +1258,7 @@ class Session {
1273
1258
  pc.close();
1274
1259
  }
1275
1260
  catch (e) {
1276
- logger$a.warn("failures during close of session", e);
1261
+ logger$9.warn("failures during close of session", e);
1277
1262
  }
1278
1263
  }
1279
1264
  hasConnectedPeerConnection() {
@@ -1774,694 +1759,17 @@ const generateByteString = (count) => {
1774
1759
  return result + result.substring(0, count - result.length);
1775
1760
  };
1776
1761
 
1777
- const logger$9 = new Logger_js.Logger("Safari17");
1778
- const NAME = "Safari17";
1779
- const SCTP_NUM_STREAMS = { OS: 1024, MIS: 1024 };
1780
- class Safari17 extends HandlerInterface_js.HandlerInterface {
1781
- static createFactory() {
1782
- return () => new Safari17();
1783
- }
1784
- constructor() {
1785
- super();
1786
- this._closed = false;
1787
- this._mapMidTransceiver = new Map();
1788
- this._sendStream = new MediaStream();
1789
- this._hasDataChannelMediaSection = false;
1790
- this._nextSendSctpStreamId = 0;
1791
- this._transportReady = false;
1792
- }
1793
- get name() {
1794
- return NAME;
1795
- }
1796
- close() {
1797
- logger$9.debug("close()");
1798
- if (this._closed) {
1799
- return;
1800
- }
1801
- this._closed = true;
1802
- if (this._pc) {
1803
- try {
1804
- this._pc.close();
1805
- }
1806
- catch (error) { }
1807
- }
1808
- this.emit("@close");
1809
- }
1810
- getNativeRtpCapabilities() {
1811
- return __awaiter(this, void 0, void 0, function* () {
1812
- logger$9.debug("getNativeRtpCapabilities()");
1813
- const pc = new RTCPeerConnection({
1814
- iceServers: [],
1815
- iceTransportPolicy: "all",
1816
- bundlePolicy: "max-bundle",
1817
- rtcpMuxPolicy: "require",
1818
- });
1819
- try {
1820
- pc.addTransceiver("audio");
1821
- pc.addTransceiver("video");
1822
- const offer = yield pc.createOffer();
1823
- try {
1824
- pc.close();
1825
- }
1826
- catch (error) { }
1827
- const sdpObject = sdpTransform__namespace.parse(offer.sdp);
1828
- const nativeRtpCapabilities = sdpCommonUtils__namespace.extractRtpCapabilities({
1829
- sdpObject,
1830
- });
1831
- ortcUtils__namespace.addNackSuppportForOpus(nativeRtpCapabilities);
1832
- return nativeRtpCapabilities;
1833
- }
1834
- catch (error) {
1835
- try {
1836
- pc.close();
1837
- }
1838
- catch (error2) { }
1839
- throw error;
1840
- }
1841
- });
1842
- }
1843
- getNativeSctpCapabilities() {
1844
- return __awaiter(this, void 0, void 0, function* () {
1845
- logger$9.debug("getNativeSctpCapabilities()");
1846
- return {
1847
- numStreams: SCTP_NUM_STREAMS,
1848
- };
1849
- });
1850
- }
1851
- run({ direction, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, extendedRtpCapabilities, }) {
1852
- this.assertNotClosed();
1853
- logger$9.debug("run()");
1854
- this._direction = direction;
1855
- this._remoteSdp = new RemoteSdp_js.RemoteSdp({
1856
- iceParameters,
1857
- iceCandidates,
1858
- dtlsParameters,
1859
- sctpParameters,
1860
- });
1861
- this._sendingRtpParametersByKind = {
1862
- audio: ortc__namespace.getSendingRtpParameters("audio", extendedRtpCapabilities),
1863
- video: ortc__namespace.getSendingRtpParameters("video", extendedRtpCapabilities),
1864
- };
1865
- this._sendingRemoteRtpParametersByKind = {
1866
- audio: ortc__namespace.getSendingRemoteRtpParameters("audio", extendedRtpCapabilities),
1867
- video: ortc__namespace.getSendingRemoteRtpParameters("video", extendedRtpCapabilities),
1868
- };
1869
- if (dtlsParameters.role && dtlsParameters.role !== "auto") {
1870
- this._forcedLocalDtlsRole = dtlsParameters.role === "server" ? "client" : "server";
1871
- }
1872
- this._pc = new RTCPeerConnection(Object.assign({ iceServers: iceServers !== null && iceServers !== void 0 ? iceServers : [], iceTransportPolicy: iceTransportPolicy !== null && iceTransportPolicy !== void 0 ? iceTransportPolicy : "all", bundlePolicy: "max-bundle", rtcpMuxPolicy: "require" }, additionalSettings), proprietaryConstraints);
1873
- this._pc.addEventListener("icegatheringstatechange", () => {
1874
- this.emit("@icegatheringstatechange", this._pc.iceGatheringState);
1875
- });
1876
- if (this._pc.connectionState) {
1877
- this._pc.addEventListener("connectionstatechange", () => {
1878
- this.emit("@connectionstatechange", this._pc.connectionState);
1879
- });
1880
- }
1881
- else {
1882
- this._pc.addEventListener("iceconnectionstatechange", () => {
1883
- logger$9.warn("run() | pc.connectionState not supported, using pc.iceConnectionState");
1884
- switch (this._pc.iceConnectionState) {
1885
- case "checking": {
1886
- this.emit("@connectionstatechange", "connecting");
1887
- break;
1888
- }
1889
- case "connected":
1890
- case "completed": {
1891
- this.emit("@connectionstatechange", "connected");
1892
- break;
1893
- }
1894
- case "failed": {
1895
- this.emit("@connectionstatechange", "failed");
1896
- break;
1897
- }
1898
- case "disconnected": {
1899
- this.emit("@connectionstatechange", "disconnected");
1900
- break;
1901
- }
1902
- case "closed": {
1903
- this.emit("@connectionstatechange", "closed");
1904
- break;
1905
- }
1906
- }
1907
- });
1908
- }
1909
- }
1910
- updateIceServers(iceServers) {
1911
- return __awaiter(this, void 0, void 0, function* () {
1912
- this.assertNotClosed();
1913
- logger$9.debug("updateIceServers()");
1914
- const configuration = this._pc.getConfiguration();
1915
- configuration.iceServers = iceServers;
1916
- this._pc.setConfiguration(configuration);
1917
- });
1918
- }
1919
- restartIce(iceParameters) {
1920
- return __awaiter(this, void 0, void 0, function* () {
1921
- this.assertNotClosed();
1922
- logger$9.debug("restartIce()");
1923
- this._remoteSdp.updateIceParameters(iceParameters);
1924
- if (!this._transportReady) {
1925
- return;
1926
- }
1927
- if (this._direction === "send") {
1928
- const offer = yield this._pc.createOffer({ iceRestart: true });
1929
- logger$9.debug("restartIce() | calling pc.setLocalDescription() [offer:%o]", offer);
1930
- yield this._pc.setLocalDescription(offer);
1931
- const answer = { type: "answer", sdp: this._remoteSdp.getSdp() };
1932
- logger$9.debug("restartIce() | calling pc.setRemoteDescription() [answer:%o]", answer);
1933
- yield this._pc.setRemoteDescription(answer);
1934
- }
1935
- else {
1936
- const offer = { type: "offer", sdp: this._remoteSdp.getSdp() };
1937
- logger$9.debug("restartIce() | calling pc.setRemoteDescription() [offer:%o]", offer);
1938
- yield this._pc.setRemoteDescription(offer);
1939
- const answer = yield this._pc.createAnswer();
1940
- logger$9.debug("restartIce() | calling pc.setLocalDescription() [answer:%o]", answer);
1941
- yield this._pc.setLocalDescription(answer);
1942
- }
1943
- });
1944
- }
1945
- getTransportStats() {
1946
- return __awaiter(this, void 0, void 0, function* () {
1947
- this.assertNotClosed();
1948
- return this._pc.getStats();
1949
- });
1950
- }
1951
- send(_a) {
1952
- return __awaiter(this, arguments, void 0, function* ({ track, encodings, codecOptions, codec, onRtpSender }) {
1953
- var _b;
1954
- this.assertNotClosed();
1955
- this.assertSendDirection();
1956
- logger$9.debug("send() [kind:%s, track.id:%s]", track.kind, track.id);
1957
- const sendingRtpParameters = utils__namespace.clone(this._sendingRtpParametersByKind[track.kind]);
1958
- sendingRtpParameters.codecs = ortc__namespace.reduceCodecs(sendingRtpParameters.codecs, codec);
1959
- if (encodings && encodings.length > 1 && encodings.every(({ rid }) => !rid)) {
1960
- encodings = encodings.map((e, i) => {
1961
- e.rid = `r${i}`;
1962
- return e;
1963
- });
1964
- }
1965
- if (encodings) {
1966
- if (!sendingRtpParameters.encodings) {
1967
- sendingRtpParameters.encodings = [];
1968
- }
1969
- Object.assign(sendingRtpParameters.encodings, encodings);
1970
- }
1971
- const layers = scalabilityModes_js.parse((encodings !== null && encodings !== void 0 ? encodings : [{}])[0].scalabilityMode);
1972
- if (sendingRtpParameters.encodings &&
1973
- sendingRtpParameters.encodings.length > 1 &&
1974
- (sendingRtpParameters.codecs[0].mimeType.toLowerCase() === "video/vp8" ||
1975
- sendingRtpParameters.codecs[0].mimeType.toLowerCase() === "video/h264")) {
1976
- for (const encoding of sendingRtpParameters.encodings) {
1977
- if (encoding.scalabilityMode) {
1978
- encoding.scalabilityMode = `L1T${layers.temporalLayers}`;
1979
- }
1980
- else {
1981
- encoding.scalabilityMode = "L1T3";
1982
- }
1983
- }
1984
- }
1985
- const sendingRemoteRtpParameters = utils__namespace.clone(this._sendingRemoteRtpParametersByKind[track.kind]);
1986
- sendingRemoteRtpParameters.codecs = ortc__namespace.reduceCodecs(sendingRemoteRtpParameters.codecs, codec);
1987
- const mediaSectionIdx = this._remoteSdp.getNextMediaSectionIdx();
1988
- const transceiver = this._pc.addTransceiver(track, {
1989
- direction: "sendonly",
1990
- streams: [this._sendStream],
1991
- sendEncodings: track.kind === "video" ? encodings : undefined,
1992
- });
1993
- if (onRtpSender) {
1994
- onRtpSender(transceiver.sender);
1995
- }
1996
- const offer = yield this._pc.createOffer();
1997
- const localSdpObject = sdpTransform__namespace.parse(offer.sdp);
1998
- let offerMediaObject = localSdpObject.media[mediaSectionIdx.idx];
1999
- if (!this._transportReady) {
2000
- yield this.setupTransport({
2001
- localDtlsRole: (_b = this._forcedLocalDtlsRole) !== null && _b !== void 0 ? _b : "client",
2002
- localSdpObject,
2003
- });
2004
- }
2005
- logger$9.debug("send() | calling pc.setLocalDescription() [offer:%o]", offer);
2006
- yield this._pc.setLocalDescription(offer);
2007
- const localId = transceiver.mid;
2008
- sendingRtpParameters.mid = localId;
2009
- offerMediaObject = localSdpObject.media[mediaSectionIdx.idx];
2010
- sendingRtpParameters.rtcp.cname = sdpCommonUtils__namespace.getCname({
2011
- offerMediaObject,
2012
- });
2013
- this._remoteSdp.send({
2014
- offerMediaObject,
2015
- reuseMid: mediaSectionIdx.reuseMid,
2016
- offerRtpParameters: sendingRtpParameters,
2017
- answerRtpParameters: sendingRemoteRtpParameters,
2018
- codecOptions,
2019
- });
2020
- const answer = { type: "answer", sdp: this._remoteSdp.getSdp() };
2021
- logger$9.debug("send() | calling pc.setRemoteDescription() [answer:%o]", answer);
2022
- yield this._pc.setRemoteDescription(answer);
2023
- this._mapMidTransceiver.set(localId, transceiver);
2024
- return {
2025
- localId,
2026
- rtpParameters: sendingRtpParameters,
2027
- rtpSender: transceiver.sender,
2028
- };
2029
- });
2030
- }
2031
- stopSending(localId) {
2032
- return __awaiter(this, void 0, void 0, function* () {
2033
- this.assertSendDirection();
2034
- if (this._closed) {
2035
- return;
2036
- }
2037
- logger$9.debug("stopSending() [localId:%s]", localId);
2038
- const transceiver = this._mapMidTransceiver.get(localId);
2039
- if (!transceiver) {
2040
- throw new Error("associated RTCRtpTransceiver not found");
2041
- }
2042
- void transceiver.sender.replaceTrack(null);
2043
- this._pc.removeTrack(transceiver.sender);
2044
- const mediaSectionClosed = this._remoteSdp.closeMediaSection(transceiver.mid);
2045
- if (mediaSectionClosed) {
2046
- try {
2047
- transceiver.stop();
2048
- }
2049
- catch (error) { }
2050
- }
2051
- const offer = yield this._pc.createOffer();
2052
- logger$9.debug("stopSending() | calling pc.setLocalDescription() [offer:%o]", offer);
2053
- yield this._pc.setLocalDescription(offer);
2054
- const answer = { type: "answer", sdp: this._remoteSdp.getSdp() };
2055
- logger$9.debug("stopSending() | calling pc.setRemoteDescription() [answer:%o]", answer);
2056
- yield this._pc.setRemoteDescription(answer);
2057
- this._mapMidTransceiver.delete(localId);
2058
- });
2059
- }
2060
- pauseSending(localId) {
2061
- return __awaiter(this, void 0, void 0, function* () {
2062
- this.assertNotClosed();
2063
- this.assertSendDirection();
2064
- logger$9.debug("pauseSending() [localId:%s]", localId);
2065
- const transceiver = this._mapMidTransceiver.get(localId);
2066
- if (!transceiver) {
2067
- throw new Error("associated RTCRtpTransceiver not found");
2068
- }
2069
- transceiver.direction = "inactive";
2070
- this._remoteSdp.pauseMediaSection(localId);
2071
- const offer = yield this._pc.createOffer();
2072
- logger$9.debug("pauseSending() | calling pc.setLocalDescription() [offer:%o]", offer);
2073
- yield this._pc.setLocalDescription(offer);
2074
- const answer = { type: "answer", sdp: this._remoteSdp.getSdp() };
2075
- logger$9.debug("pauseSending() | calling pc.setRemoteDescription() [answer:%o]", answer);
2076
- yield this._pc.setRemoteDescription(answer);
2077
- });
2078
- }
2079
- resumeSending(localId) {
2080
- return __awaiter(this, void 0, void 0, function* () {
2081
- this.assertNotClosed();
2082
- this.assertSendDirection();
2083
- logger$9.debug("resumeSending() [localId:%s]", localId);
2084
- const transceiver = this._mapMidTransceiver.get(localId);
2085
- if (!transceiver) {
2086
- throw new Error("associated RTCRtpTransceiver not found");
2087
- }
2088
- transceiver.direction = "sendonly";
2089
- this._remoteSdp.resumeSendingMediaSection(localId);
2090
- const offer = yield this._pc.createOffer();
2091
- logger$9.debug("resumeSending() | calling pc.setLocalDescription() [offer:%o]", offer);
2092
- yield this._pc.setLocalDescription(offer);
2093
- const answer = { type: "answer", sdp: this._remoteSdp.getSdp() };
2094
- logger$9.debug("resumeSending() | calling pc.setRemoteDescription() [answer:%o]", answer);
2095
- yield this._pc.setRemoteDescription(answer);
2096
- });
2097
- }
2098
- replaceTrack(localId, track) {
2099
- return __awaiter(this, void 0, void 0, function* () {
2100
- this.assertNotClosed();
2101
- this.assertSendDirection();
2102
- if (track) {
2103
- logger$9.debug("replaceTrack() [localId:%s, track.id:%s]", localId, track.id);
2104
- }
2105
- else {
2106
- logger$9.debug("replaceTrack() [localId:%s, no track]", localId);
2107
- }
2108
- const transceiver = this._mapMidTransceiver.get(localId);
2109
- if (!transceiver) {
2110
- throw new Error("associated RTCRtpTransceiver not found");
2111
- }
2112
- yield transceiver.sender.replaceTrack(track);
2113
- });
2114
- }
2115
- setMaxSpatialLayer(localId, spatialLayer) {
2116
- return __awaiter(this, void 0, void 0, function* () {
2117
- this.assertNotClosed();
2118
- this.assertSendDirection();
2119
- logger$9.debug("setMaxSpatialLayer() [localId:%s, spatialLayer:%s]", localId, spatialLayer);
2120
- const transceiver = this._mapMidTransceiver.get(localId);
2121
- if (!transceiver) {
2122
- throw new Error("associated RTCRtpTransceiver not found");
2123
- }
2124
- const parameters = transceiver.sender.getParameters();
2125
- parameters.encodings.forEach((encoding, idx) => {
2126
- if (idx <= spatialLayer) {
2127
- encoding.active = true;
2128
- }
2129
- else {
2130
- encoding.active = false;
2131
- }
2132
- });
2133
- yield transceiver.sender.setParameters(parameters);
2134
- this._remoteSdp.muxMediaSectionSimulcast(localId, parameters.encodings);
2135
- const offer = yield this._pc.createOffer();
2136
- logger$9.debug("setMaxSpatialLayer() | calling pc.setLocalDescription() [offer:%o]", offer);
2137
- yield this._pc.setLocalDescription(offer);
2138
- const answer = { type: "answer", sdp: this._remoteSdp.getSdp() };
2139
- logger$9.debug("setMaxSpatialLayer() | calling pc.setRemoteDescription() [answer:%o]", answer);
2140
- yield this._pc.setRemoteDescription(answer);
2141
- });
2142
- }
2143
- setRtpEncodingParameters(localId, params) {
2144
- return __awaiter(this, void 0, void 0, function* () {
2145
- this.assertNotClosed();
2146
- this.assertSendDirection();
2147
- logger$9.debug("setRtpEncodingParameters() [localId:%s, params:%o]", localId, params);
2148
- const transceiver = this._mapMidTransceiver.get(localId);
2149
- if (!transceiver) {
2150
- throw new Error("associated RTCRtpTransceiver not found");
2151
- }
2152
- const parameters = transceiver.sender.getParameters();
2153
- parameters.encodings.forEach((encoding, idx) => {
2154
- parameters.encodings[idx] = Object.assign(Object.assign({}, encoding), params);
2155
- });
2156
- yield transceiver.sender.setParameters(parameters);
2157
- this._remoteSdp.muxMediaSectionSimulcast(localId, parameters.encodings);
2158
- const offer = yield this._pc.createOffer();
2159
- logger$9.debug("setRtpEncodingParameters() | calling pc.setLocalDescription() [offer:%o]", offer);
2160
- yield this._pc.setLocalDescription(offer);
2161
- const answer = { type: "answer", sdp: this._remoteSdp.getSdp() };
2162
- logger$9.debug("setRtpEncodingParameters() | calling pc.setRemoteDescription() [answer:%o]", answer);
2163
- yield this._pc.setRemoteDescription(answer);
2164
- });
2165
- }
2166
- getSenderStats(localId) {
2167
- return __awaiter(this, void 0, void 0, function* () {
2168
- this.assertNotClosed();
2169
- this.assertSendDirection();
2170
- const transceiver = this._mapMidTransceiver.get(localId);
2171
- if (!transceiver) {
2172
- throw new Error("associated RTCRtpTransceiver not found");
2173
- }
2174
- return transceiver.sender.getStats();
2175
- });
2176
- }
2177
- sendDataChannel(_a) {
2178
- return __awaiter(this, arguments, void 0, function* ({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol, }) {
2179
- var _b;
2180
- this.assertNotClosed();
2181
- this.assertSendDirection();
2182
- const options = {
2183
- negotiated: true,
2184
- id: this._nextSendSctpStreamId,
2185
- ordered,
2186
- maxPacketLifeTime,
2187
- maxRetransmits,
2188
- protocol,
2189
- };
2190
- logger$9.debug("sendDataChannel() [options:%o]", options);
2191
- const dataChannel = this._pc.createDataChannel(label, options);
2192
- this._nextSendSctpStreamId = ++this._nextSendSctpStreamId % SCTP_NUM_STREAMS.MIS;
2193
- if (!this._hasDataChannelMediaSection) {
2194
- const offer = yield this._pc.createOffer();
2195
- const localSdpObject = sdpTransform__namespace.parse(offer.sdp);
2196
- const offerMediaObject = localSdpObject.media.find((m) => m.type === "application");
2197
- if (!this._transportReady) {
2198
- yield this.setupTransport({
2199
- localDtlsRole: (_b = this._forcedLocalDtlsRole) !== null && _b !== void 0 ? _b : "client",
2200
- localSdpObject,
2201
- });
2202
- }
2203
- logger$9.debug("sendDataChannel() | calling pc.setLocalDescription() [offer:%o]", offer);
2204
- yield this._pc.setLocalDescription(offer);
2205
- this._remoteSdp.sendSctpAssociation({ offerMediaObject });
2206
- const answer = { type: "answer", sdp: this._remoteSdp.getSdp() };
2207
- logger$9.debug("sendDataChannel() | calling pc.setRemoteDescription() [answer:%o]", answer);
2208
- yield this._pc.setRemoteDescription(answer);
2209
- this._hasDataChannelMediaSection = true;
2210
- }
2211
- const sctpStreamParameters = {
2212
- streamId: options.id,
2213
- ordered: options.ordered,
2214
- maxPacketLifeTime: options.maxPacketLifeTime,
2215
- maxRetransmits: options.maxRetransmits,
2216
- };
2217
- return { dataChannel, sctpStreamParameters };
2218
- });
2219
- }
2220
- receive(optionsList) {
2221
- return __awaiter(this, void 0, void 0, function* () {
2222
- var _a, _b;
2223
- this.assertNotClosed();
2224
- this.assertRecvDirection();
2225
- const results = [];
2226
- const mapLocalId = new Map();
2227
- for (const options of optionsList) {
2228
- const { trackId, kind, rtpParameters, streamId } = options;
2229
- logger$9.debug("receive() [trackId:%s, kind:%s]", trackId, kind);
2230
- const localId = (_a = rtpParameters.mid) !== null && _a !== void 0 ? _a : String(this._mapMidTransceiver.size);
2231
- mapLocalId.set(trackId, localId);
2232
- this._remoteSdp.receive({
2233
- mid: localId,
2234
- kind,
2235
- offerRtpParameters: rtpParameters,
2236
- streamId: streamId !== null && streamId !== void 0 ? streamId : rtpParameters.rtcp.cname,
2237
- trackId,
2238
- });
2239
- }
2240
- const offer = { type: "offer", sdp: this._remoteSdp.getSdp() };
2241
- logger$9.debug("receive() | calling pc.setRemoteDescription() [offer:%o]", offer);
2242
- yield this._pc.setRemoteDescription(offer);
2243
- for (const options of optionsList) {
2244
- const { trackId, onRtpReceiver } = options;
2245
- if (onRtpReceiver) {
2246
- const localId = mapLocalId.get(trackId);
2247
- const transceiver = this._pc.getTransceivers().find((t) => t.mid === localId);
2248
- if (!transceiver) {
2249
- throw new Error("transceiver not found");
2250
- }
2251
- onRtpReceiver(transceiver.receiver);
2252
- }
2253
- }
2254
- let answer = yield this._pc.createAnswer();
2255
- const localSdpObject = sdpTransform__namespace.parse(answer.sdp);
2256
- for (const options of optionsList) {
2257
- const { trackId, rtpParameters } = options;
2258
- const localId = mapLocalId.get(trackId);
2259
- const answerMediaObject = localSdpObject.media.find((m) => String(m.mid) === localId);
2260
- sdpCommonUtils__namespace.applyCodecParameters({
2261
- offerRtpParameters: rtpParameters,
2262
- answerMediaObject,
2263
- });
2264
- }
2265
- answer = { type: "answer", sdp: sdpTransform__namespace.write(localSdpObject) };
2266
- if (!this._transportReady) {
2267
- yield this.setupTransport({
2268
- localDtlsRole: (_b = this._forcedLocalDtlsRole) !== null && _b !== void 0 ? _b : "client",
2269
- localSdpObject,
2270
- });
2271
- }
2272
- logger$9.debug("receive() | calling pc.setLocalDescription() [answer:%o]", answer);
2273
- yield this._pc.setLocalDescription(answer);
2274
- for (const options of optionsList) {
2275
- const { trackId } = options;
2276
- const localId = mapLocalId.get(trackId);
2277
- const transceiver = this._pc.getTransceivers().find((t) => t.mid === localId);
2278
- if (!transceiver) {
2279
- throw new Error("new RTCRtpTransceiver not found");
2280
- }
2281
- this._mapMidTransceiver.set(localId, transceiver);
2282
- results.push({
2283
- localId,
2284
- track: transceiver.receiver.track,
2285
- rtpReceiver: transceiver.receiver,
2286
- });
2287
- }
2288
- return results;
2289
- });
2290
- }
2291
- stopReceiving(localIds) {
2292
- return __awaiter(this, void 0, void 0, function* () {
2293
- this.assertRecvDirection();
2294
- if (this._closed) {
2295
- return;
2296
- }
2297
- for (const localId of localIds) {
2298
- logger$9.debug("stopReceiving() [localId:%s]", localId);
2299
- const transceiver = this._mapMidTransceiver.get(localId);
2300
- if (!transceiver) {
2301
- throw new Error("associated RTCRtpTransceiver not found");
2302
- }
2303
- this._remoteSdp.closeMediaSection(transceiver.mid);
2304
- }
2305
- const offer = { type: "offer", sdp: this._remoteSdp.getSdp() };
2306
- logger$9.debug("stopReceiving() | calling pc.setRemoteDescription() [offer:%o]", offer);
2307
- yield this._pc.setRemoteDescription(offer);
2308
- const answer = yield this._pc.createAnswer();
2309
- logger$9.debug("stopReceiving() | calling pc.setLocalDescription() [answer:%o]", answer);
2310
- yield this._pc.setLocalDescription(answer);
2311
- for (const localId of localIds) {
2312
- this._mapMidTransceiver.delete(localId);
2313
- }
2314
- });
2315
- }
2316
- pauseReceiving(localIds) {
2317
- return __awaiter(this, void 0, void 0, function* () {
2318
- this.assertNotClosed();
2319
- this.assertRecvDirection();
2320
- for (const localId of localIds) {
2321
- logger$9.debug("pauseReceiving() [localId:%s]", localId);
2322
- const transceiver = this._mapMidTransceiver.get(localId);
2323
- if (!transceiver) {
2324
- throw new Error("associated RTCRtpTransceiver not found");
2325
- }
2326
- transceiver.direction = "inactive";
2327
- this._remoteSdp.pauseMediaSection(localId);
2328
- }
2329
- const offer = { type: "offer", sdp: this._remoteSdp.getSdp() };
2330
- logger$9.debug("pauseReceiving() | calling pc.setRemoteDescription() [offer:%o]", offer);
2331
- yield this._pc.setRemoteDescription(offer);
2332
- const answer = yield this._pc.createAnswer();
2333
- logger$9.debug("pauseReceiving() | calling pc.setLocalDescription() [answer:%o]", answer);
2334
- yield this._pc.setLocalDescription(answer);
2335
- });
2336
- }
2337
- resumeReceiving(localIds) {
2338
- return __awaiter(this, void 0, void 0, function* () {
2339
- this.assertNotClosed();
2340
- this.assertRecvDirection();
2341
- for (const localId of localIds) {
2342
- logger$9.debug("resumeReceiving() [localId:%s]", localId);
2343
- const transceiver = this._mapMidTransceiver.get(localId);
2344
- if (!transceiver) {
2345
- throw new Error("associated RTCRtpTransceiver not found");
2346
- }
2347
- transceiver.direction = "recvonly";
2348
- this._remoteSdp.resumeReceivingMediaSection(localId);
2349
- }
2350
- const offer = { type: "offer", sdp: this._remoteSdp.getSdp() };
2351
- logger$9.debug("resumeReceiving() | calling pc.setRemoteDescription() [offer:%o]", offer);
2352
- yield this._pc.setRemoteDescription(offer);
2353
- const answer = yield this._pc.createAnswer();
2354
- logger$9.debug("resumeReceiving() | calling pc.setLocalDescription() [answer:%o]", answer);
2355
- yield this._pc.setLocalDescription(answer);
2356
- });
2357
- }
2358
- getReceiverStats(localId) {
2359
- return __awaiter(this, void 0, void 0, function* () {
2360
- this.assertNotClosed();
2361
- this.assertRecvDirection();
2362
- const transceiver = this._mapMidTransceiver.get(localId);
2363
- if (!transceiver) {
2364
- throw new Error("associated RTCRtpTransceiver not found");
2365
- }
2366
- return transceiver.receiver.getStats();
2367
- });
2368
- }
2369
- receiveDataChannel(_a) {
2370
- return __awaiter(this, arguments, void 0, function* ({ sctpStreamParameters, label, protocol, }) {
2371
- var _b;
2372
- this.assertNotClosed();
2373
- this.assertRecvDirection();
2374
- const { streamId, ordered, maxPacketLifeTime, maxRetransmits } = sctpStreamParameters;
2375
- const options = {
2376
- negotiated: true,
2377
- id: streamId,
2378
- ordered,
2379
- maxPacketLifeTime,
2380
- maxRetransmits,
2381
- protocol,
2382
- };
2383
- logger$9.debug("receiveDataChannel() [options:%o]", options);
2384
- const dataChannel = this._pc.createDataChannel(label, options);
2385
- if (!this._hasDataChannelMediaSection) {
2386
- this._remoteSdp.receiveSctpAssociation();
2387
- const offer = { type: "offer", sdp: this._remoteSdp.getSdp() };
2388
- logger$9.debug("receiveDataChannel() | calling pc.setRemoteDescription() [offer:%o]", offer);
2389
- yield this._pc.setRemoteDescription(offer);
2390
- const answer = yield this._pc.createAnswer();
2391
- if (!this._transportReady) {
2392
- const localSdpObject = sdpTransform__namespace.parse(answer.sdp);
2393
- yield this.setupTransport({
2394
- localDtlsRole: (_b = this._forcedLocalDtlsRole) !== null && _b !== void 0 ? _b : "client",
2395
- localSdpObject,
2396
- });
2397
- }
2398
- logger$9.debug("receiveDataChannel() | calling pc.setRemoteDescription() [answer:%o]", answer);
2399
- yield this._pc.setLocalDescription(answer);
2400
- this._hasDataChannelMediaSection = true;
2401
- }
2402
- return { dataChannel };
2403
- });
2404
- }
2405
- setupTransport(_a) {
2406
- return __awaiter(this, arguments, void 0, function* ({ localDtlsRole, localSdpObject, }) {
2407
- if (!localSdpObject) {
2408
- localSdpObject = sdpTransform__namespace.parse(this._pc.localDescription.sdp);
2409
- }
2410
- const dtlsParameters = sdpCommonUtils__namespace.extractDtlsParameters({
2411
- sdpObject: localSdpObject,
2412
- });
2413
- dtlsParameters.role = localDtlsRole;
2414
- this._remoteSdp.updateDtlsRole(localDtlsRole === "client" ? "server" : "client");
2415
- yield new Promise((resolve, reject) => {
2416
- this.safeEmit("@connect", { dtlsParameters }, resolve, reject);
2417
- });
2418
- this._transportReady = true;
2419
- });
2420
- }
2421
- assertNotClosed() {
2422
- if (this._closed) {
2423
- throw new errors_js.InvalidStateError("method called in a closed handler");
2424
- }
2425
- }
2426
- assertSendDirection() {
2427
- if (this._direction !== "send") {
2428
- throw new Error('method can just be called for handlers with "send" direction');
2429
- }
2430
- }
2431
- assertRecvDirection() {
2432
- if (this._direction !== "recv") {
2433
- throw new Error('method can just be called for handlers with "recv" direction');
2434
- }
2435
- }
2436
- }
2437
-
2438
- const getMediasoupDevice = (features) => {
2439
- var _a;
1762
+ const getMediasoupDeviceAsync = (features) => __awaiter(void 0, void 0, void 0, function* () {
2440
1763
  if (features.isNodeSdk) {
2441
- return new mediasoupClient.Device({ handlerFactory: Safari12_js.Safari12.createFactory() });
2442
- }
2443
- let handlerName = mediasoupClient.detectDevice() || (/applecoremedia|applewebkit|safari/i.test(navigator.userAgent) ? "Safari12" : undefined);
2444
- if (handlerName === "Safari12" && typeof navigator === "object" && typeof navigator.userAgent === "string") {
2445
- const uaParser = new uaParserJs.UAParser(navigator.userAgent);
2446
- const browser = uaParser.getBrowser();
2447
- const browserVersion = parseInt((_a = browser.major) !== null && _a !== void 0 ? _a : "0");
2448
- if (browserVersion >= 17 && features.safari17HandlerOn) {
2449
- handlerName = "Safari17";
2450
- }
1764
+ return new mediasoupClient.Device({ handlerName: "Safari12" });
2451
1765
  }
1766
+ let handlerName = (yield mediasoupClient.detectDeviceAsync()) ||
1767
+ (/applecoremedia|applewebkit|safari/i.test(navigator.userAgent) ? "Safari12" : undefined);
2452
1768
  if (/iphone|ipad/i.test(navigator.userAgent)) {
2453
- if (features.safari17HandlerOn) {
2454
- handlerName = "Safari17";
2455
- }
2456
- else {
2457
- handlerName = "Safari12";
2458
- }
2459
- }
2460
- if (handlerName === "Safari17") {
2461
- return new mediasoupClient.Device({ handlerFactory: Safari17.createFactory() });
1769
+ handlerName = "Safari12";
2462
1770
  }
2463
1771
  return new mediasoupClient.Device({ handlerName });
2464
- };
1772
+ });
2465
1773
 
2466
1774
  const AUDIO_SETTINGS = {
2467
1775
  codecOptions: {
@@ -2584,11 +1892,12 @@ function prioritizeRouterRtpCapabilitiesCodecs(codecs, preferredCodec) {
2584
1892
  return codecs;
2585
1893
  }
2586
1894
  return [...codecs].sort((left, right) => {
1895
+ var _a;
2587
1896
  if (left.mimeType.toLowerCase() === preferredCodec) {
2588
1897
  return -1;
2589
1898
  }
2590
1899
  if (left.mimeType.toLowerCase() === "video/rtx" &&
2591
- left.parameters.apt === preferredCodecEntry.preferredPayloadType) {
1900
+ ((_a = left.parameters) === null || _a === void 0 ? void 0 : _a.apt) === preferredCodecEntry.preferredPayloadType) {
2592
1901
  if (right.mimeType.toLowerCase() === preferredCodec) {
2593
1902
  return 1;
2594
1903
  }
@@ -4964,7 +4273,7 @@ class VegaRtcManager {
4964
4273
  this._vegaConnection = null;
4965
4274
  this._micAnalyser = null;
4966
4275
  this._micAnalyserDebugger = null;
4967
- this._mediasoupDevice = getMediasoupDevice(features);
4276
+ this._mediasoupDeviceInitializedAsync = getMediasoupDeviceAsync(features);
4968
4277
  this._routerRtpCapabilities = null;
4969
4278
  this._sendTransport = null;
4970
4279
  this._receiveTransport = null;
@@ -5081,7 +4390,7 @@ class VegaRtcManager {
5081
4390
  }
5082
4391
  if (this._screenVideoTrack)
5083
4392
  this._emitScreenshareStarted();
5084
- if (this._features.sfuReconnectV2On && this._reconnect) {
4393
+ if (this._reconnect) {
5085
4394
  this._connect();
5086
4395
  }
5087
4396
  }), this._serverSocket.on("connect", () => this._onNetworkIsDetectedUpBySignal()), this._serverSocket.onEngineEvent("packet", () => this._onNetworkIsDetectedUpBySignal()), this._serverSocket.on("disconnect", () => this._onNetworkIsDetectedPossiblyDownBySignal()));
@@ -5094,19 +4403,17 @@ class VegaRtcManager {
5094
4403
  });
5095
4404
  }
5096
4405
  _connect() {
5097
- if (this._features.sfuReconnectV2On) {
5098
- if (this._isConnectingOrConnected)
4406
+ if (this._isConnectingOrConnected)
4407
+ return;
4408
+ if (!this._serverSocket.isConnected()) {
4409
+ const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
4410
+ if (!reconnectThresholdInMs)
4411
+ return;
4412
+ if (Date.now() > (this._serverSocket.disconnectTimestamp || 0) + reconnectThresholdInMs)
5099
4413
  return;
5100
- if (!this._serverSocket.isConnected()) {
5101
- const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
5102
- if (!reconnectThresholdInMs)
5103
- return;
5104
- if (Date.now() > (this._serverSocket.disconnectTimestamp || 0) + reconnectThresholdInMs)
5105
- return;
5106
- }
5107
- if (this._reconnectTimeOut)
5108
- clearTimeout(this._reconnectTimeOut);
5109
4414
  }
4415
+ if (this._reconnectTimeOut)
4416
+ clearTimeout(this._reconnectTimeOut);
5110
4417
  if (!this._vegaConnectionManager) {
5111
4418
  const hostList = this._features.sfuServersOverride ||
5112
4419
  this._sfuServers ||
@@ -5168,10 +4475,10 @@ class VegaRtcManager {
5168
4475
  if (!this._routerRtpCapabilities) {
5169
4476
  const modifiedCapabilities = modifyMediaCapabilities(routerRtpCapabilities, Object.assign(Object.assign({}, this._features), { vp9On: this._features.sfuVp9On }));
5170
4477
  this._routerRtpCapabilities = modifiedCapabilities;
5171
- yield ((_a = this._mediasoupDevice) === null || _a === void 0 ? void 0 : _a.load({ routerRtpCapabilities: modifiedCapabilities }));
4478
+ yield ((_a = (yield this._mediasoupDeviceInitializedAsync)) === null || _a === void 0 ? void 0 : _a.load({ routerRtpCapabilities: modifiedCapabilities }));
5172
4479
  }
5173
4480
  this._vegaConnection.message("setCapabilities", {
5174
- rtpCapabilities: (_b = this._mediasoupDevice) === null || _b === void 0 ? void 0 : _b.rtpCapabilities,
4481
+ rtpCapabilities: (_b = (yield this._mediasoupDeviceInitializedAsync)) === null || _b === void 0 ? void 0 : _b.rtpCapabilities,
5175
4482
  });
5176
4483
  if (this._colocation)
5177
4484
  this._vegaConnection.message("setColocation", { colocation: this._colocation });
@@ -5214,7 +4521,7 @@ class VegaRtcManager {
5214
4521
  });
5215
4522
  transportOptions.iceServers = turnServerOverride(this._features.turnServersOn ? this._turnServers : this._iceServers, this._features.turnServerOverrideHost);
5216
4523
  maybeTurnOnly(transportOptions, this._features);
5217
- const transport = (_a = this._mediasoupDevice) === null || _a === void 0 ? void 0 : _a[creator](transportOptions);
4524
+ const transport = (_a = (yield this._mediasoupDeviceInitializedAsync)) === null || _a === void 0 ? void 0 : _a[creator](transportOptions);
5218
4525
  const onConnectionStateListener = (connectionState) => __awaiter(this, void 0, void 0, function* () {
5219
4526
  logger$3.info(`Transport ConnectionStateChanged ${connectionState}`);
5220
4527
  if (connectionState !== "disconnected" && connectionState !== "failed") {
@@ -6030,7 +5337,7 @@ class VegaRtcManager {
6030
5337
  this._screenVideoTrack = null;
6031
5338
  this._screenAudioTrack = null;
6032
5339
  this._streamIdToVideoConsumerId.clear();
6033
- this._mediasoupDevice = null;
5340
+ this._mediasoupDeviceInitializedAsync = Promise.resolve(null);
6034
5341
  }
6035
5342
  sendAudioMutedStats(muted) {
6036
5343
  rtcStats.sendEvent("audio_muted", { muted });
@@ -7195,7 +6502,7 @@ class BandwidthTester extends EventEmitter {
7195
6502
  this.closed = false;
7196
6503
  this._features = features || {};
7197
6504
  this._vegaConnection = null;
7198
- this._mediasoupDevice = getMediasoupDevice(this._features);
6505
+ this._mediasoupDeviceInitializedAsync = getMediasoupDeviceAsync(this._features);
7199
6506
  this._routerRtpCapabilities = null;
7200
6507
  this._sendTransport = null;
7201
6508
  this._receiveTransport = null;
@@ -7255,7 +6562,7 @@ class BandwidthTester extends EventEmitter {
7255
6562
  this._receiveTransport.close();
7256
6563
  }
7257
6564
  this._receiveTransport = null;
7258
- this._mediasoupDevice = null;
6565
+ this._mediasoupDeviceInitializedAsync = Promise.resolve(null);
7259
6566
  if (this._vegaConnection) {
7260
6567
  this._vegaConnection.removeAllListeners();
7261
6568
  this._vegaConnection.close();
@@ -7283,10 +6590,10 @@ class BandwidthTester extends EventEmitter {
7283
6590
  if (!this._routerRtpCapabilities) {
7284
6591
  const modifiedCapabilities = modifyMediaCapabilities(routerRtpCapabilities, Object.assign(Object.assign({}, this._features), { vp9On: this._features.sfuVp9On }));
7285
6592
  this._routerRtpCapabilities = modifiedCapabilities;
7286
- yield ((_a = this._mediasoupDevice) === null || _a === void 0 ? void 0 : _a.load({ routerRtpCapabilities: modifiedCapabilities }));
6593
+ yield ((_a = (yield this._mediasoupDeviceInitializedAsync)) === null || _a === void 0 ? void 0 : _a.load({ routerRtpCapabilities: modifiedCapabilities }));
7287
6594
  }
7288
6595
  this._vegaConnection.message("setCapabilities", {
7289
- rtpCapabilities: (_b = this._mediasoupDevice) === null || _b === void 0 ? void 0 : _b.rtpCapabilities,
6596
+ rtpCapabilities: (_b = (yield this._mediasoupDeviceInitializedAsync)) === null || _b === void 0 ? void 0 : _b.rtpCapabilities,
7290
6597
  });
7291
6598
  yield Promise.all([this._createTransport(true), this._createTransport(false)]);
7292
6599
  yield this._createProducer();
@@ -7328,7 +6635,7 @@ class BandwidthTester extends EventEmitter {
7328
6635
  preferUdp: true,
7329
6636
  });
7330
6637
  transportOptions.iceServers = [{ urls: "stun:any.turn.svc.whereby.com" }];
7331
- const transport = (_a = this._mediasoupDevice) === null || _a === void 0 ? void 0 : _a[creator](transportOptions);
6638
+ const transport = (_a = (yield this._mediasoupDeviceInitializedAsync)) === null || _a === void 0 ? void 0 : _a[creator](transportOptions);
7332
6639
  transport === null || transport === void 0 ? void 0 : transport.on("connect", ({ dtlsParameters }, callback) => {
7333
6640
  this._vegaConnection.message("connectTransport", {
7334
6641
  transportId: transport.id,
@@ -8007,7 +7314,7 @@ exports.getDisplayMedia = getDisplayMedia;
8007
7314
  exports.getIssuesAndMetrics = getIssuesAndMetrics;
8008
7315
  exports.getMediaConstraints = getMediaConstraints;
8009
7316
  exports.getMediaSettings = getMediaSettings;
8010
- exports.getMediasoupDevice = getMediasoupDevice;
7317
+ exports.getMediasoupDeviceAsync = getMediasoupDeviceAsync;
8011
7318
  exports.getNumFailedStatsReports = getNumFailedStatsReports;
8012
7319
  exports.getNumFailedTrackSsrcLookups = getNumFailedTrackSsrcLookups;
8013
7320
  exports.getNumMissingTrackSsrcLookups = getNumMissingTrackSsrcLookups;