iobroker.chromecast
Advanced tools
Comparing version 0.2.1 to 1.0.0
@@ -79,7 +79,7 @@ /** | ||
chromecastScanner(adapter.config.useSSDP, | ||
function (name, address, port){ | ||
chromecastDevices[name] = new ChromecastDevice(adapter, name, address, port); | ||
},SCAN_INTERVAL, | ||
function (name, address, port){ | ||
chromecastDevices[name].updateAddress(address, port); | ||
function (name, address, port) { | ||
chromecastDevices[name] = new ChromecastDevice(adapter, name, address, port); | ||
}, SCAN_INTERVAL, | ||
function (name, address, port) { | ||
chromecastDevices[name].updateAddress(address, port); | ||
}); | ||
@@ -86,0 +86,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"title": "Chromecast Adapter", | ||
"version": "0.2.1", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "authors": ["Vegetto <iobroker@angelnu.com>"], |
@@ -13,3 +13,3 @@ /* | ||
const STATUS_QUERY_TIME = 30000; // 30 seconds | ||
var STATUS_QUERY_TIME = 30000; // 30 seconds | ||
@@ -23,19 +23,19 @@ //NOTE: the retries are implemented in this way: | ||
// 100 * 101 * 30000 /2 = 42 hours | ||
const DELAY_CONNECTION_RETY = 1000; // 30 seconds | ||
const MAX_CONECTIONS_RETRIES = 100; | ||
var DELAY_CONNECTION_RETY = 1000; // 30 seconds | ||
var MAX_CONECTIONS_RETRIES = 100; | ||
var ChromecastDevice = function (adapter, name, address, port) { | ||
var ChromecastDevice = function (_adapter, _name, _address, _port) { | ||
adapter.log.info(name + " - Found (Address:"+address+" Port:"+port+")"); | ||
adapter.log.info(name + " - Found (Address:" + address + " Port:" + port + ")"); | ||
var that = this; | ||
var adapter = adapter; | ||
var address = address; | ||
var name = name.replace(/[.\s]+/g, '_'); | ||
var port = port; | ||
var adapter = _adapter; | ||
var address = _address; | ||
var name = _name.replace(/[.\s]+/g, '_'); | ||
var port = _port; | ||
//Internal variables | ||
var player = undefined; | ||
var currentApplicationObject = undefined; | ||
var player; | ||
var currentApplicationObject; | ||
@@ -51,3 +51,3 @@ //Internal status | ||
//Some constants | ||
var NAMESPACE = adapter.namespace+"."+name; | ||
var NAMESPACE = adapter.namespace + "." + name; | ||
@@ -71,5 +71,5 @@ //Create ioBroker objects | ||
//Need to be called when the address/port change | ||
this.updateAddress = function(n_address, n_port) { | ||
this.updateAddress = function (n_address, n_port) { | ||
adapter.log.info(name+" - Updating address: "+n_address+":"+n_port) | ||
adapter.log.info(name + " - Updating address: " + n_address + ":" + n_port); | ||
@@ -82,3 +82,3 @@ address = n_address; | ||
if (connectedClient) | ||
reconnectClient() | ||
reconnectClient(); | ||
}; | ||
@@ -97,22 +97,22 @@ | ||
var CHANNEL_STATUS = name+'.status'; | ||
var CHANNEL_STATUS = name + '.status'; | ||
var channels = { | ||
'status': { | ||
name: name+'.status', | ||
name: name + '.status', | ||
desc: 'Status channel for Chromecast device' | ||
}, | ||
'player': { | ||
name: name+'.player', | ||
name: name + '.player', | ||
desc: 'Player channel for Chromecast device' | ||
}, | ||
'media': { | ||
name: name+'.media', | ||
name: name + '.media', | ||
desc: 'Media channel for Chromecast device' | ||
}, | ||
'metadata': { | ||
name: name+'.metadata', | ||
name: name + '.metadata', | ||
desc: 'Metadata channel for Chromecast device' | ||
}, | ||
'exportedMedia': { | ||
name: name+'.exportedMedia', | ||
name: name + '.exportedMedia', | ||
desc: 'Media exported via ioBroker web server' | ||
@@ -123,3 +123,4 @@ } | ||
//Create/update all channel definitions | ||
for (var k in channels) { | ||
var k; | ||
for (k in channels) { | ||
adapter.setObject(channels[k].name, { | ||
@@ -130,3 +131,3 @@ type: 'channel', | ||
}); | ||
}; | ||
} | ||
@@ -136,3 +137,3 @@ var states = { | ||
'address': { | ||
name: name+'.address', | ||
name: name + '.address', | ||
def: address, | ||
@@ -146,3 +147,3 @@ type: 'string', | ||
'port': { | ||
name: name+'.port', | ||
name: name + '.port', | ||
def: address, | ||
@@ -157,3 +158,3 @@ type: 'string', | ||
'connected': { | ||
name: channels.status.name+'.connected', | ||
name: channels.status.name + '.connected', | ||
def: false, | ||
@@ -167,3 +168,3 @@ type: 'boolean', | ||
'playing': { | ||
name: channels.status.name+'.playing', | ||
name: channels.status.name + '.playing', | ||
def: false, | ||
@@ -177,3 +178,3 @@ type: 'boolean', | ||
'volume': { | ||
name: channels.status.name+'.volume', | ||
name: channels.status.name + '.volume', | ||
def: 1, | ||
@@ -189,3 +190,3 @@ type: 'number', | ||
'muted': { | ||
name: channels.status.name+'.muted', | ||
name: channels.status.name + '.muted', | ||
def: false, | ||
@@ -199,3 +200,3 @@ type: 'boolean', | ||
'isActiveInput': { | ||
name: channels.status.name+'.isActiveInput', | ||
name: channels.status.name + '.isActiveInput', | ||
def: true, | ||
@@ -209,3 +210,3 @@ type: 'boolean', | ||
'isStandBy': { | ||
name: channels.status.name+'.isStandBy', | ||
name: channels.status.name + '.isStandBy', | ||
def: false, | ||
@@ -219,3 +220,3 @@ type: 'boolean', | ||
'displayName': { | ||
name: channels.status.name+'.displayName', | ||
name: channels.status.name + '.displayName', | ||
def: "", | ||
@@ -229,3 +230,3 @@ type: 'string', | ||
'statusText': { | ||
name: channels.status.name+'.text', | ||
name: channels.status.name + '.text', | ||
def: "", | ||
@@ -240,3 +241,3 @@ type: 'string', | ||
'url2play': { | ||
name: channels.player.name+'.url2play', | ||
name: channels.player.name + '.url2play', | ||
def: '', | ||
@@ -250,3 +251,3 @@ type: 'string', | ||
'playerState': { | ||
name: channels.player.name+'.playerState', | ||
name: channels.player.name + '.playerState', | ||
def: '', | ||
@@ -260,3 +261,3 @@ type: 'string', | ||
'paused': { | ||
name: channels.player.name+'.paused', | ||
name: channels.player.name + '.paused', | ||
def: false, | ||
@@ -270,3 +271,3 @@ type: 'boolean', | ||
'currentTime': { | ||
name: channels.player.name+'.currentTime', | ||
name: channels.player.name + '.currentTime', | ||
def: 0, | ||
@@ -278,6 +279,6 @@ type: 'number', | ||
desc: 'Playing time?', | ||
unit: 's' | ||
unit: 's' | ||
}, | ||
'repeat': { | ||
name: channels.player.name+'.repeatMode', | ||
name: channels.player.name + '.repeatMode', | ||
def: false, | ||
@@ -291,3 +292,3 @@ type: 'boolean', | ||
'playerVolume': { | ||
name: channels.player.name+'.volume', | ||
name: channels.player.name + '.volume', | ||
def: 1, | ||
@@ -298,9 +299,8 @@ type: 'number', | ||
role: 'status', | ||
desc: 'volume in %', | ||
min: 0, | ||
max: 100, | ||
desc: 'Player volume' | ||
desc: 'Player volume in %' | ||
}, | ||
'playerMuted': { | ||
name: channels.player.name+'.muted', | ||
name: channels.player.name + '.muted', | ||
def: false, | ||
@@ -315,3 +315,3 @@ type: 'boolean', | ||
'streamType': { | ||
name: channels.media.name+'.streamType', | ||
name: channels.media.name + '.streamType', | ||
def: '', | ||
@@ -325,3 +325,3 @@ type: 'string', | ||
'duration': { | ||
name: channels.media.name+'.duration', | ||
name: channels.media.name + '.duration', | ||
def: -1, | ||
@@ -336,3 +336,3 @@ type: 'number', | ||
'contentType': { | ||
name: channels.media.name+'.contentType', | ||
name: channels.media.name + '.contentType', | ||
def: '', | ||
@@ -346,3 +346,3 @@ type: 'string', | ||
'contentId': { | ||
name: channels.media.name+'.contentId', | ||
name: channels.media.name + '.contentId', | ||
def: '', | ||
@@ -357,3 +357,3 @@ type: 'string', | ||
'title': { | ||
name: channels.metadata.name+'.title', | ||
name: channels.metadata.name + '.title', | ||
def: '', | ||
@@ -367,3 +367,3 @@ type: 'string', | ||
'album': { | ||
name: channels.metadata.name+'.album', | ||
name: channels.metadata.name + '.album', | ||
def: '', | ||
@@ -377,3 +377,3 @@ type: 'string', | ||
'artist': { | ||
name: channels.metadata.name+'.artist', | ||
name: channels.metadata.name + '.artist', | ||
def: '', | ||
@@ -388,3 +388,3 @@ type: 'string', | ||
'exportedMedia': { | ||
name: channels.exportedMedia.name+'.mp3', | ||
name: channels.exportedMedia.name + '.mp3', | ||
type: 'object', | ||
@@ -399,3 +399,3 @@ read: true, | ||
//Create/update all state definitions | ||
for (var k in states) { | ||
for (k in states) { | ||
adapter.setObject(states[k].name, { | ||
@@ -406,3 +406,3 @@ type: 'state', | ||
}); | ||
}; | ||
} | ||
@@ -416,4 +416,4 @@ //Set some objects | ||
//Set url2play only if not set already | ||
adapter.getState(states.url2play.name,function(err,state){ | ||
if (!state){ | ||
adapter.getState(states.url2play.name, function (err, state) { | ||
if (!state) { | ||
adapter.setState(states.url2play.name, {val: "http:/example.org/playme.mp3", ack: true}); | ||
@@ -426,3 +426,3 @@ } | ||
}; | ||
} | ||
@@ -436,17 +436,17 @@ | ||
var connectionRetries = 0; | ||
function reconnectClient(){ | ||
function reconnectClient() { | ||
if (client){ | ||
if (client) { | ||
if (player) { | ||
try{ | ||
try { | ||
detachPlayer(); | ||
} catch (e){ | ||
adapter.log.error(name + " - error detaching player: "+e); | ||
} catch (e) { | ||
adapter.log.error(name + " - error detaching player: " + e); | ||
} | ||
} | ||
try{ | ||
try { | ||
client.removeListener('status', updateStatus); | ||
if (connectedClient) client.close(); | ||
} catch (e){ | ||
adapter.log.error(name + " - error closing client: "+e); | ||
} catch (e) { | ||
adapter.log.error(name + " - error closing client: " + e); | ||
} | ||
@@ -463,7 +463,7 @@ client = undefined; | ||
connectionRetries++; | ||
if (connectionRetries>MAX_CONECTIONS_RETRIES){ | ||
if (connectionRetries > MAX_CONECTIONS_RETRIES) { | ||
adapter.log.warn(name + " - Max amount of reconnects reached - stay offline"); | ||
} else { | ||
//Try to reconnect after 5 seconds | ||
setTimeout(function() { | ||
setTimeout(function () { | ||
@@ -473,6 +473,6 @@ client = new Client(); | ||
}, connectionRetries * DELAY_CONNECTION_RETY); | ||
}; | ||
}; | ||
} | ||
} | ||
function connectClient(){ | ||
function connectClient() { | ||
@@ -483,4 +483,4 @@ //Register for status updates | ||
//Register for errors | ||
client.once('close', function(err) { | ||
adapter.log.error(name + " - Client closed: "+JSON.stringify(err)); | ||
client.once('close', function (err) { | ||
adapter.log.error(name + " - Client closed: " + JSON.stringify(err)); | ||
//Try to re-connect | ||
@@ -491,4 +491,4 @@ reconnectClient(); | ||
//Register for errors | ||
client.once('error', function(err) { | ||
adapter.log.warn(name + " - Client error: "+JSON.stringify(err)); | ||
client.once('error', function (err) { | ||
adapter.log.warn(name + " - Client error: " + JSON.stringify(err)); | ||
//Try to re-connect | ||
@@ -499,3 +499,3 @@ reconnectClient(); | ||
//Connect client | ||
client.connect({host:address, port:port}, function() { | ||
client.connect({host:address, port:port}, function () { | ||
adapter.log.info(name + " - Connected"); | ||
@@ -507,3 +507,3 @@ connectionRetries = 0; | ||
//Register for status updates | ||
client.getStatus(function(err, status){ | ||
client.getStatus(function (err, status) { | ||
updateStatus(status); | ||
@@ -516,3 +516,3 @@ }); | ||
function updateStatus(status){ | ||
function updateStatus(status) { | ||
/* | ||
@@ -544,11 +544,11 @@ * Example for Chromecast audio (plex) | ||
adapter.log.debug(name+' currentApplicationObject ' + JSON.stringify(status)); | ||
adapter.log.debug(name + ' currentApplicationObject ' + JSON.stringify(status)); | ||
//volume object seems to always be there | ||
adapter.setState(states.volume.name, {val: Math.round(status.volume.level*100), ack: true}); | ||
adapter.setState(states.volume.name, {val: Math.round(status.volume.level * 100), ack: true}); | ||
adapter.setState(states.muted.name, {val: status.volume.muted, ack: true}); | ||
//Video Chromecast-only | ||
adapter.setState(states.isActiveInput.name, {val: ("isActiveInput" in status? status.isActiveInput: true ), ack: true}); | ||
adapter.setState(states.isStandBy.name, {val: ("isStandBy" in status? status.isStandBy : false), ack: true}); | ||
adapter.setState(states.isActiveInput.name, {val: ("isActiveInput" in status ? status.isActiveInput: true), ack: true}); | ||
adapter.setState(states.isStandBy.name, {val: ("isStandBy" in status ? status.isStandBy : false), ack: true}); | ||
@@ -558,17 +558,17 @@ //if the Chromecast has an application running then try to attach DefaultMediaReceiver | ||
// It works fine with the TuneIn and Plex applications | ||
if ("applications" in status){ | ||
if ("applications" in status) { | ||
currentApplicationObject = status.applications[0]; | ||
//display name and status | ||
adapter.setState(states.displayName.name, {val: ("displayName" in currentApplicationObject? currentApplicationObject.displayName: "" ), ack: true}); | ||
adapter.setState(states.statusText.name, {val: ("statusText" in currentApplicationObject? currentApplicationObject.statusText: "" ), ack: true}); | ||
adapter.setState(states.displayName.name, {val: ("displayName" in currentApplicationObject ? currentApplicationObject.displayName: ""), ack: true}); | ||
adapter.setState(states.statusText.name, {val: ("statusText" in currentApplicationObject ? currentApplicationObject.statusText: ""), ack: true}); | ||
if (//(currentApplicationObject.appId == "MultizoneFollower") || | ||
(currentApplicationObject.appId == "MultizoneLeader")) { | ||
//adapter.log.info(name+' currentApplicationObject ' + JSON.stringify(status)); | ||
} else | ||
if (!connectedPlayer && !connectingPlayer) joinPlayer(); | ||
if (//(currentApplicationObject.appId != "MultizoneFollower") && | ||
(currentApplicationObject.appId != "MultizoneLeader")) { | ||
if (!connectedPlayer && !connectingPlayer) joinPlayer(); | ||
} //else | ||
//adapter.log.info(name + ' currentApplicationObject ' + JSON.stringify(status)); | ||
} else { | ||
currentApplicationObject = undefined | ||
currentApplicationObject = undefined; | ||
detachPlayer(); | ||
@@ -584,6 +584,6 @@ } | ||
function joinPlayer(){ | ||
if (!connectedClient){ | ||
function joinPlayer() { | ||
if (!connectedClient) { | ||
adapter.log.error(name + " - Cannot join player: client not connected!"); | ||
} else if (connectedPlayer){ | ||
} else if (connectedPlayer) { | ||
adapter.log.error(name + " - Cannot join player: player already connected!"); | ||
@@ -597,6 +597,6 @@ } else if (connectingPlayer) { | ||
DefaultMediaReceiver, | ||
function(err, p) { | ||
function (err, p) { | ||
connectingPlayer = false; | ||
if (err){ | ||
adapter.log.error(name+' failed to attach player: '+err); | ||
if (err) { | ||
adapter.log.error(name + ' failed to attach player: ' + err); | ||
} else { | ||
@@ -616,3 +616,3 @@ adapter.log.info(name + " - Attached player"); | ||
player.on("error", function (err) { | ||
adapter.log.error(name+" - Player - "+err); | ||
adapter.log.error(name + " - Player - " + err); | ||
detachPlayer(); | ||
@@ -623,7 +623,8 @@ }); | ||
player.on('status', updatePlayerStatus); | ||
player.getStatus(function(err, pStatus) { | ||
if (err) | ||
adapter.log.error(name+" - Player - "+err); | ||
else | ||
player.getStatus(function (err, pStatus) { | ||
if (err) { | ||
adapter.log.error(name + " - Player - " + err); | ||
} else { | ||
updatePlayerStatus(pStatus); | ||
} | ||
}); | ||
@@ -646,3 +647,3 @@ } | ||
//was already destroyed | ||
try{ | ||
try { | ||
player.removeListener('status', updatePlayerStatus); | ||
@@ -653,3 +654,3 @@ player.close(); | ||
currentApplicationObject = undefined; | ||
} catch(e){}; | ||
} catch (e) {} | ||
@@ -667,7 +668,7 @@ adapter.log.info(name + " - Detached player"); | ||
adapter.log.debug(name + " - Launching player"); | ||
else{ | ||
else { | ||
adapter.log.error(name + " - Cannot launchPlayer: no connection to client"); | ||
return; | ||
} | ||
if (connectingPlayer || connectedPlayer){ | ||
if (connectingPlayer || connectedPlayer) { | ||
if (DefaultMediaReceiver.APP_ID == currentApplicationObject.appId) { | ||
@@ -683,5 +684,5 @@ adapter.log.info(name + " - own player was already loaded"); | ||
connectingPlayer = true; | ||
client.launch(DefaultMediaReceiver, function(err, p) { | ||
client.launch(DefaultMediaReceiver, function (err, p) { | ||
if (err) { | ||
adapter.log.info(name+' failed to launch player: '+err); | ||
adapter.log.info(name + ' failed to launch player: ' + err); | ||
} else { | ||
@@ -694,4 +695,4 @@ adapter.log.info(name + " - Launched player"); | ||
player.on('status', updatePlayerStatus); | ||
player.getStatus(function(err, pStatus) { | ||
if (err) adapter.log.error(name+" - "+err); | ||
player.getStatus(function (err, pStatus) { | ||
if (err) adapter.log.error(name + " - " + err); | ||
updatePlayerStatus(pStatus); | ||
@@ -706,5 +707,5 @@ }); | ||
var getStatusTimeout = undefined; | ||
var cachedPlayerStatus = undefined; | ||
function updatePlayerStatus(pStatus){ | ||
var getStatusTimeout; | ||
var cachedPlayerStatus; | ||
function updatePlayerStatus(pStatus) { | ||
/* | ||
@@ -750,3 +751,3 @@ * {"mediaSessionId":2, | ||
*/ | ||
//adapter.log.info(name+' - Player status: ' + JSON.stringify(pStatus)); | ||
//adapter.log.info(name + ' - Player status: ' + JSON.stringify(pStatus)); | ||
@@ -773,4 +774,4 @@ //Player channel status | ||
setStateIfChanged(states.playerVolume.name, | ||
{val: Math.round(("volume" in status ? status.volume.level : 1)*100), ack: true}, | ||
Math.round(("volume" in cachedStatus ? cachedStatus.volume.level : 1)*100)); | ||
{val: Math.round(("volume" in status ? status.volume.level : 1) * 100), ack: true}, | ||
Math.round(("volume" in cachedStatus ? cachedStatus.volume.level : 1) * 100)); | ||
setStateIfChanged(states.playerMuted.name, | ||
@@ -801,4 +802,4 @@ {val: ("volume" in status ? status.volume.muted : false), ack: true}, | ||
//If contentId starts with http try to get media info | ||
if (playerState != "STOP" && contentId.indexOf("http") == 0) | ||
getMediaInfo(contentId, contentId, "LIVE", function(){}); | ||
if (playerState != "STOP" && contentId.indexOf("http") === 0) | ||
getMediaInfo(contentId, contentId, "LIVE", function () {}); | ||
@@ -826,9 +827,10 @@ //Metadata channel status | ||
if (getStatusTimeout) clearTimeout(getStatusTimeout); | ||
getStatusTimeout = setTimeout(function(){ | ||
if (connectingPlayer || connectedPlayer){ | ||
player.getStatus(function(err, pStatus) { | ||
if (err) | ||
adapter.log.error(name+" - "+err); | ||
else | ||
updatePlayerStatus(pStatus); | ||
getStatusTimeout = setTimeout(function () { | ||
if (connectingPlayer || connectedPlayer) { | ||
player.getStatus(function (err, pStatus) { | ||
if (err) { | ||
adapter.log.error(name + " - " + err); | ||
} else { | ||
updatePlayerStatus(pStatus); | ||
} | ||
}); | ||
@@ -839,3 +841,3 @@ } | ||
function setStateIfChanged(id, val, oldVal){ | ||
function setStateIfChanged(id, val, oldVal) { | ||
if (oldVal == val.val) | ||
@@ -845,15 +847,16 @@ //same value | ||
adapter.getState(id,function(err,state){ | ||
if (err) | ||
adapter.log.error(name+' - Could not get '+id+':'+err); | ||
else{ | ||
if (!state) | ||
adapter.getState(id, function (err, state) { | ||
if (err) { | ||
adapter.log.error(name + ' - Could not get ' + id + ':' + err); | ||
} else { | ||
if (!state) { | ||
adapter.setState(id, val); | ||
else if (val != state.val) | ||
} else if (val != state.val) { | ||
adapter.setState(id, val); | ||
else if ((val.val != state.val) || | ||
(val.ack != state.ack)){ | ||
} else if ((val.val != state.val) || | ||
(val.ack != state.ack)) { | ||
adapter.setState(id, val); | ||
} else | ||
adapter.log.debug(name+' - '+id+' value unchanged -> SKIP'); | ||
} else { | ||
adapter.log.debug(name + ' - ' + id + ' value unchanged -> SKIP'); | ||
} | ||
} | ||
@@ -871,5 +874,5 @@ | ||
function getMediaInfo(url2play, org_url2play, streamType, callback){ | ||
function getMediaInfo(url2play, org_url2play, streamType, callback) { | ||
//get connection | ||
connection = MediaInformation.getListener(name,url2play, org_url2play, streamType, callback); | ||
connection = MediaInformation.getListener(name, url2play, org_url2play, streamType, callback); | ||
@@ -893,3 +896,3 @@ //For all media updates update iobroker state | ||
function playURL(url2play, org_url2play, streamType){ | ||
function playURL(url2play, org_url2play, streamType) { | ||
if (connectedClient) { | ||
@@ -903,3 +906,3 @@ if (org_url2play === undefined) | ||
if (url2play.indexOf("http") != 0) { | ||
if (url2play.indexOf("http") !== 0) { | ||
//Not an http(s) URL -> assume local file | ||
@@ -909,4 +912,4 @@ adapter.log.info("Not a http(s) URL -> asume local file"); | ||
//Check that the webserver has been configured | ||
if (adapter.config.webServer == ""){ | ||
adapter.log.error(name + '- Sorry, cannot play file "' + url2play+'"'); | ||
if (adapter.config.webServer === "") { | ||
adapter.log.error(name + '- Sorry, cannot play file "' + url2play + '"'); | ||
adapter.log.error(name + '- Please configure webserver settings first!'); | ||
@@ -916,18 +919,18 @@ return; | ||
var exported_file_state = adapter.namespace+"."+states.exportedMedia.name; | ||
var exported_file_state = adapter.namespace + "." + states.exportedMedia.name; | ||
//Try to load in a local state | ||
try { | ||
adapter.setBinaryState(exported_file_state, fs.readFileSync(url2play),function(err){ | ||
if (err){ | ||
adapter.log.error(name+' - Cannot store file "' + url2play+' into '+exported_file_state+'": ' + e.toString()); | ||
return | ||
adapter.setBinaryState(exported_file_state, fs.readFileSync(url2play), function (err) { | ||
if (err) { | ||
adapter.log.error(name + ' - Cannot store file "' + url2play + ' into ' + exported_file_state + '": ' + e.toString()); | ||
return; | ||
} | ||
//Calculate the exported URL | ||
url2play = 'http://'+adapter.config.webServer+':8082/state/'+exported_file_state; | ||
adapter.log.info("Exported as "+url2play); | ||
url2play = 'http://' + adapter.config.webServer + ':8082/state/' + exported_file_state; | ||
adapter.log.info("Exported as " + url2play); | ||
playURL(url2play, org_url2play, 'BUFFERED'); | ||
}); | ||
} catch (e) { | ||
adapter.log.error(name+' - Cannot play file "' + url2play+'": ' + e.toString()); | ||
adapter.log.error(name + ' - Cannot play file "' + url2play + '": ' + e.toString()); | ||
} | ||
@@ -938,5 +941,5 @@ return; | ||
//get media info | ||
getMediaInfo(url2play, org_url2play, streamType, function(mediaInfo){ | ||
getMediaInfo(url2play, org_url2play, streamType, function (mediaInfo) { | ||
//launch player | ||
launchPlayer(function(){ | ||
launchPlayer(function () { | ||
//load media | ||
@@ -947,14 +950,14 @@ loadMedia(mediaInfo); | ||
} else | ||
adapter.log.error(name+' - cannot play URL: disconnected from Chromecast'); | ||
} else { | ||
adapter.log.error(name + ' - cannot play URL: disconnected from Chromecast'); | ||
} | ||
function loadMedia(media){ | ||
player.load(media, { autoplay: true }, function(err, status) { | ||
if (err){ | ||
adapter.log.error(name+' - media loaded err=%s', err); | ||
function loadMedia(media) { | ||
player.load(media, {autoplay: true}, function (err, status) { | ||
if (err) { | ||
adapter.log.error(name + ' - media loaded err=%s', err); | ||
detachPlayer(); | ||
}else { | ||
adapter.log.info(name + " - Playing "+org_url2play); | ||
} else { | ||
adapter.log.info(name + " - Playing " + org_url2play); | ||
//ACK after we successfully started playing | ||
@@ -974,3 +977,3 @@ adapter.setState(states.url2play.name, {val: org_url2play, ack: true}); | ||
// Warning, state can be null if it was deleted | ||
adapter.log.debug(name+' - device stateChange ' + id + ' ' + JSON.stringify(state)); | ||
adapter.log.debug(name + ' - device stateChange ' + id + ' ' + JSON.stringify(state)); | ||
@@ -981,4 +984,4 @@ // you can use the ack flag to detect if it is status (true) or command (false) | ||
//Is connected? | ||
if (id.indexOf(adapter.namespace+"."+states.connected.name) === 0){ | ||
adapter.log.warn(name+' - reconnecting as requested by '+state.from); | ||
if (id.indexOf(adapter.namespace + "." + states.connected.name) === 0) { | ||
adapter.log.warn(name + ' - reconnecting as requested by ' + state.from); | ||
connectionRetries = 0; | ||
@@ -988,54 +991,77 @@ reconnectClient(); | ||
//Is volume? | ||
else if (id.indexOf(adapter.namespace+"."+states.volume.name) === 0){ | ||
else if (id.indexOf(adapter.namespace + "." + states.volume.name) === 0) { | ||
if (connectedClient) { | ||
client.setVolume({level: (state.val/100)}, function(err,volume){ | ||
if (err) adapter.log.error(name+" - "+err); | ||
client.setVolume({level: (state.val / 100)}, function (err, volume) { | ||
if (err) adapter.log.error(name + " - " + err); | ||
//ACK written when status update sent by Chromecast | ||
}); | ||
} else | ||
adapter.log.error(name+' - cannot set volume: disconnected from Chromecast'); | ||
} else { | ||
adapter.log.error(name + ' - cannot set volume: disconnected from Chromecast'); | ||
} | ||
} | ||
//Is muted? | ||
else if (id.indexOf(adapter.namespace+"."+states.muted.name) === 0){ | ||
else if (id.indexOf(adapter.namespace + "." + states.muted.name) === 0) { | ||
if (connectedClient) { | ||
client.setVolume({muted: state.val}, function(err,volume){ | ||
client.setVolume({muted: state.val}, function (err, volume) { | ||
if (err) adapter.log.error(name+" - "+err); | ||
if (err) adapter.log.error(name + " - " + err); | ||
//ACK written when status update sent by Chromecast | ||
}); | ||
} else | ||
adapter.log.error(name+' - cannot (un)mute: disconnected from Chromecast'); | ||
} else { | ||
adapter.log.error(name + ' - cannot (un)mute: disconnected from Chromecast'); | ||
} | ||
} | ||
//Is playing? | ||
else if (id.indexOf(adapter.namespace+"."+states.playing.name) === 0){ | ||
else if (id.indexOf(adapter.namespace + "." + states.playing.name) === 0) { | ||
if (connectedClient) { | ||
if (!state.val) client.stop(player, function(err){ | ||
if (err) adapter.log.error(name+" - "+err); | ||
//ACK written when status update sent by Chromecast | ||
}); | ||
} else | ||
adapter.log.error(name+' - cannot stop: disconnected from Chromecast'); | ||
if (state.val) { | ||
//Try to play last contentID | ||
adapter.getState(states.contentId.name, function (err, state) { | ||
if (state && state.val && state.val.startsWith("http")) { | ||
playURL(state.val); | ||
} else { | ||
//Try to play last url2play | ||
adapter.getState(states.url2play.name, function (err, state) { | ||
if (state && state.val && state.val.startsWith("http")) { | ||
playURL(state.val); | ||
} else { | ||
//Could not find a valid link to play -> set to false again | ||
adapter.setState(id, false); | ||
} | ||
}); | ||
} | ||
}); | ||
} else { | ||
//Disconnect client | ||
client.stop(player, function (err) { | ||
if (err) adapter.log.error(name + " - " + err); | ||
//ACK written when status update sent by Chromecast | ||
}); | ||
} | ||
} else { | ||
adapter.log.error(name + ' - cannot play/stop: disconnected from Chromecast'); | ||
} | ||
} | ||
//Is paused? | ||
else if (id.indexOf(adapter.namespace+"."+states.paused.name) === 0){ | ||
else if (id.indexOf(adapter.namespace + "." + states.paused.name) === 0) { | ||
if (connectedPlayer) { | ||
if (state.val) | ||
player.pause(function(){}); | ||
else | ||
player.play(function(){}); | ||
if (state.val) { | ||
player.pause(function () {}); | ||
} else { | ||
player.play(function () {}); | ||
} | ||
//ACK written when status update sent by Chromecast | ||
}else | ||
adapter.log.error(name+' - cannot pause: Chromecast not playing'); | ||
} else { | ||
adapter.log.error(name + ' - cannot pause: Chromecast not playing'); | ||
} | ||
} | ||
//Is url2play? | ||
else if (id.indexOf(adapter.namespace+"."+states.url2play.name) === 0){ | ||
else if (id.indexOf(adapter.namespace + "." + states.url2play.name) === 0) { | ||
playURL(state.val); | ||
} else { | ||
adapter.log.error(name + ' - Sorry, update for ' + id + ' not supported!'); | ||
} | ||
else | ||
adapter.log.error(name+' - Sorry, update for '+id+' not supported!'); | ||
}; | ||
}; | ||
}; | ||
} | ||
} | ||
} | ||
}; | ||
@@ -1045,2 +1071,2 @@ | ||
module.exports = ChromecastDevice; | ||
module.exports = ChromecastDevice; |
//SSDP Scanner | ||
var ssdp = require('node-ssdp').Client; | ||
var http = require('http'); | ||
function ssdp_scan(callback){ | ||
function ssdp_scan(callback) { | ||
@@ -10,10 +10,10 @@ var ssdpBrowser = new ssdp(); | ||
return; | ||
if (!headers['LOCATION']) | ||
if (!headers.LOCATION) | ||
return; | ||
var request = http.get(headers['LOCATION'], function(res) { | ||
var request = http.get(headers.LOCATION, function (res) { | ||
var body = ''; | ||
res.on('data', function(chunk) { | ||
res.on('data', function (chunk) { | ||
body += chunk; | ||
}); | ||
res.on('end', function() { | ||
res.on('end', function () { | ||
if (body.search('<manufacturer>Google Inc.</manufacturer>') == -1) | ||
@@ -47,3 +47,3 @@ return; | ||
var txt = require('mdns-txt')(); | ||
function mdsn_scan(cb_new, scan_interval, cb_update){ | ||
function mdsn_scan(cb_new, scan_interval, cb_update) { | ||
var m = mdns(); | ||
@@ -53,13 +53,13 @@ | ||
var onResponse = function(response) { | ||
var onResponse = function (response) { | ||
var txt_field = find(response.additionals, function(entry) { | ||
var txt_field = find(response.additionals, function (entry) { | ||
return entry.type === 'TXT'; | ||
}); | ||
var srv_field = find(response.additionals, function(entry) { | ||
var srv_field = find(response.additionals, function (entry) { | ||
return entry.type === 'SRV'; | ||
}); | ||
var a_field = find(response.additionals, function(entry) { | ||
var a_field = find(response.additionals, function (entry) { | ||
return entry.type === 'A'; | ||
@@ -95,3 +95,3 @@ }); | ||
//First time we see this device | ||
found_devices[name]={ | ||
found_devices[name] = { | ||
ip: ip, | ||
@@ -103,6 +103,6 @@ port: port | ||
} | ||
} | ||
}; | ||
m.on('response', onResponse); | ||
function sendQuery(){ | ||
function sendQuery() { | ||
//console.log("Sending query"); | ||
@@ -123,8 +123,9 @@ m.query({ | ||
function chromecastScanner(useSSDP, cb_new, scan_interval, cb_update) { | ||
if (useSSDP) | ||
if (useSSDP) { | ||
ssdp_scan(cb_new); | ||
else | ||
} else { | ||
mdsn_scan(cb_new, scan_interval, cb_update); | ||
} | ||
} | ||
module.exports = chromecastScanner; |
@@ -16,3 +16,3 @@ /* | ||
const DISCOVER_ICY_METADATA = true; | ||
var DISCOVER_ICY_METADATA = true; | ||
@@ -44,20 +44,20 @@ var Connection = function (url2play, org_url2play, streamType, callback) { | ||
try{ | ||
try { | ||
this._requestObject = icy.get(url2play, this._connected.bind(this)); | ||
this._requestObject.on('error', function(e){ | ||
console.log("MediaInformation - ICY connection error for "+this._url2play+": "+e); | ||
this._requestObject.on('error', function (e) { | ||
console.log("MediaInformation - ICY connection error for " + this._url2play + ": " + e); | ||
}); | ||
} catch(e){ | ||
console.log("MediaInformation - Cannot connect to "+this._url2play+": "+e); | ||
} catch (e) { | ||
console.log("MediaInformation - Cannot connect to " + this._url2play + ": " + e); | ||
} | ||
} | ||
}; | ||
util.inherits(Connection, EventEmitter); | ||
Connection.prototype.getMedia = function() { | ||
Connection.prototype.getMedia = function () { | ||
return this._media; | ||
}; | ||
Connection.prototype.close = function() { | ||
if (this._requestObject){ | ||
Connection.prototype.close = function () { | ||
if (this._requestObject) { | ||
this._requestObject.abort(); | ||
@@ -68,4 +68,4 @@ } | ||
Connection.prototype._connected = function(res){ | ||
console.log("MediaInformation - Connected to "+this._url2play); | ||
Connection.prototype._connected = function (res) { | ||
console.log("MediaInformation - Connected to " + this._url2play); | ||
/* | ||
@@ -98,4 +98,4 @@ * Example from http://edge.live.mp3.mdn.newmedia.nacamar.net/ps-dieneue_rock/livestream_hi.mp3 | ||
res.headers["content-type"] && | ||
((res.headers["content-type"].indexOf("audio") >=0) || | ||
(res.headers["content-type"].indexOf("video") >=0))) | ||
((res.headers["content-type"].indexOf("audio") >= 0) || | ||
(res.headers["content-type"].indexOf("video") >= 0))) | ||
this._media.contentType = res.headers["content-type"]; | ||
@@ -107,5 +107,5 @@ //console.log(this._media); | ||
//first metadata in less than 1 second | ||
this._timeoutHandler = setTimeout(function(){ | ||
this._timeoutHandler = setTimeout(function () { | ||
this._callback(this._media); | ||
},1000); | ||
}, 1000); | ||
@@ -119,7 +119,7 @@ // log any "metadata" events that happen | ||
} | ||
}; | ||
Connection.prototype._gotMetadata = function(res, metadata) { | ||
Connection.prototype._gotMetadata = function (res, metadata) { | ||
/* | ||
@@ -136,3 +136,3 @@ * { StreamTitle: 'BILLY IDOL - WHITE WEDDING', | ||
//If we got media info then call callback already | ||
if (this._timeoutHandler){ | ||
if (this._timeoutHandler) { | ||
clearTimeout(this._timeoutHandler); | ||
@@ -146,3 +146,3 @@ this._timeoutHandler = undefined; | ||
if (!this._pipeOn){ | ||
if (!this._pipeOn) { | ||
//We need to keep reading in order to receive additional metadata | ||
@@ -160,6 +160,6 @@ //We do it here to avoid reading data for sources that do not send | ||
function getMediaInfoListerner(callerId, url2play, org_url2play, streamType, callback){ | ||
function getMediaInfoListerner(callerId, url2play, org_url2play, streamType, callback) { | ||
if (url2play in activeConnections && | ||
callerId in activeConnections[url2play].callerIDs){ | ||
callerId in activeConnections[url2play].callerIDs) { | ||
@@ -182,3 +182,3 @@ //Call callback | ||
connection: connection | ||
} | ||
}; | ||
} | ||
@@ -193,4 +193,4 @@ | ||
function closeMediaInfoListerner(callerId){ | ||
for (var url2play in activeConnections){ | ||
function closeMediaInfoListerner(callerId) { | ||
for (var url2play in activeConnections) { | ||
@@ -202,3 +202,3 @@ //Set this callerId as inactive | ||
var anyListenerActive = false; | ||
for (var i in activeConnections[url2play].callerIDs){ | ||
for (var i in activeConnections[url2play].callerIDs) { | ||
anyListenerActive |= activeConnections[url2play].callerIDs[i]; | ||
@@ -210,5 +210,5 @@ } | ||
activeConnections[url2play].connection.close(); | ||
activeConnections[url2play].callerIDs=undefined; | ||
console.log("Disconnect "+url2play); | ||
console.log("Last listener was "+callerId); | ||
activeConnections[url2play].callerIDs = undefined; | ||
console.log("Disconnect " + url2play); | ||
console.log("Last listener was " + callerId); | ||
delete activeConnections[url2play]; | ||
@@ -215,0 +215,0 @@ } |
{ | ||
"name": "iobroker.chromecast", | ||
"version": "0.2.1", | ||
"version": "1.0.0", | ||
"description": "ioBroker chromecast Adapter", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -66,2 +66,6 @@ ![Logo](admin/chromecast.png) | ||
### 0.2.2 | ||
* (Vegetto) Try to play last played URL when setting playing state to true | ||
* (Vegetto) Fix jshint and jscs findings | ||
### 0.2.1 | ||
@@ -68,0 +72,0 @@ * (Vegetto) Update readme |
/* | ||
ioBroker.chromecast Widget-Set | ||
version: "0.2.1" | ||
version: "1.0.0" | ||
@@ -142,3 +142,3 @@ Copyright 10.2015-2016 Vegetto<iobroker@angelnu.com> | ||
vis.binds.chromecast = { | ||
version: "0.2.1", | ||
version: "1.0.0", | ||
showVersion: function () { | ||
@@ -145,0 +145,0 @@ if (vis.binds.chromecast.version) { |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
104479
1571
0
129