@whereby.com/media 11.3.4 → 11.4.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
@@ -67,6 +67,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
67
67
  var _a$6;
68
68
  (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
69
69
  const RTCSTATS_PROTOCOL_VERSION = "1.0";
70
+ const POLICY_VIOLATION = 1008;
70
71
  const GETSTATS_BUFFER_SIZE = 20;
71
72
  const clientInfo = {
72
73
  id: uuid.v4(),
@@ -74,6 +75,13 @@ const clientInfo = {
74
75
  };
75
76
  const noop = () => { };
76
77
  let resetDelta = noop;
78
+ let roomUrl = null;
79
+ function getConnectionPath() {
80
+ return roomUrl ? "/" : window.location.pathname;
81
+ }
82
+ function getConnectionQuery() {
83
+ return roomUrl ? `?roomUrl=${encodeURIComponent(roomUrl)}` : "";
84
+ }
77
85
  function rtcStatsConnection(wsURL, logger = console) {
78
86
  const buffer = [];
79
87
  let ws;
@@ -84,6 +92,7 @@ function rtcStatsConnection(wsURL, logger = console) {
84
92
  let roomSessionId;
85
93
  let connectionShouldBeOpen;
86
94
  let connectionAttempt = 0;
95
+ let reconnectTimeout;
87
96
  let hasPassedOnRoomSessionId = false;
88
97
  let getStatsBufferUsed = 0;
89
98
  let deviceId;
@@ -149,8 +158,9 @@ function rtcStatsConnection(wsURL, logger = console) {
149
158
  else {
150
159
  buffer.push(args);
151
160
  }
152
- if ((ws === null || ws === void 0 ? void 0 : ws.readyState) === WebSocket.CLOSED && connectionShouldBeOpen) {
153
- setTimeout(() => {
161
+ if ((ws === null || ws === void 0 ? void 0 : ws.readyState) === WebSocket.CLOSED && connectionShouldBeOpen && !reconnectTimeout) {
162
+ reconnectTimeout = setTimeout(() => {
163
+ reconnectTimeout = undefined;
154
164
  if (ws.readyState === WebSocket.CLOSED && connectionShouldBeOpen) {
155
165
  connection.connect();
156
166
  }
@@ -159,22 +169,33 @@ function rtcStatsConnection(wsURL, logger = console) {
159
169
  },
160
170
  close: () => {
161
171
  connectionShouldBeOpen = false;
172
+ clearTimeout(reconnectTimeout);
173
+ reconnectTimeout = undefined;
162
174
  ws === null || ws === void 0 ? void 0 : ws.close();
163
175
  },
164
176
  connect: () => {
177
+ clearTimeout(reconnectTimeout);
178
+ reconnectTimeout = undefined;
165
179
  connectionShouldBeOpen = true;
166
180
  connectionAttempt += 1;
167
181
  ws === null || ws === void 0 ? void 0 : ws.close();
168
182
  connection.connected = true;
169
183
  connection.attemptedConnectedAtLeastOnce = true;
170
- ws = new WebSocket(wsURL + window.location.pathname, RTCSTATS_PROTOCOL_VERSION);
184
+ const socket = new WebSocket(wsURL + getConnectionPath() + getConnectionQuery(), RTCSTATS_PROTOCOL_VERSION);
185
+ ws = socket;
171
186
  ws.onerror = (e) => {
172
187
  connection.connected = false;
173
188
  logger.warn(`[RTCSTATS] WebSocket error`, e);
174
189
  };
175
190
  ws.onclose = (e) => {
176
191
  connection.connected = false;
177
- logger.info(`[RTCSTATS] Closed ${e.code}`);
192
+ if (e.code === POLICY_VIOLATION && ws === socket) {
193
+ connectionShouldBeOpen = false;
194
+ logger.warn(`[RTCSTATS] Rejected by the server: ${e.reason}`);
195
+ }
196
+ else {
197
+ logger.info(`[RTCSTATS] Closed ${e.code}`);
198
+ }
178
199
  resetDelta();
179
200
  };
180
201
  ws.onopen = () => {
@@ -247,6 +268,9 @@ const rtcStats = {
247
268
  });
248
269
  },
249
270
  server,
271
+ setRoomUrl: (url) => {
272
+ roomUrl = url;
273
+ },
250
274
  };
251
275
 
252
276
  const debugOn = (typeof window !== "undefined" && new URLSearchParams(window.location.search).has("debug"));
package/dist/index.d.cts CHANGED
@@ -1915,6 +1915,7 @@ declare const rtcStats: {
1915
1915
  close: () => void;
1916
1916
  connect: () => void;
1917
1917
  };
1918
+ setRoomUrl: (url: string | null) => void;
1918
1919
  };
1919
1920
 
1920
1921
  interface SetCodecPreferenceSDPOptions {
package/dist/index.d.mts CHANGED
@@ -1915,6 +1915,7 @@ declare const rtcStats: {
1915
1915
  close: () => void;
1916
1916
  connect: () => void;
1917
1917
  };
1918
+ setRoomUrl: (url: string | null) => void;
1918
1919
  };
1919
1920
 
1920
1921
  interface SetCodecPreferenceSDPOptions {
package/dist/index.d.ts CHANGED
@@ -1915,6 +1915,7 @@ declare const rtcStats: {
1915
1915
  close: () => void;
1916
1916
  connect: () => void;
1917
1917
  };
1918
+ setRoomUrl: (url: string | null) => void;
1918
1919
  };
1919
1920
 
1920
1921
  interface SetCodecPreferenceSDPOptions {
package/dist/index.mjs CHANGED
@@ -47,6 +47,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
47
47
  var _a$6;
48
48
  (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
49
49
  const RTCSTATS_PROTOCOL_VERSION = "1.0";
50
+ const POLICY_VIOLATION = 1008;
50
51
  const GETSTATS_BUFFER_SIZE = 20;
51
52
  const clientInfo = {
52
53
  id: v4$1(),
@@ -54,6 +55,13 @@ const clientInfo = {
54
55
  };
55
56
  const noop = () => { };
56
57
  let resetDelta = noop;
58
+ let roomUrl = null;
59
+ function getConnectionPath() {
60
+ return roomUrl ? "/" : window.location.pathname;
61
+ }
62
+ function getConnectionQuery() {
63
+ return roomUrl ? `?roomUrl=${encodeURIComponent(roomUrl)}` : "";
64
+ }
57
65
  function rtcStatsConnection(wsURL, logger = console) {
58
66
  const buffer = [];
59
67
  let ws;
@@ -64,6 +72,7 @@ function rtcStatsConnection(wsURL, logger = console) {
64
72
  let roomSessionId;
65
73
  let connectionShouldBeOpen;
66
74
  let connectionAttempt = 0;
75
+ let reconnectTimeout;
67
76
  let hasPassedOnRoomSessionId = false;
68
77
  let getStatsBufferUsed = 0;
69
78
  let deviceId;
@@ -129,8 +138,9 @@ function rtcStatsConnection(wsURL, logger = console) {
129
138
  else {
130
139
  buffer.push(args);
131
140
  }
132
- if ((ws === null || ws === void 0 ? void 0 : ws.readyState) === WebSocket.CLOSED && connectionShouldBeOpen) {
133
- setTimeout(() => {
141
+ if ((ws === null || ws === void 0 ? void 0 : ws.readyState) === WebSocket.CLOSED && connectionShouldBeOpen && !reconnectTimeout) {
142
+ reconnectTimeout = setTimeout(() => {
143
+ reconnectTimeout = undefined;
134
144
  if (ws.readyState === WebSocket.CLOSED && connectionShouldBeOpen) {
135
145
  connection.connect();
136
146
  }
@@ -139,22 +149,33 @@ function rtcStatsConnection(wsURL, logger = console) {
139
149
  },
140
150
  close: () => {
141
151
  connectionShouldBeOpen = false;
152
+ clearTimeout(reconnectTimeout);
153
+ reconnectTimeout = undefined;
142
154
  ws === null || ws === void 0 ? void 0 : ws.close();
143
155
  },
144
156
  connect: () => {
157
+ clearTimeout(reconnectTimeout);
158
+ reconnectTimeout = undefined;
145
159
  connectionShouldBeOpen = true;
146
160
  connectionAttempt += 1;
147
161
  ws === null || ws === void 0 ? void 0 : ws.close();
148
162
  connection.connected = true;
149
163
  connection.attemptedConnectedAtLeastOnce = true;
150
- ws = new WebSocket(wsURL + window.location.pathname, RTCSTATS_PROTOCOL_VERSION);
164
+ const socket = new WebSocket(wsURL + getConnectionPath() + getConnectionQuery(), RTCSTATS_PROTOCOL_VERSION);
165
+ ws = socket;
151
166
  ws.onerror = (e) => {
152
167
  connection.connected = false;
153
168
  logger.warn(`[RTCSTATS] WebSocket error`, e);
154
169
  };
155
170
  ws.onclose = (e) => {
156
171
  connection.connected = false;
157
- logger.info(`[RTCSTATS] Closed ${e.code}`);
172
+ if (e.code === POLICY_VIOLATION && ws === socket) {
173
+ connectionShouldBeOpen = false;
174
+ logger.warn(`[RTCSTATS] Rejected by the server: ${e.reason}`);
175
+ }
176
+ else {
177
+ logger.info(`[RTCSTATS] Closed ${e.code}`);
178
+ }
158
179
  resetDelta();
159
180
  };
160
181
  ws.onopen = () => {
@@ -227,6 +248,9 @@ const rtcStats = {
227
248
  });
228
249
  },
229
250
  server,
251
+ setRoomUrl: (url) => {
252
+ roomUrl = url;
253
+ },
230
254
  };
231
255
 
232
256
  const debugOn = (typeof window !== "undefined" && new URLSearchParams(window.location.search).has("debug"));
@@ -47,6 +47,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
47
47
  var _a$6;
48
48
  (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
49
49
  const RTCSTATS_PROTOCOL_VERSION = "1.0";
50
+ const POLICY_VIOLATION = 1008;
50
51
  const GETSTATS_BUFFER_SIZE = 20;
51
52
  const clientInfo = {
52
53
  id: v4$1(),
@@ -54,6 +55,13 @@ const clientInfo = {
54
55
  };
55
56
  const noop = () => { };
56
57
  let resetDelta = noop;
58
+ let roomUrl = null;
59
+ function getConnectionPath() {
60
+ return roomUrl ? "/" : window.location.pathname;
61
+ }
62
+ function getConnectionQuery() {
63
+ return roomUrl ? `?roomUrl=${encodeURIComponent(roomUrl)}` : "";
64
+ }
57
65
  function rtcStatsConnection(wsURL, logger = console) {
58
66
  const buffer = [];
59
67
  let ws;
@@ -64,6 +72,7 @@ function rtcStatsConnection(wsURL, logger = console) {
64
72
  let roomSessionId;
65
73
  let connectionShouldBeOpen;
66
74
  let connectionAttempt = 0;
75
+ let reconnectTimeout;
67
76
  let hasPassedOnRoomSessionId = false;
68
77
  let getStatsBufferUsed = 0;
69
78
  let deviceId;
@@ -129,8 +138,9 @@ function rtcStatsConnection(wsURL, logger = console) {
129
138
  else {
130
139
  buffer.push(args);
131
140
  }
132
- if ((ws === null || ws === void 0 ? void 0 : ws.readyState) === WebSocket.CLOSED && connectionShouldBeOpen) {
133
- setTimeout(() => {
141
+ if ((ws === null || ws === void 0 ? void 0 : ws.readyState) === WebSocket.CLOSED && connectionShouldBeOpen && !reconnectTimeout) {
142
+ reconnectTimeout = setTimeout(() => {
143
+ reconnectTimeout = undefined;
134
144
  if (ws.readyState === WebSocket.CLOSED && connectionShouldBeOpen) {
135
145
  connection.connect();
136
146
  }
@@ -139,22 +149,33 @@ function rtcStatsConnection(wsURL, logger = console) {
139
149
  },
140
150
  close: () => {
141
151
  connectionShouldBeOpen = false;
152
+ clearTimeout(reconnectTimeout);
153
+ reconnectTimeout = undefined;
142
154
  ws === null || ws === void 0 ? void 0 : ws.close();
143
155
  },
144
156
  connect: () => {
157
+ clearTimeout(reconnectTimeout);
158
+ reconnectTimeout = undefined;
145
159
  connectionShouldBeOpen = true;
146
160
  connectionAttempt += 1;
147
161
  ws === null || ws === void 0 ? void 0 : ws.close();
148
162
  connection.connected = true;
149
163
  connection.attemptedConnectedAtLeastOnce = true;
150
- ws = new WebSocket(wsURL + window.location.pathname, RTCSTATS_PROTOCOL_VERSION);
164
+ const socket = new WebSocket(wsURL + getConnectionPath() + getConnectionQuery(), RTCSTATS_PROTOCOL_VERSION);
165
+ ws = socket;
151
166
  ws.onerror = (e) => {
152
167
  connection.connected = false;
153
168
  logger.warn(`[RTCSTATS] WebSocket error`, e);
154
169
  };
155
170
  ws.onclose = (e) => {
156
171
  connection.connected = false;
157
- logger.info(`[RTCSTATS] Closed ${e.code}`);
172
+ if (e.code === POLICY_VIOLATION && ws === socket) {
173
+ connectionShouldBeOpen = false;
174
+ logger.warn(`[RTCSTATS] Rejected by the server: ${e.reason}`);
175
+ }
176
+ else {
177
+ logger.info(`[RTCSTATS] Closed ${e.code}`);
178
+ }
158
179
  resetDelta();
159
180
  };
160
181
  ws.onopen = () => {
@@ -227,6 +248,9 @@ const rtcStats = {
227
248
  });
228
249
  },
229
250
  server,
251
+ setRoomUrl: (url) => {
252
+ roomUrl = url;
253
+ },
230
254
  };
231
255
 
232
256
  const debugOn = (typeof window !== "undefined" && new URLSearchParams(window.location.search).has("debug"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@whereby.com/media",
3
3
  "description": "Media library for Whereby",
4
- "version": "11.3.4",
4
+ "version": "11.4.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {
@@ -41,13 +41,13 @@
41
41
  "dependencies": {
42
42
  "check-ip": "^1.1.1",
43
43
  "events": "^3.3.0",
44
- "ip-address": "^10.1.1",
44
+ "ip-address": "^10.7.6",
45
45
  "mediasoup-client": "3.19.0",
46
46
  "@whereby.com/rtcstats": "5.4.2",
47
47
  "@whereby.com/webrtcapihealthcheck": "1.0.1",
48
48
  "sdp": "^3.2.0",
49
49
  "sdp-transform": "^2.14.2",
50
- "socket.io-client": "4.7.2",
50
+ "socket.io-client": "4.8.4",
51
51
  "uuid": "^9.0.1",
52
52
  "uuid-validate": "^0.0.3",
53
53
  "webrtc-adapter": "9.0.4"