mediasfu-shared 1.2.0 → 1.2.2

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +145 -131
  3. package/dist/consumers/connectIps.d.ts.map +1 -1
  4. package/dist/consumers/index.cjs +1 -1
  5. package/dist/consumers/index.js +1 -1
  6. package/dist/{getParticipantMedia-CdcYqcbD.cjs → getParticipantMedia-BH3d_-Q1.cjs} +4 -4
  7. package/dist/getParticipantMedia-BH3d_-Q1.cjs.map +1 -0
  8. package/dist/{getParticipantMedia-B0JS6d2b.js → getParticipantMedia-CGqnSb93.js} +4 -4
  9. package/dist/getParticipantMedia-CGqnSb93.js.map +1 -0
  10. package/dist/index.cjs +3 -3
  11. package/dist/index.js +4 -4
  12. package/dist/index.native.cjs +3 -3
  13. package/dist/index.native.js +3 -3
  14. package/dist/{joinLocalRoom-CvteNe4R.js → joinLocalRoom-7ibqv7zZ.js} +2 -2
  15. package/dist/{joinLocalRoom-CvteNe4R.js.map → joinLocalRoom-7ibqv7zZ.js.map} +1 -1
  16. package/dist/{joinLocalRoom-BdM1msQt.cjs → joinLocalRoom-BJBDvTYh.cjs} +2 -2
  17. package/dist/{joinLocalRoom-BdM1msQt.cjs.map → joinLocalRoom-BJBDvTYh.cjs.map} +1 -1
  18. package/dist/methods/recording/startRecording.d.ts.map +1 -1
  19. package/dist/types/index.cjs +2 -2
  20. package/dist/types/index.js +2 -2
  21. package/dist/{updateParticipantAudioDecibels-DLd8Y-Fh.js → updateParticipantAudioDecibels-C_MygF6q.js} +45 -5
  22. package/dist/updateParticipantAudioDecibels-C_MygF6q.js.map +1 -0
  23. package/dist/{updateParticipantAudioDecibels-DPmHiy3K.cjs → updateParticipantAudioDecibels-bZ6R8WHj.cjs} +45 -5
  24. package/dist/updateParticipantAudioDecibels-bZ6R8WHj.cjs.map +1 -0
  25. package/package.json +2 -1
  26. package/src/consumers/connectIps.ts +68 -8
  27. package/src/methods/recording/startRecording.ts +7 -1
  28. package/dist/getParticipantMedia-B0JS6d2b.js.map +0 -1
  29. package/dist/getParticipantMedia-CdcYqcbD.cjs.map +0 -1
  30. package/dist/updateParticipantAudioDecibels-DLd8Y-Fh.js.map +0 -1
  31. package/dist/updateParticipantAudioDecibels-DPmHiy3K.cjs.map +0 -1
@@ -1192,6 +1192,40 @@ const joinConsumeRoom = async ({
1192
1192
  throw new Error("Failed to join the consumption room or set up necessary components.");
1193
1193
  }
1194
1194
  };
1195
+ const pendingConsumeConnections = /* @__PURE__ */ new WeakMap();
1196
+ const normalizeConsumeEndpoint = (ip) => ip.trim().toLowerCase().replace(/\.$/, "");
1197
+ const hasConsumeEndpoint = (consumeSockets, endpoint) => consumeSockets.some((socketObj) => {
1198
+ const ip = Object.keys(socketObj)[0];
1199
+ return Boolean(ip) && normalizeConsumeEndpoint(ip) === endpoint;
1200
+ });
1201
+ async function reserveConsumeEndpoint(consumeSockets, ip, reservationOwner = consumeSockets) {
1202
+ const endpoint = normalizeConsumeEndpoint(ip);
1203
+ if (!endpoint || endpoint === "none") return null;
1204
+ let pendingForSockets = pendingConsumeConnections.get(reservationOwner);
1205
+ if (!pendingForSockets) {
1206
+ pendingForSockets = /* @__PURE__ */ new Map();
1207
+ pendingConsumeConnections.set(reservationOwner, pendingForSockets);
1208
+ }
1209
+ while (true) {
1210
+ if (hasConsumeEndpoint(consumeSockets, endpoint)) return null;
1211
+ const pending = pendingForSockets.get(endpoint);
1212
+ if (pending) {
1213
+ if (await pending) return null;
1214
+ continue;
1215
+ }
1216
+ let resolvePending;
1217
+ const reservation = new Promise((resolve) => {
1218
+ resolvePending = resolve;
1219
+ });
1220
+ pendingForSockets.set(endpoint, reservation);
1221
+ return (didConnect = false) => {
1222
+ if (pendingForSockets?.get(endpoint) === reservation) {
1223
+ pendingForSockets.delete(endpoint);
1224
+ }
1225
+ resolvePending(didConnect === true);
1226
+ };
1227
+ }
1228
+ }
1195
1229
  const connectIps = async ({
1196
1230
  consume_sockets,
1197
1231
  remIP,
@@ -1216,11 +1250,14 @@ const connectIps = async ({
1216
1250
  return [consume_sockets, roomRecvIPs];
1217
1251
  }
1218
1252
  for (const ip of remIP) {
1253
+ const releaseReservation = await reserveConsumeEndpoint(
1254
+ consume_sockets,
1255
+ ip,
1256
+ parameters?.socket || consume_sockets
1257
+ );
1258
+ if (!releaseReservation) continue;
1259
+ let connected = false;
1219
1260
  try {
1220
- const matching = consume_sockets.find((socketObj) => Object.keys(socketObj)[0] === ip);
1221
- if (matching || !ip) {
1222
- continue;
1223
- }
1224
1261
  const remote_sock = await connectSocket({ apiUserName, apiKey, apiToken, link: `https://${ip}.mediasfu.com` });
1225
1262
  if (remote_sock.id) {
1226
1263
  if (!roomRecvIPs.includes(ip)) {
@@ -1257,9 +1294,12 @@ const connectIps = async ({
1257
1294
  }
1258
1295
  consume_sockets.push({ [ip]: remote_sock });
1259
1296
  updateConsume_sockets(consume_sockets);
1297
+ connected = true;
1260
1298
  }
1261
1299
  } catch (error) {
1262
1300
  console.log("connectIps error", error);
1301
+ } finally {
1302
+ releaseReservation(connected);
1263
1303
  }
1264
1304
  }
1265
1305
  return [consume_sockets, roomRecvIPs];
@@ -5388,4 +5428,4 @@ exports.trigger = trigger;
5388
5428
  exports.updateMicLevel = updateMicLevel;
5389
5429
  exports.updateMiniCardsGrid = updateMiniCardsGrid;
5390
5430
  exports.updateParticipantAudioDecibels = updateParticipantAudioDecibels;
5391
- //# sourceMappingURL=updateParticipantAudioDecibels-DPmHiy3K.cjs.map
5431
+ //# sourceMappingURL=updateParticipantAudioDecibels-bZ6R8WHj.cjs.map