Kodi Community Forum
JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93)
+---- Forum: JSON-RPC (https://forum.kodi.tv/forumdisplay.php?fid=174)
+---- Thread: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC (/showthread.php?tid=68263)



- jonib - 2010-10-10

barrygordon Wrote:I have seen several references to the document that describes the JSON methods that have been implemented to date. The one I have is dated feb 15 2010. Is that the latest one? If not could some one post a URL to the latest one? I have ssen instructions on how to get to it but all I ever end up with is a blank web page or a web page not found
This seems to be the only (external to XBMC) documentation I know.

jonib


- barrygordon - 2010-10-10

Thank you jonib. Sometimes how fast a response comes back amazes me!!


- xgamer99 - 2010-10-11

It would be wonderful if a path parameter could be added to <library>.ScanForContent, and perhaps add a <library>.CleanLibrary method that also takes a path.

I created a request for the feature here with more details, and there's also a TRAC associated with it.

Just posting it here to maybe get a little more exposure. The CleanLibrary method, while nice, isn't really a priority, however I would love the path parameter added to both AudioLibrary.ScanForContent and VideoLibrary.ScanForContent. From what I understand there was a patch posted in this very thread a few months ago that added this feature; however, the patch is no longer hosted and the poster hasn't logged on for months. ;_;


- sWORDs - 2010-10-11

Questions already answered (found them out by testing).


- Nick8888 - 2010-10-11

1.
topfs2 Wrote:jsonrpc isn't really finialized for dharma but a stepping stone, until its final or atleast have enough features to deprecate http-api, http-api will remain Smile
working fine for me with whats in the wiki


- sWORDs - 2010-10-11

barrygordon Wrote:I assume if I use the raw port I would just send
/jsonrpc {"jsonrpc": "2.0" . . . "id": 1}

Any help that will allow me to get started would be greatly appreciated.

I've just tested with the raw socket (using putty raw socket to 9090). Drop the /jsonrpc part. The return isn't compacted:

send:
Code:
{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1}

received:
Code:
{
    "id" : 1,
                "jsonrpc" : "2.0",
                                     "result" : {
                                                       "audio" : false,
                                                                             "picture" : false,
                     "video" : false
                                       }
                                        }
This might be problematic because it looks like there will be no way of telling when the return has been processed. Maybe counting { and } until the difference = 0.

What is interesting are the announcements, this is what happens when I select a song using ordinairy controls:

Code:
{
    "jsonrpc" : "2.0",
                         "method" : "Announcement",
                                                      "params" : {
                                                                        "message" : "PlaybackStarted",
                            "sender" : "xbmc"
                                                }
                                                 }
But I can't really find that much about the Announcements. http://trac.xbmc.org/browser/trunk/xbmc/utils/IAnnouncer.h

I've also tested the "old" httpapi and it works just like before, I think some pre-beta nightly builds had a non working httpapi and I wrongly assumed it was dropped from Dharma.

Tolriq Wrote:And i reiterate my request that was discussed some times ago and mostly accepted, to getback some kind of thing similar to GetNowPlaying to avoid hamering XBMC with request (4 request per sec to get current player, volume , progress and media informations) that's a little too much Smile

Tolriq.
Wouldn't it be possible to send multiple requests as one in an array as JSON-RPC 2.0 spec ("To send several Request objects at the same time, the Client MAY send an Array filled with Request objects.")

edit: Woops... TOPFS2 about arrays: When it will be added is not decided yet but hopefully for eden.

Nick8888 Wrote:1. working fine for me with whats in the wiki
Things I used in HTTP-API that I'm missing in JSON:

  1. SendKey
  2. GetCurrentlyPlaying (some items are missing in JSON)
  3. GetGuiStatus
  4. SetBroadcast
  5. ExecBuiltIn (ActivateWindow)

I'm using EventServer for 1 and 5, multiple requests to get parts from 2 and 4 (might be possible with JSON, hopefully someone will answer my previous question about it), dropped everything else for now.

And there are much more missing that I didn't use, but others probably do.

Topfs2, could you tell a little more about the announcements? Is it possible to get more announcements? Ifso how? Which announcements are there? And once again, amazing job with JSON-RPC. Can't wait until the last objects are added and array support is in!


- topfs2 - 2010-10-11

sWORDs Wrote:This might be problematic because it looks like there will be no way of telling when the return has been processed. Maybe counting { and } until the difference = 0.

This is how we do it in XBMC atleast (when you as client send something).

Also a tip overall when dealing with jsonrpc. there is no garantue in jsonrpc spec (although in xbmc there currently is) that your response will come in the order you send them. So what you should do is parse anything comming from xbmc and put them in json messages which you then react on depending of the id or action. Lots of extra code for xbmc though but would be future proof Smile

sWORDs Wrote:But I can't really find that much about the Announcements. http://trac.xbmc.org/browser/trunk/xbmc/utils/IAnnouncer.h

Yeah the documentation about announcements are sad. Just grep the code for CAnnouncementManager::Announce

sWORDs Wrote:
  1. SendKey
  2. GetCurrentlyPlaying (some items are missing in JSON)
  3. GetGuiStatus
  4. SetBroadcast
  5. ExecBuiltIn (ActivateWindow)

  1. will be added at some point, just waiting for input refactoring to be done so that there will be a stable extension for jsonrpc to hook up with (no more of the weird bugs event server and other inputs suffer from).
  2. is under discussion how and if to add.
  3. most should be doable from the infobool, infostrings. Except running window.
  4. level is setable in jsonrpc, with far better precision than httpapi (you enable/disable certain announcement classes).
  5. Is left out since its impossible to wrap security wise. Could add it as a fallback but the security permission would be admin which really shouldn't be enabled by default security wise (so client would have to ask for it and that mechanism isn't available yet).



