@mega-yfue/eufy-sdk 0.4.0-beta.5 → 0.4.0-beta.6

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.js CHANGED
@@ -15178,6 +15178,7 @@ var LOCAL_LOOKUP_PORT = 32108;
15178
15178
  var HEARTBEAT_MS = 5e3;
15179
15179
  var PATH_SILENCE_MS = HEARTBEAT_MS * 3;
15180
15180
  var LOOKUP_RETRY_MS = 1e3;
15181
+ var RECEIVE_BUFFER_BYTES = 4 * 1024 * 1024;
15181
15182
  var CONNECT_TIMEOUT_MS = 15e3;
15182
15183
  var STATION_CHANNEL3 = 255;
15183
15184
  var CMD_GATEWAYINFO = 1100;
@@ -15233,6 +15234,8 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
15233
15234
  connected = false;
15234
15235
  connecting = false;
15235
15236
  closed = false;
15237
+ /** Whether a short receive buffer has been reported, so a reconnect does not repeat the same warning. */
15238
+ receiveBufferReported = false;
15236
15239
  connectAddress;
15237
15240
  seqNumber = 0;
15238
15241
  /**
@@ -15555,6 +15558,26 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
15555
15558
  get isConnected() {
15556
15559
  return this.connected;
15557
15560
  }
15561
+ /**
15562
+ * Ask the OS for {@link RECEIVE_BUFFER_BYTES} on a bound socket, and warn once per session when it grants
15563
+ * less or refuses.
15564
+ *
15565
+ * The request is made here rather than through `createSocket`'s `recvBufferSize`: Node applies that option
15566
+ * inside the bind callback, where a refusal is thrown out of reach of this session and ends the process.
15567
+ */
15568
+ requestReceiveBuffer(socket) {
15569
+ let granted;
15570
+ try {
15571
+ socket.setRecvBufferSize(RECEIVE_BUFFER_BYTES);
15572
+ granted = socket.getRecvBufferSize();
15573
+ } catch {
15574
+ granted = 0;
15575
+ }
15576
+ if (granted >= RECEIVE_BUFFER_BYTES || this.receiveBufferReported)
15577
+ return;
15578
+ this.receiveBufferReported = true;
15579
+ this.logger.warn(`[p2p] ${this.cfg.stationSn} UDP receive buffer below the ${RECEIVE_BUFFER_BYTES} bytes requested` + (granted > 0 ? ` (granted ${granted})` : " (request refused)") + `; live video can lose keyframes. Raise the OS limit (net.core.rmem_max on Linux, kern.ipc.maxsockbuf on BSD) to at least ${RECEIVE_BUFFER_BYTES}.`);
15580
+ }
15558
15581
  /** Open the socket and start the lookup → hole-punch handshake. */
15559
15582
  async connect() {
15560
15583
  if (this.connecting || this.connected)
@@ -15578,6 +15601,7 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
15578
15601
  socket.setBroadcast(true);
15579
15602
  } catch {
15580
15603
  }
15604
+ this.requestReceiveBuffer(socket);
15581
15605
  resolve();
15582
15606
  });
15583
15607
  });