Skip to content

Commit

Permalink
Merge pull request #1 from FrankZZ/feature/reconnect
Browse files Browse the repository at this point in the history
Feature/reconnect
  • Loading branch information
FrankZZ authored Mar 29, 2022
2 parents 281123b + 1459339 commit 6460910
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 3,435 deletions.
3 changes: 3 additions & 0 deletions dahua.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ dahua.prototype.connect = function(options) {
'headers': {'Accept':'multipart/x-mixed-replace'}
};

console.log("Connecting...");
var client = request(opts).auth(USER,PASS,false);

client.on('socket', function(socket) {
// Set keep-alive probes - throws ESOCKETTIMEDOUT error after ~16min if connection broken
socket.setKeepAlive(true, 1000);
NetKeepAlive.setKeepAliveInterval(socket, 1000);
if (TRACE) console.log('TCP_KEEPINTVL:',NetKeepAlive.getKeepAliveInterval(socket));

Expand All @@ -100,6 +102,7 @@ dahua.prototype.connect = function(options) {
});

client.on('close', function() { // Try to reconnect after 30s
console.error("Connection closed- reconnecting in 30 seconds...");
setTimeout(function() { self.connect(options); }, 30000 );
handleDahuaEventEnd(self);
});
Expand Down
Loading

0 comments on commit 6460910

Please sign in to comment.