Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple TVs discover #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,16 @@ var _send_ssdp_discover = function(socket)
/*---------------------------------------------------------------------------*/
var discover_ip = function(retry_timeout_seconds, tv_ip_found_callback)
{

// timeout added for multi tv find // +1 second added in case of retry timeout use
setTimeout(function() {
server.close();
}, ((retry_timeout_seconds+1)*1000));

var server = dgram.createSocket('udp4');
var timeout = 0;
var cb = tv_ip_found_callback || undefined;

var tvFound = "";
// sanitize parameters and set default otherwise
if (retry_timeout_seconds && typeof(retry_timeout_seconds) === 'number') {
timeout = retry_timeout_seconds;
Expand All @@ -227,16 +233,19 @@ var discover_ip = function(retry_timeout_seconds, tv_ip_found_callback)
// set timeout before next probe
// XXXXX
// after timeout seconds, invoke callback indicating failure
// cb(true, "");
//cb(true, "");
}
});

// scan incoming messages for the magic string, close when we've got it
// scan incoming messages for the magic string
server.on('message', function(message, remote) {
if (message.indexOf("LG Smart TV") >= 0) {
server.close();
if (message.indexOf("LG Smart TV")) {
// commented because is stop at first tv found
//server.close();
if (cb) {
cb(false, remote.address);
if (tvFound != remote.address){ // we need this to filter same ip return
cb(false, remote.address);
tvFound = remote.address;
}
}
}
});
Expand Down