Created
December 24, 2014 13:28
-
-
Save wallydz/255b9eb1758890d093fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var browser = new mdns.createBrowser(mdns.tcp('airplay')); | |
//var legacyMdnsBrowser = new mdns.Mdns(mdns.tcp('airplay')); | |
var mdnsOnUpdate = function(data) { | |
if(data.port && data.port == 7000){ | |
var info = data.addresses | |
var name = data.fullname.split('.')[0] | |
var dID = data.deviceid | |
/* | |
if ( !self.isValid( info ) ) { | |
return; | |
} | |
var device = self.getDevice( info ); | |
if ( device ) { | |
return; | |
} | |
*/ | |
//if(info.length && name){ | |
device = new Device( dID, info , name ); | |
device.on( 'ready', function( d ) { | |
self.emit( 'deviceOn', d ); | |
}); | |
device.on( 'close', function( d ) { | |
delete self.devices[ d.id ]; | |
self.emit( 'deviceOff', d ); | |
}); | |
self.devices[ device.id ] = device; | |
//}else{ | |
// console.log("Error adding device: "+JSON.stringify(data)) | |
//} | |
} | |
}; | |
//mdnsBrowser.on('ready', function () { | |
// mdnsBrowser.discover(); | |
//}); | |
browser.on('ready', function () { | |
browser.discover(); | |
}); | |
//mdnsBrowser.on('update', mdnsOnUpdate); | |
browser.on('update', mdnsOnUpdate); | |
/* | |
this.browser.on( 'serviceDown', function( info ) { | |
if ( !self.isValid( info ) ) { | |
return; | |
} | |
var device = self.getDevice( info ); | |
if ( device ) { | |
device.close(); | |
} | |
});*/ | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment