@apocaliss92/nodelink-js 0.4.1 → 0.4.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.
- package/dist/{chunk-SDRNJQ5U.js → chunk-TJNPGYJA.js} +88 -34
- package/dist/chunk-TJNPGYJA.js.map +1 -0
- package/dist/cli/rtsp-server.cjs +87 -33
- package/dist/cli/rtsp-server.cjs.map +1 -1
- package/dist/cli/rtsp-server.js +1 -1
- package/dist/index.cjs +87 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -5
- package/dist/index.d.ts +47 -5
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-SDRNJQ5U.js.map +0 -1
|
@@ -5518,6 +5518,7 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter3 {
|
|
|
5518
5518
|
flow;
|
|
5519
5519
|
deviceId;
|
|
5520
5520
|
dedicatedSessionRelease;
|
|
5521
|
+
externalListener;
|
|
5521
5522
|
// Authentication
|
|
5522
5523
|
authCredentials = [];
|
|
5523
5524
|
requireAuth;
|
|
@@ -5685,6 +5686,7 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter3 {
|
|
|
5685
5686
|
this.logger = options.logger ?? console;
|
|
5686
5687
|
this.tcpRtpFraming = options.tcpRtpFraming ?? "rfc4571";
|
|
5687
5688
|
this.deviceId = options.deviceId;
|
|
5689
|
+
this.externalListener = options.externalListener ?? false;
|
|
5688
5690
|
this.authCredentials = options.credentials ?? [];
|
|
5689
5691
|
this.requireAuth = options.requireAuth ?? this.authCredentials.length > 0;
|
|
5690
5692
|
const transport = this.api.client.getTransport();
|
|
@@ -5815,41 +5817,56 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter3 {
|
|
|
5815
5817
|
this.streamMetadata = { frameRate: 25 };
|
|
5816
5818
|
this.setFlowVideoType("H264", "metadata unavailable");
|
|
5817
5819
|
}
|
|
5818
|
-
this.
|
|
5819
|
-
this.
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
this.
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5820
|
+
if (!this.externalListener) {
|
|
5821
|
+
this.clientConnectionServer = net2.createServer((socket) => {
|
|
5822
|
+
this.handleRtspConnection(socket);
|
|
5823
|
+
});
|
|
5824
|
+
await new Promise((resolve, reject) => {
|
|
5825
|
+
this.clientConnectionServer.listen(
|
|
5826
|
+
this.listenPort,
|
|
5827
|
+
this.listenHost,
|
|
5828
|
+
() => {
|
|
5829
|
+
const address = this.clientConnectionServer.address();
|
|
5830
|
+
if (address && typeof address === "object" && "port" in address) {
|
|
5831
|
+
this.listenPort = address.port;
|
|
5832
|
+
}
|
|
5833
|
+
resolve();
|
|
5829
5834
|
}
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
reject(error);
|
|
5835
|
+
);
|
|
5836
|
+
this.clientConnectionServer.on("error", (error) => {
|
|
5837
|
+
reject(error);
|
|
5838
|
+
});
|
|
5835
5839
|
});
|
|
5836
|
-
}
|
|
5840
|
+
}
|
|
5837
5841
|
this.active = true;
|
|
5838
5842
|
this.logger.info(
|
|
5839
5843
|
`[BaichuanRtspServer] RTSP server started on ${this.listenHost}:${this.listenPort}, path: ${this.path}`
|
|
5840
5844
|
);
|
|
5841
5845
|
}
|
|
5846
|
+
/**
|
|
5847
|
+
* Accept an externally-routed RTSP connection.
|
|
5848
|
+
* Used in directHandoff mode where RtspProxyServer routes sockets here.
|
|
5849
|
+
* @param socket - The client TCP socket (already authenticated by proxy)
|
|
5850
|
+
* @param initialBuffer - Any bytes already read during path parsing/auth
|
|
5851
|
+
*/
|
|
5852
|
+
acceptConnection(socket, initialBuffer) {
|
|
5853
|
+
if (!this.active) {
|
|
5854
|
+
socket.end("RTSP/1.0 503 Service Unavailable\r\n\r\n");
|
|
5855
|
+
return;
|
|
5856
|
+
}
|
|
5857
|
+
this.handleRtspConnection(socket, initialBuffer);
|
|
5858
|
+
}
|
|
5842
5859
|
/**
|
|
5843
5860
|
* Handle RTSP connection from a client.
|
|
5844
5861
|
*/
|
|
5845
|
-
handleRtspConnection(socket) {
|
|
5862
|
+
handleRtspConnection(socket, initialBuffer) {
|
|
5846
5863
|
const clientId = `${socket.remoteAddress}:${socket.remotePort}`;
|
|
5847
5864
|
const connectTime = Date.now();
|
|
5848
5865
|
this.logger.info(
|
|
5849
5866
|
`[rebroadcast] client connected client=${clientId} path=${this.path} profile=${this.profile} channel=${this.channel}`
|
|
5850
5867
|
);
|
|
5851
5868
|
let sessionId = "";
|
|
5852
|
-
let buffer = Buffer.alloc(0);
|
|
5869
|
+
let buffer = initialBuffer ?? Buffer.alloc(0);
|
|
5853
5870
|
let clientFfmpeg;
|
|
5854
5871
|
let useTcpInterleaved = false;
|
|
5855
5872
|
let clientUdpSocket = null;
|
|
@@ -5934,8 +5951,7 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter3 {
|
|
|
5934
5951
|
}
|
|
5935
5952
|
cleanup();
|
|
5936
5953
|
});
|
|
5937
|
-
|
|
5938
|
-
buffer = Buffer.concat([buffer, data]);
|
|
5954
|
+
const processBuffer = async () => {
|
|
5939
5955
|
while (buffer.includes("\r\n\r\n")) {
|
|
5940
5956
|
const endIndex = buffer.indexOf("\r\n\r\n");
|
|
5941
5957
|
const requestText = buffer.subarray(0, endIndex).toString();
|
|
@@ -6210,7 +6226,14 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter3 {
|
|
|
6210
6226
|
sendResponse(501, "Not Implemented");
|
|
6211
6227
|
}
|
|
6212
6228
|
}
|
|
6229
|
+
};
|
|
6230
|
+
socket.on("data", (data) => {
|
|
6231
|
+
buffer = Buffer.concat([buffer, data]);
|
|
6232
|
+
void processBuffer();
|
|
6213
6233
|
});
|
|
6234
|
+
if (buffer.includes("\r\n\r\n")) {
|
|
6235
|
+
void processBuffer();
|
|
6236
|
+
}
|
|
6214
6237
|
}
|
|
6215
6238
|
/**
|
|
6216
6239
|
* Generate SDP (Session Description Protocol) for RTSP DESCRIBE.
|
|
@@ -7178,21 +7201,27 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter3 {
|
|
|
7178
7201
|
res.seenFirstVideoKeyframe = false;
|
|
7179
7202
|
res.rtpSentVideoConfig = false;
|
|
7180
7203
|
}
|
|
7181
|
-
if (this.dedicatedSessionRelease) {
|
|
7182
|
-
const release = this.dedicatedSessionRelease;
|
|
7183
|
-
this.dedicatedSessionRelease = void 0;
|
|
7184
|
-
release().catch(() => {
|
|
7185
|
-
});
|
|
7186
|
-
}
|
|
7187
7204
|
this.logger.info(
|
|
7188
7205
|
`[rebroadcast] native stream ended (camera sleeping or connection lost) profile=${this.profile} channel=${this.channel} clients=${this.connectedClients.size}`
|
|
7189
7206
|
);
|
|
7190
|
-
|
|
7191
|
-
this.
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7207
|
+
const releaseAndRestart = async () => {
|
|
7208
|
+
if (this.dedicatedSessionRelease) {
|
|
7209
|
+
const release = this.dedicatedSessionRelease;
|
|
7210
|
+
this.dedicatedSessionRelease = void 0;
|
|
7211
|
+
try {
|
|
7212
|
+
await release();
|
|
7213
|
+
} catch {
|
|
7214
|
+
}
|
|
7215
|
+
}
|
|
7216
|
+
if (this.connectedClients.size > 0) {
|
|
7217
|
+
this.logger.info(
|
|
7218
|
+
`[rebroadcast] restarting native stream for ${this.connectedClients.size} active client(s)`
|
|
7219
|
+
);
|
|
7220
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
7221
|
+
void this.startNativeStream();
|
|
7222
|
+
}
|
|
7223
|
+
};
|
|
7224
|
+
void releaseAndRestart();
|
|
7196
7225
|
}
|
|
7197
7226
|
});
|
|
7198
7227
|
this.nativeFanout.start();
|
|
@@ -7416,6 +7445,31 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter3 {
|
|
|
7416
7445
|
getClientCount() {
|
|
7417
7446
|
return this.connectedClients.size;
|
|
7418
7447
|
}
|
|
7448
|
+
/**
|
|
7449
|
+
* Subscribe to the raw native stream for diagnostic purposes.
|
|
7450
|
+
* The subscriber receives the same frames as RTSP clients.
|
|
7451
|
+
* Counts as a "consumer" for lifecycle — prevents auto-stop while subscribed.
|
|
7452
|
+
* If the native stream is not active, starts it automatically.
|
|
7453
|
+
*/
|
|
7454
|
+
async subscribeDiagnostic(id) {
|
|
7455
|
+
this.connectedClients.add(`diag:${id}`);
|
|
7456
|
+
if (!this.nativeStreamActive) {
|
|
7457
|
+
await this.startNativeStream();
|
|
7458
|
+
}
|
|
7459
|
+
return this.nativeFanout.subscribe(`diag:${id}`);
|
|
7460
|
+
}
|
|
7461
|
+
/**
|
|
7462
|
+
* Unsubscribe a diagnostic session.
|
|
7463
|
+
*/
|
|
7464
|
+
unsubscribeDiagnostic(id) {
|
|
7465
|
+
this.removeClient(`diag:${id}`);
|
|
7466
|
+
}
|
|
7467
|
+
/**
|
|
7468
|
+
* Returns detected audio metadata (available after first audio frame).
|
|
7469
|
+
*/
|
|
7470
|
+
getAudioInfo() {
|
|
7471
|
+
return this.audioInfo;
|
|
7472
|
+
}
|
|
7419
7473
|
};
|
|
7420
7474
|
|
|
7421
7475
|
// src/reolink/baichuan/capabilities.ts
|
|
@@ -21516,4 +21570,4 @@ export {
|
|
|
21516
21570
|
isTcpFailureThatShouldFallbackToUdp,
|
|
21517
21571
|
autoDetectDeviceType
|
|
21518
21572
|
};
|
|
21519
|
-
//# sourceMappingURL=chunk-
|
|
21573
|
+
//# sourceMappingURL=chunk-TJNPGYJA.js.map
|