- sWORDs - 2010-10-11

Tnx for the reply! I only can find AnnouncementManager.cpp and AnnouncementManager.h. Is it in another directory or in a guilib?


- topfs2 - 2010-10-11

sWORDs Wrote:Tnx for the reply! I only can find AnnouncementManager.cpp and AnnouncementManager.h. Is it in another directory or in a guilib?

Should be plenty of calls to the announcementmanager made through out the code, for one example in application.cpp


- sWORDs - 2010-10-12

Isn't it an idea to compact the return (or build it up compacted in the first place) before sending it?

Code:
{
    "id" : 1,
                "jsonrpc" : "2.0",
                                     "result" : {
                                                       "audio" : false,
                                                                             "picture" : false,
                     "video" : false
                                       }
                                        }
vs.
Code:
{"id":1,"jsonrpc":"2.0","result":{"audio":false,"picture":false,"video":false}}
Both is 100% correct JavaScript and JSON code.

And I think it could be helpfull to update the startpost of this topic with some extra information like JSON is in but not complete and mention the most asked for missing objects, and tell about the alternatives. Like the "old" httpapi that now doesn't accept POST but only GET, EventClient on port 9777 (eventclient.h). And also mention the RAW JSON tcp port on 9090. Might save a lot of questions asked over and over again.

The RAW tcp port is extremely fast, on my (not very cpu powered) remote it's almost four times faster with small requests (partly because the socket is already connected and can stay open).

And is there anything else available besides these?:
  • HTTPAPI (80 http)
  • vfs (80 http)
  • JSON (80 http)
  • JSON (9090 TCP)
  • UDP Broadcast (8278 UDP)
  • EventServer (9777 UDP)
I'm still looking for a non http way to fetch fan and cover art (I've got http working, but it's slow, still a lot faster then the base64 encoded version). Would be great if I could use the HTTP-API in the RAW socket.


- topfs2 - 2010-10-12

sWORDs Wrote:Isn't it an idea to compact the return (or build it up compacted in the first place) before sending it?

