amcrest/hikvision: add setKeepAlive to tcp socket to see if that detects terminated connections

This commit is contained in:
Koushik Dutta
2022-06-30 17:22:01 -07:00
parent 8a21b0e2d0
commit e84ff90ee3
7 changed files with 16 additions and 9 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/amcrest",
"version": "0.0.101",
"version": "0.0.102",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/amcrest",
"version": "0.0.101",
"version": "0.0.102",
"hasInstallScript": true,
"license": "Apache",
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/amcrest",
"version": "0.0.101",
"version": "0.0.102",
"description": "Amcrest Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",

View File

@@ -21,7 +21,7 @@ export enum AmcrestEvent {
}
export const amcrestHttpsAgent = new https.Agent({
rejectUnauthorized: false
rejectUnauthorized: false,
});
export class AmcrestCameraClient {
@@ -57,6 +57,7 @@ export class AmcrestCameraClient {
url,
});
const stream = response.data as IncomingMessage;
stream.socket.setKeepAlive(true);
let activityTimeout: NodeJS.Timeout;
const resetActivityTimeout = () => {
clearTimeout(activityTimeout);

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/hikvision",
"version": "0.0.93",
"version": "0.0.94",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/hikvision",
"version": "0.0.93",
"version": "0.0.94",
"hasInstallScript": true,
"license": "Apache",
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/hikvision",
"version": "0.0.93",
"version": "0.0.94",
"description": "HikVision Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",

View File

@@ -1,6 +1,7 @@
import { Readable } from 'stream';
import AxiosDigestAuth from '@koush/axios-digest-auth';
import { EventEmitter } from "stream";
import { IncomingMessage } from 'http';
function getChannel(channel: string) {
return channel || '101';
@@ -117,7 +118,8 @@ export class HikVisionCameraAPI {
url,
responseType: 'stream',
});
const stream = response.data as Readable;
const stream = response.data as IncomingMessage;
stream.socket.setKeepAlive(true);
stream.on('data', (buffer: Buffer) => {
const data = buffer.toString();

View File

@@ -81,6 +81,7 @@ export async function createRTCPeerConnectionSource(options: {
const pc = await peerConnection.promise;
audioTransceiver = pc.addTransceiver("audio", setup.audio as any);
audioTransceiver.mid = '0';
audioTransceiver.onTrack.subscribe((track) => {
track.onReceiveRtp.subscribe(rtp => {
if (!gotAudio) {
@@ -93,6 +94,7 @@ export async function createRTCPeerConnectionSource(options: {
});
const videoTransceiver = pc.addTransceiver("video", setup.video as any);
videoTransceiver.mid = '1';
videoTransceiver.onTrack.subscribe((track) => {
track.onReceiveRtp.subscribe(rtp => {
if (!gotVideo) {
@@ -157,8 +159,10 @@ export async function createRTCPeerConnectionSource(options: {
if (type === 'offer')
doSetup(setup);
const pc = await peerConnection.promise;
if (setup.datachannel)
if (setup.datachannel) {
pc.createDataChannel(setup.datachannel.label, setup.datachannel.dict);
pc.sctpTransport.mid = '2';
}
const gatheringPromise = pc.iceGatheringState === 'complete' ? Promise.resolve(undefined) : new Promise(resolve => pc.iceGatheringStateChange.subscribe(state => {
if (state === 'complete')