castv2-player
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -31,2 +31,9 @@ "use strict" | ||
}) | ||
//playAnnouncementPromise again | ||
.then( function () { | ||
return mediaPlayer.playAnnouncementPromise(JSON.stringify({ | ||
url: defines.urls.shortSingle, | ||
volume: 50, | ||
})); | ||
}) | ||
//Final checks | ||
@@ -33,0 +40,0 @@ .then (function () { |
@@ -84,2 +84,3 @@ "use strict" | ||
setVolumePromise(volume) { | ||
return this._client.setVolumePromise(volume); | ||
@@ -86,0 +87,0 @@ } |
@@ -34,2 +34,3 @@ "use strict" | ||
that._connectClient(); | ||
}; | ||
@@ -73,2 +74,7 @@ | ||
if (volume == that.getVolume()) { | ||
log.info("%s - setting volume to same value %s - ignored", that._name, volume); | ||
return Promise.resolve(volume); | ||
} | ||
return that._getConnectedClientPromise() | ||
@@ -75,0 +81,0 @@ .then (function (client) {return that._setVolumePromise (client, volume);}); |
@@ -266,29 +266,32 @@ "use strict" | ||
let appendedItemIds = []; | ||
//Remember current position | ||
let chunkItemIds = []; | ||
//Remember information on the current track position | ||
let currentTime = that.getStatus().currentTime; | ||
let currentVolume = that._client.getVolume(); | ||
let currentURL = that.getStatus().media.contentId; | ||
let mediaDuration = that.getStatus().media.duration; | ||
let optionsPlaylistResume = {}; | ||
if (mediaDuration && currentTime && currentTime <= mediaDuration) | ||
optionsPlaylistResume.startTime = currentTime; | ||
let currentDuration = that.getStatus().media.duration; | ||
// Objective: current -> announcement -> remaining current (if not streaming)-> (nextItem) | ||
let playingStreaming = !(mediaDuration > 0); | ||
let playingStreaming = !(currentDuration > 0); | ||
//Calculate next element | ||
//Calculate next track | ||
let nextItem; | ||
if (!playingStreaming){ | ||
if (playingStreaming){ | ||
nextItem = that.getCurrentPlaylistId(); //In streaming we come back to the current playlist | ||
} else { | ||
let nextItemIndex = that._playlist.getIndexForId(that.getCurrentPlaylistId()) + 1; | ||
nextItem = that._playlist.getItemWithIndex(nextItemIndex); | ||
} else { | ||
nextItem = that.getCurrentPlaylistId(); | ||
} | ||
//If we are not streaming we add the current track again with the start set to the current location | ||
let remainingPromise = Promise.resolve([]); | ||
if (!playingStreaming) { | ||
let optionsPlaylistResume = {}; | ||
//if (currentDuration && currentTime && currentTime <= currentDuration) | ||
optionsPlaylistResume.startTime = currentTime; | ||
//First we add it locally | ||
remainingPromise = that._playlist.insertPromise(currentURL, optionsPlaylistResume, true) | ||
//Insert the remaining time of the current playing item after the current item | ||
// First: insert in current playlist class | ||
.then (function (items) { | ||
@@ -298,3 +301,3 @@ | ||
let optionsResume = {}; | ||
if (mediaDuration && currentTime && currentTime <= mediaDuration) | ||
if (currentDuration && currentTime && currentTime <= currentDuration) | ||
optionsResume.startTime = currentTime; | ||
@@ -311,15 +314,11 @@ if (nextItem) | ||
//Remember that we have to delete this item (in case it was added) | ||
appendedItemIds = appendedItemIds.concat(itemIds); | ||
//Remember that we have to delete the chunk (if we are not streaming) | ||
chunkItemIds = itemIds; | ||
//Now we can insert the actual announcement | ||
return that._playlist.insertPromise(url, options, true) | ||
.then (function (items) { | ||
return Promise.resolve({items:items, insertedRemainingId: itemIds[0]}); | ||
}); | ||
}) | ||
//Insert into playlist after current | ||
.then (function (values) { | ||
let items = values.items; | ||
let insertedRemainingId = values.insertedRemainingId; | ||
//First locally | ||
return that._playlist.insertPromise(url, options, true); | ||
}) | ||
.then (function (items) { | ||
@@ -329,25 +328,24 @@ //Insert into playlist and start playing | ||
optionsAnnouncement.currentItemIndex = 0; | ||
optionsAnnouncement.insertBefore = insertedRemainingId ? insertedRemainingId : that.getCurrentPlaylistId(); | ||
optionsAnnouncement.insertBefore = playingStreaming ? that.getCurrentPlaylistId() : chunkItemIds[0]; | ||
//Set volume if required | ||
let urlPromise = Promise.resolve(); | ||
if (urlOptions.volume) { | ||
urlPromise = that._client.setVolumePromise(urlOptions.volume); | ||
} | ||
log.debug("%s - Inserting announcement into playlist - %s", that._name, url); | ||
return urlPromise | ||
.then (function() { return that.insertIntoPlaylistPromise(items, optionsAnnouncement); }); | ||
//Second: send it to the Chromecast | ||
return that.insertIntoPlaylistPromise(items, optionsAnnouncement); | ||
}) | ||
.then (function (anouncementIds) { | ||
//Set volume if required - we do it here to avoid a peak in the volume with the currently playing track | ||
if (urlOptions.volume) { | ||
that._client.setVolumePromise(urlOptions.volume); | ||
} | ||
//Wait for the remaining current to start playing in order to remove the announcement and resume the volume | ||
return new Promise(function (resolve, reject) { | ||
//log.info("%s - Announcement playing:\n%s",that._name, util.inspect(that.getStatus(),{depth:null})); | ||
//resumeAfterAnnouncement <- It will be called on every status update | ||
let resumeAfterAnnouncement = function (status) { | ||
if (anouncementIds.length > 0 && anouncementIds.indexOf(that.getCurrentPlaylistId()) < 0) | ||
{ | ||
//The item after the announcement has starting buffering -> reset volume | ||
//Restore original volume if required | ||
//The item after the announcement has starting buffering -> restore original volume if required | ||
if (urlOptions && urlOptions.volume) { | ||
@@ -373,4 +371,6 @@ that._client.setVolumePromise(currentVolume); | ||
( | ||
(nextItem && that.getCurrentPlaylistId() == nextItem.itemId && that.getStatus().playerState != "BUFFERING") || | ||
appendedItemIds.length === 0 | ||
//Did we insert a chunk? | ||
chunkItemIds.length === 0 || | ||
//Next item started playing ? | ||
(nextItem && that.getCurrentPlaylistId() == nextItem.itemId && that.getStatus().playerState != "BUFFERING") | ||
) | ||
@@ -381,4 +381,4 @@ ) | ||
log.info ("%s - Back to regular playlist", that._name); | ||
if (appendedItemIds.length > 0) | ||
that.removeFromPlaylistPromise(appendedItemIds); | ||
if (chunkItemIds.length > 0) | ||
that.removeFromPlaylistPromise(chunkItemIds); | ||
@@ -391,3 +391,3 @@ //We are done | ||
//Sanity check - if all items disapear then this means that a new playlist was loaded | ||
let idsToCheck=anouncementIds.concat(appendedItemIds); | ||
let idsToCheck=anouncementIds.concat(chunkItemIds); | ||
let allGone = true; | ||
@@ -406,3 +406,3 @@ | ||
//Not the status updated we are waiting for | ||
//Not the status update we are waiting for | ||
} | ||
@@ -409,0 +409,0 @@ |
@@ -13,6 +13,7 @@ "use strict" | ||
class Device { | ||
constructor (name, host, port){ | ||
constructor (name, host, port, type){ | ||
this.name = name; | ||
this.host = host; | ||
this.port = port; | ||
this.type = type; //'Chromecast','Chromecast Audio','Google Cast Group' | ||
} | ||
@@ -23,2 +24,10 @@ | ||
} | ||
isGroup () { | ||
return (type == 'Google Cast Group'); | ||
} | ||
isAudio () { | ||
return (type == 'Chromecast Audio'); | ||
} | ||
} | ||
@@ -64,5 +73,6 @@ | ||
var host = a_field.data; | ||
var name = txt.decode(txt_field.data).fn; | ||
var decoded_txt = txt.decode(txt_field.data); | ||
var name = decoded_txt.fn; | ||
var type = decoded_txt.md; //'Chromecast','Chromecast Audio','Google Cast Group' | ||
var port = srv_field.data.port; | ||
if (!host || !name || !port) { | ||
@@ -82,3 +92,3 @@ return; | ||
old_device.port = port; | ||
log.debug('updated device "%s" at %s:%d', name, host, port); | ||
log.debug('updated device %s (%s) at %s:%d', name, type, host, port); | ||
if (old_device.cb_update) { | ||
@@ -91,5 +101,5 @@ //Call callback and update it with return value | ||
//First time we see this device | ||
found_devices[name] = new Device(name, host, port); | ||
found_devices[name] = new Device(name, host, port, type); | ||
if (cb_new) { | ||
log.debug('found device %s at %s:%d', name, host, port); | ||
log.debug('found device %s (%s) at %s:%d', name, type, host, port); | ||
cb_new(found_devices[name]); | ||
@@ -96,0 +106,0 @@ } |
{ | ||
"name": "castv2-player", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A Chromecast client based on the new (CASTV2) protocol", | ||
@@ -5,0 +5,0 @@ "author": "angelnu", |
79798
2077