Code:
{
"id" : 1,
"jsonrpc" : "2.0",
"result" : {
"audio" : false,
"picture" : false,
"video" : false
}
}
vs.
Code:
{"id":1,"jsonrpc":"2.0","result":{"audio":false,"p icture":false,"video":false}}
Both is 100% correct JavaScript and JSON code.

The json writer we have is perfectly able to write the shorter version, I opted for the styled writer since it was easier for me to debug, and I figured if it was easier for me it must be easier for the client creators Smile

I see no problem having an option to make it more truncated (or just always truncate on release builds). please feel free to make a feature suggestion and we can discuss how to best implement it.

sWORDs Wrote:And I think it could be helpfull to update the startpost of this topic with some extra information like JSON is in but not complete and mention the most asked for missing objects, and tell about the alternatives. Like the "old" httpapi that now doesn't accept POST but only GET, EventClient on port 9777 (eventclient.h). And also mention the RAW JSON tcp port on 9090. Might save a lot of questions asked over and over again.

The RAW tcp port is extremely fast, on my (not very cpu powered) remote it's almost four times faster with small requests (partly because the socket is already connected and can stay open).

And is there anything else available besides these?:
  • HTTPAPI (80 http)
  • vfs (80 http)
  • JSON (80 http)
  • JSON (9090 TCP)
  • UDP Broadcast (8278 UDP)
  • EventServer (9777 UDP)
I'm still looking for a non http way to fetch fan and cover art. Would be great if I could use the HTTP-API in the RAW socket.

Hmm, didn't realize old httpapi accepted post aswell, thats a regression. I'll look into it ASAP!

From erhnam:

LOL! I was seeing this as a new feature Smile


- sWORDs - 2010-10-12

topfs2 Wrote:LOL! I was seeing this as a new feature Smile

Maybe it's because english isn't my native language, but I really don't understand your quote and command. Is it cynical? Or is not accepting POST a bug?


- topfs2 - 2010-10-13

Uhm, I got edited, think ernham meant to quote me ... need to yell at him. have fixed it now Smile

So what I WAS saying is that its an regression, I have committed a fix to trunk and is currently backporting it. thanks for bringing it to my attention

And to erhnam, yeah I think accepting post is definatly wrong and its probably not sane security wise but backwards (mad) compability is probably sane. no point in forcing client creators to patch before deprecating Smile


- sWORDs - 2010-10-13

topfs2 Wrote:The json writer we have is perfectly able to write the shorter version, I opted for the styled writer since it was easier for me to debug, and I figured if it was easier for me it must be easier for the client creators Smile

I see no problem having an option to make it more truncated (or just always truncate on release builds). please feel free to make a feature suggestion and we can discuss how to best implement it.

  1. Do you mean "XBMC Community Forum->Development->XBMC Feature Suggestions" or "TRAC Feature Request"? Compacted JSON means less data to send and lighter parsing for clients.
  2. Maybe I could write some JSON and EventServer documentation?
  3. And are there any control methods that I don't know off? (Besides the ones in the list above?)
  4. There is another odd thing. With Camelot [LIVE] keypresses were send using f100 + ascii code. With Dharma [WINDOWS] f100 + ascii doesn't work, f000 + ascii does? (With EventServer and HTTPAPI sendkey)

Once again, every comment I make isn't ment to bash your work in any way, I just would like to improve an already great feature and it's documentation.


- erhnam - 2010-10-13

topfs2 Wrote:Uhm, I got edited, think ernham meant to quote me ... need to yell at him. have fixed it now Smile

So what I WAS saying is that its an regression, I have committed a fix to trunk and is currently backporting it. thanks for bringing it to my attention

And to erhnam, yeah I think accepting post is definatly wrong and its probably not sane security wise but backwards (mad) compability is probably sane. no point in forcing client creators to patch before deprecating Smile

Yeah sorry. I'm not very used at the quote and edit buttons since my status has changed. Sorry for that.

I started building my xbmc php remote app just a couple of days and using only POST.