Skip to content

Commit

Permalink
MPRIS Plugin: don't export players unless they're in the playerList
Browse files Browse the repository at this point in the history
Occasionally kdeconnect-android will send player updates for recently
destroyed players. Instead of creating players when we receive their
state, create and destroy stub players based on the list we receive and
ignore updates for players not in the list.

fixes #830
  • Loading branch information
andyholmes committed Apr 26, 2020
1 parent ef766c8 commit a568f12
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/service/plugins/mpris.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,24 @@ var Plugin = GObject.registerClass({
* @param {array} playerList - A list of remote player names
*/
_handlePlayerList(playerList) {
// First destroy removed players
for (let player of this._players.values()) {
if (!playerList.includes(player.Identity)) {
this._players.delete(player.Identity);
player.destroy();
}
}

// Then add new players before requesting their state
for (let identity of playerList) {
this._device.sendPacket({
if (!this._players.has(identity)) {
this._players.set(
identity,
new RemotePlayer(this.device, identity)
);
}

this.device.sendPacket({
type: 'kdeconnect.mpris.request',
body: {
player: identity,
Expand All @@ -129,10 +138,7 @@ var Plugin = GObject.registerClass({
_handlePlayerState(state) {
let player = this._players.get(state.player);

if (player === undefined) {
player = new RemotePlayer(this.device, state);
this._players.set(state.player, player);
} else {
if (player !== undefined) {
player.parseState(state);
}
}
Expand Down Expand Up @@ -513,18 +519,17 @@ var RemotePlayer = GObject.registerClass({
}
}, class RemotePlayer extends GObject.Object {

_init(device, initialState) {
_init(device, identity) {
super._init();

this._device = device;
this._Identity = identity;
this._isPlaying = false;

this._ownerId = 0;
this._connection = null;
this._applicationIface = null;
this._playerIface = null;

this.parseState(initialState);
}

async export() {
Expand Down

0 comments on commit a568f12

Please sign in to comment.