Skip to content

Commit

Permalink
v0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zefau authored Oct 28, 2019
1 parent 702610e commit fc213f1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions plex.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let retryCycle, refreshCycle;

let encryptionKey;
let plex, plexAuth, tautulli, data;
let players = [], playing = [];
let players = [], playing = [], streams = 0;
let history = [];
let notifications = {};
let upload = _multer({ dest: '/tmp/' });
Expand Down Expand Up @@ -283,6 +283,8 @@ function testConnection()
library.setDeviceState(state.replace(adapterName + '.' + adapter.instance + '.', ''), states[state] && states[state].val);

library.clearPromiseListener();
playing = library.getDeviceState('_playing.players') && library.getDeviceState('_playing.players').split(',') || [];
streams = library.getDeviceState('_playing.streams') || 0;
});

// verify Tautulli settings
Expand Down Expand Up @@ -361,13 +363,19 @@ function setEvent(data, source, prefix)
// index current playing players
if (data.event && data.Player && data.Player.title)
{
if (['media.play', 'media.resume'].indexOf(data.event) > -1 && playing.indexOf(data.Player.title) == -1)
playing.push(data.Player.title);

if (['media.stop', 'media.pause'].indexOf(data.event) > -1)
if (['media.play', 'media.resume'].indexOf(data.event) > -1)
{
if (playing.indexOf(data.Player.title) == -1) playing.push(data.Player.title);
streams++;
}
else if (['media.stop', 'media.pause'].indexOf(data.event) > -1)
{
playing = playing.filter(player => player !== data.Player.title);
streams > 0 && streams--;
}

library.set({node: '_playing.playing', role: 'text', type: 'string', description: 'Players currently playing'}, playing.join(','));
library.set({node: '_playing.players', role: 'text', type: 'string', description: 'Players currently playing'}, playing.join(','));
library.set({node: '_playing.streams', role: 'value', type: 'number', description: 'Number of players currently playing'}, streams);
}

// add player controls
Expand Down

0 comments on commit fc213f1

Please sign in to comment.