JSON-RPC over HTTP?
#21
Hello,

I apologise in advance if I ask any stupid questions - you might gather from the number of posts I've made on this forum that I'm a bit new to all this ;-)

I feel that I'm close to knowing what I need to do having read this thread ... can someone confirm - or prod me in the right direction if not?

I want my XBMC (on linux) to start playing my favourite radio station when I press a shortcut button on my mobile phone.

From what I read on this thread I have to:
1. Make sure my (linux) XBMC server side is all set up and ready to receive JSON RPC

2. Set up a server side streaming file for XBMC to play - containing the web address of the radio stream. I've called it ~/arctic/antenne_bayern.strm Smile

3. Now - this is the bit I'm still a bit unsure about how to do ...
I want to initiate a command to my XBMC from my phone. I don't want to use a remote control app - I want to have a single shortcut icon that I only have to tap once from my home screen - or trigger by any number of other amusing ways using a great app called tasker that I found Smile.

It seems there are plenty of ways of getting a message to an XBMC server - but can I initiate a POST request simply by the act of loading a webpage? By invoking a javascript function when the page loads?

Can this POST message people are talking about above be kicked off from a bit of javascript - or ajax? If this is true then all I have to do is make a shortcut to the webpage on the home screen of my phone - hit the shortcut and off it goes Smile then I don't need to mess about trying to find mobile versions of various script interpreters ...

3a. So assuming all that is possible: Will a phone browser be able to deal with AJAX in an html file? Will my XBMC server want a username and password first? Will that stop this from working?
What do I need to write in my javascript function to get XBMC to start playing my file?

Here is my guess having read this thread and your wiki - apologies if it seems obvious to everyone else, but I'm new Smile any help greatly appreciated.

Code:
<html>
<head>
  <script>
function XbmcPlayFile()
{
    var data = '{"jsonrpc": "2.0", "method": "XBMC.Play", "params": { "file": "/home/arctic/antenne_bayern.strm"}, "id": 1}' http://myIPaddress:9019/jsonrpc;

    var xhr;
    xhr = new XMLHttpRequest(); // for an Opera like mobile browser?
  
    xhr.onreadystatechange = function()
    {
        // do something with xhr.responseText;
    };

    xhr.open("POST", "ajax-post-response-text.php", true, myLogin, myPassword);
    // line below is for a form - do I bother with this - what's it need to be?
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
    xhr.send(data);}
  </script>
</head>
                
<body>
  <script type="text/javascript" language="JavaScript">
    XbmcPlayFile();
  </script>
</body>
</html>

So - there is my first hair-brained scheme - does this look like it might work? or is there an easier way to fire off a POST request from a smart phone? Bearing in mind that I need it to be a one shot execution - so I can play with how I kick it off later!
Reply


Messages In This Thread
JSON-RPC over HTTP? - by bradvido88 - 2010-12-20, 17:24
[No subject] - by _Andy_ - 2010-12-20, 17:59
[No subject] - by darkscout - 2010-12-20, 18:01
[No subject] - by bradvido88 - 2010-12-20, 18:17
[No subject] - by bradvido88 - 2010-12-20, 19:16
[No subject] - by Montellese - 2010-12-20, 20:42
[No subject] - by bradvido88 - 2010-12-20, 20:49
[No subject] - by darkscout - 2010-12-20, 21:51
[No subject] - by bradvido88 - 2010-12-20, 21:52
[No subject] - by plumser - 2010-12-21, 19:49
[No subject] - by Adam - 2011-01-01, 04:57
[No subject] - by Montellese - 2011-01-01, 11:46
[No subject] - by toenuff - 2011-01-04, 05:26
[No subject] - by toenuff - 2011-01-04, 05:45
[No subject] - by manxam - 2011-01-05, 09:17
[No subject] - by Montellese - 2011-01-05, 10:48
Actionscript 2.0 - by TheyKilledKenny - 2011-01-07, 13:18
[No subject] - by Montellese - 2011-01-07, 14:08
[No subject] - by TheyKilledKenny - 2011-01-07, 18:41
[No subject] - by Montellese - 2011-01-07, 20:27
[No subject] - by ArcticGiraffe - 2011-08-13, 02:08
[No subject] - by topfs2 - 2011-08-13, 10:40
[No subject] - by ArcticGiraffe - 2011-08-13, 15:32
[No subject] - by topfs2 - 2011-08-13, 18:48
[No subject] - by ArcticGiraffe - 2011-08-13, 19:27
RE: JSON-RPC over HTTP? - by Richard6360 - 2016-05-22, 11:38
Logout Mark Read Team Forum Stats Members Help
JSON-RPC over HTTP?1