JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC

  Thread Rating:
  • 8 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Montellese Offline
Team-XBMC Developer
Posts: 3,848
Joined: Jan 2009
Reputation: 36
Location: Switzerland
Post: #1891
Tuesday, May 1st 2012:
Commit: 5cc59fd88149927ae708
  • added "lastplayed" property for songs

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
Mizaki Offline
Fan
Posts: 726
Joined: Apr 2011
Reputation: 14
Post: #1892
With streaming audio the skins can pick up additional information (such as artist and song name). Is it possible to make that available? Atm all you get is the name of the stream as the label.

[Image: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
find quote
Montellese Offline
Team-XBMC Developer
Posts: 3,848
Joined: Jan 2009
Reputation: 36
Location: Switzerland
Post: #1893
With what version of XBMC and the JSON-RPC API did you try this? I added the following commit a while back which should provide more info for non-library items through Player.GetItem: https://github.com/xbmc/xbmc/commit/73fd...32648b3110

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
Mizaki Offline
Fan
Posts: 726
Joined: Apr 2011
Reputation: 14
Post: #1894
This is in Eden. I just tried it in Frodo and get the same. For reference:
Code:
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": 1}
Code:
{"id":1,"jsonrpc":"2.0","result":{"item":{"fanart":"special://masterprofile/Thumbnails/Video/Fanart/515043c5.tbn","file":"shout://streamer-dtc-aa01.somafm.com:80/stream/1018","label":"SomaFM Groove Salad","thumbnail":"","title":"","type":"unknown"}}}

[Image: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
find quote
Montellese Offline
Team-XBMC Developer
Posts: 3,848
Joined: Jan 2009
Reputation: 36
Location: Switzerland
Post: #1895
Friday, May 4th 2012:
Commit: 0bd7924d87f00059a9b4
  • added SetArtistDetails, SetAlbumDetails and SetSongDetails to the AudioLibrary namespace
  • added SetMovieDetails, SetTVShowDetails. SetEpisodeDetails and SetMusicVideoDetails to the VideoLibrary namespace
  • added RemoveMovie, RemoveTVShow, RemoveEpisode and RemoveMusicVideo to the VideoLibrary namespace

I'll update the wiki page on JSON-RPC API v5 ASAP but make sure to take a close look at the JSON schema for the SetFooDetails methods so you don't mess up your (and possibly other people's) libraries Wink

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
Mizaki Offline
Fan
Posts: 726
Joined: Apr 2011
Reputation: 14
Post: #1896
Nice. Fingers crossed for webserver: image transformation handler soon Smile

I'm using Frodo with Firefox and I think the Content-Type change has broken things. It appears that Firefox adds "; charset=UTF-8" to the Content-Type. Bug report. Chrome and IE don't do this and all the JSONRPC requests work fine. Same thing in Firefox gives:
Code:
NetworkError: 415 Unsupported Media Type
from FireBug. Anything you can do on the web server end because Mozilla won't?

Did you get a chance to check on the details of audio web streams whilst I'm here?

[Image: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
find quote
Montellese Offline
Team-XBMC Developer
Posts: 3,848
Joined: Jan 2009
Reputation: 36
Location: Switzerland
Post: #1897
(2012-05-04 18:06)Mizaki Wrote:  Nice. Fingers crossed for webserver: image transformation handler soon Smile
jmarshall claimed that PR and will adjust it's implementation so might still be a while.

(2012-05-04 18:06)Mizaki Wrote:  I'm using Frodo with Firefox and I think the Content-Type change has broken things. It appears that Firefox adds "; charset=UTF-8" to the Content-Type. Bug report. Chrome and IE don't do this and all the JSONRPC requests work fine. Same thing in Firefox gives:
Code:
NetworkError: 415 Unsupported Media Type
from FireBug. Anything you can do on the web server end because Mozilla won't?
Should be fixed with https://github.com/xbmc/xbmc/commit/75fd...cb9784be76

(2012-05-04 18:06)Mizaki Wrote:  Did you get a chance to check on the details of audio web streams whilst I'm here?
As I don't use any audio web streams or similar addons it always takes me a while to look into those things.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
Mizaki Offline
Fan
Posts: 726
Joined: Apr 2011
Reputation: 14
Post: #1898
That's great, thanks. I don't use them either but Martijn was bugging me Smile

[Image: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
find quote
sjroesink Offline
Junior Member
Posts: 4
Joined: May 2012
Reputation: 0
Post: #1899
I'm having trouble finding out how the websocket functionality works.
Maybe it lacks documentation because websocket support is pretty new (and maybe unstable), but it would be great if someone could point me in the right direction.

Thusfar I've got the following:

Code:
var xbmcSocket = new WebSocket('ws://localhost:9090/jsonrpc');
xbmcSocket.onopen = function() {
    console.log('xbmcSocket.open');
};
xbmcSocket.onmessage = function(msg) {
    console.log('xbmcSocket.onmessage', msg);
};
So far so good: I now receive XBMC events.

Now I would also like to send commands using the websocket. So my initial though was:
Code:
xbmcSocket.send({
    "id": 1,
    "jsonrpc": "2.0",
    "method": "JSONRPC.Introspect"
});
However, this gives the following parse error:
Code:
{
    "error": {
        "code": -32700,
        "message": "Parse error."
    },
    "id": null,
    "jsonrpc": "2.0"
}
find quote
Montellese Offline
Team-XBMC Developer
Posts: 3,848
Joined: Jan 2009
Reputation: 36
Location: Switzerland
Post: #1900
You are probably the first to try and use the new websocket functionality (after me) so first thanks for the feedback. Have you tried other JSON-RPC methods like JSONRPC.Ping etc? I have to admit that JSONRPC.Introspect is a bit of a loose candidate depending on the browser/websocket-implementation is used because of the huge amount of data it returns. During my testing I found out that there are browsers who can handle literally any amount of result data you throw at them while others have a fixed limit (which is pretty stupid considering that WebSocket supports fragmented messages).

Thanks again for the feedback.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
sjroesink Offline
Junior Member
Posts: 4
Joined: May 2012
Reputation: 0
Post: #1901
Thanks for the fast response.
I did try other methods. They all give the same parse error.

Is there any way I can provide more information to make the debugging easier? I'm not sure how to debug websockets.
find quote
Montellese Offline
Team-XBMC Developer
Posts: 3,848
Joined: Jan 2009
Reputation: 36
Location: Switzerland
Post: #1902
Neither am I. I just ran latest XBMC (from master not a nightly build, but shouldn't make a difference) and used the websocket demo on websocket.org, opened a websocket to XBMC and ran JSONRPC.Ping, JSONRPC.Version and VideoLibrary.GetMovies without a problem.

EDIT: What browser are you using and are you using any framework for websockets?

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
(This post was last modified: 2012-05-06 11:15 by Montellese.)
find quote
sjroesink Offline
Junior Member
Posts: 4
Joined: May 2012
Reputation: 0
Post: #1903
When using Firefox, I can't get the websocket.org demo to connect to the websocket. In Chrome I can.

Via the demo I found out I had to send the JSON encoded string instead of the actual object (I tried this before using the Introspect method, but this gave me the error "Received unexpected continuation frame."):
Code:
var xbmcSocket = new WebSocket('ws://localhost:9090/jsonrpc');
xbmcSocket.onopen = function() {
    console.log('xbmcSocket.open');
    xbmcSocket.send(JSON.stringify({
        "id": 1,
        "jsonrpc": "2.0",
        "method": "JSONRPC.Ping"
    }));
};
xbmcSocket.onmessage = function(msg) {
    console.log('xbmcSocket.onmessage', msg);
};

This does work!

BTW: The error "Received unexpected continuation frame." also occurs when I start playing a movie.
find quote
Mizaki Offline
Fan
Posts: 726
Joined: Apr 2011
Reputation: 14
Post: #1904
That's funny. I was just about to post I was having problems. I've been trying on and off for a few days, I'm doing basically the same thing but I don't get a connection. It tries to open and then after a while I get a closed message and error "Firefox can't establish a connection to the server at ws://10.0.0.101:9090/jsonrpc". Here is the simple code:
Code:
        wsListener: function() {
            if ("WebSocket" in window) {
                
                var wsConn = 'ws://' + location.hostname + ':9090/jsonrpc';
                console.log(wsConn);
                var ws = new WebSocket(wsConn);
                console.log(ws);
                ws.onopen = function (e) {
                    console.log('socket open');
                    ws.send('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["thumbnail"]}, "id": 1}');
                };
                ws.onerror = function (err) {
                    console.log(err);
                };
                ws.onmessage = function (e) {
                    console.log(e.data);
                };
                ws.onclose = function (e) {
                    console.log('socket close');
                };
            };
        }
I can't see what I'm doing wrong. Seems rather simple... I've allowed everything in network just in case. Any ideas? I've tried FF and Chrome.

EDIT: Just thought I'd try the websocket.org demo. Works in Chrome but not in FF. Error in log:
Code:
10:39:44 T:2874841968    INFO: WebSocket [RFC6455]: invalid "connection" received
10:39:44 T:2874841968    INFO: WebSocket: No frame expected in the current state

EDIT, EDIT: Okay and now Chrome is working fine. Maybe because I just allowed UPnP access?

I'll leave all this here for any searchers it might help.

[Image: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
(This post was last modified: 2012-05-06 11:45 by Mizaki.)
find quote
Montellese Offline
Team-XBMC Developer
Posts: 3,848
Joined: Jan 2009
Reputation: 36
Location: Switzerland
Post: #1905
Ah right I thought the websocket send method would take care of the stringification of the JSON object. Yes a websocket is just an extended TCP socket so you'll need to pass in everything as a string.

Back when I implemented this there was no browser who supported the final RFC6455 implementation yet so I could only test against the latest draft. Maybe there's a bug in there.

The only thing you should have to enable in the settings is "Allow programs on this system to control XBMC" (and "Allow programs on other systems to control XBMC" if that's what you want)).

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
Post Reply