Skip to content

Commit

Permalink
fix: Avoid getting properties from unavailable player (#36)
Browse files Browse the repository at this point in the history
It makes no sense asking for playerid=1 if it doesn't exist.
Furthermore, it makes Kodi return:
"""
{"error":{"code":-32100,"message":"Failed to execute method."},"id":2,"jsonrpc":"2.0"}
"""
which makes the entire context menu fail and show only an error.

Fixes: #34
  • Loading branch information
pespin committed Nov 8, 2020
1 parent ed337ba commit f9c0536
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/core/jsonrpc/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const Player = class {
const players = await this.kodi.send("Player.GetActivePlayers");
// Ne pas demander les propriétés du lecteur vidéo quand un autre
// lecteur est actif. https://github.com/xbmc/xbmc/issues/17897
if (0 === players.length || players.some((p) => 1 === p.playerid)) {
if (players.some((p) => 1 === p.playerid)) {
const results = await this.kodi.send("Player.GetProperties", {
playerid: 1,
properties,
Expand Down
20 changes: 7 additions & 13 deletions test/unit/core/jsonrpc/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,18 @@ describe("core/jsonrpc/player.js", function () {
const properties = ["foo", "baz", "quz", "time", "totaltime"];
const result = await player.getProperties(properties);
assert.deepStrictEqual(result, {
foo: "bar",
baz: 42,
qux: true,
time: 3723,
position: -1,
repeat: "off",
shuffled: false,
speed: 0,
time: 0,
totaltime: 0,
});

assert.strictEqual(fake.callCount, 2);
assert.strictEqual(fake.callCount, 1);
assert.deepStrictEqual(fake.firstCall.args, [
"Player.GetActivePlayers",
]);
assert.deepStrictEqual(fake.secondCall.args, [
"Player.GetProperties",
{
playerid: 1,
properties: ["foo", "baz", "quz", "time", "totaltime"],
},
]);
});

it("should return properties when video player is active",
Expand Down Expand Up @@ -118,7 +112,7 @@ describe("core/jsonrpc/player.js", function () {
const fake = sinon.fake((method) => {
switch (method) {
case "Player.GetActivePlayers":
return Promise.resolve([]);
return Promise.resolve([{ playerid: 1 }]);
case "Player.GetProperties":
return Promise.resolve({ foo: "bar" });
default:
Expand Down

0 comments on commit f9c0536

Please sign in to comment.