add websocket support for JSON-RPC #511

Merged
merged 7 commits into from Mar 25, 2012

Projects

None yet

5 participants

@Montellese
Member

These commits add support for websockets (http://en.wikipedia.org/wiki/WebSocket) to CTCPServer so that web-based JSON-RPC clients can also benefit from the advantages of JSON-RPC over TCP like notifications sent by XBMC.

This PR only adds support for the IETF draft hybi-10 (http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10) which handles websocket requests with version 8 but I have written the WebSocketManager in a way so that it can be extended with additional versions. The reason I chose the IETF draft hybi-10 is because it is the first draft that does not have a serious security issue all the earlier drafts suffered from and it is currently supported by Firefox 7, Chrome 14 and the developer version of IE 10.

EDIT (December 13): Yesterday the IETF released http://tools.ietf.org/html/rfc6455 which standardizes Websocket version 13 so I finally took the time to also add support for version 13 (there's no version between 8 and 13 in case someone wonders). Hopefully this also means that websocket support will be finally added to all modern browsers.

As usual I mainly tested this on win32 and with Chrome 14 but I also tested it once on linux and updated the makefiles. No testing on osx yet and the osx project files haven't been updated either.

PS: This PR also includes two new utility classes Base64 and CHttpResponse. Both could probably be used in other code parts as well (IIRC the airtunes/airplay server contains some code that manually puts together a HTTP response).

@Montellese
Member

I just updated the PR with an additional implementation of websocket version 13 (before only version 8 was supported and now both 8 and 13 are supported). Version 13 is the successor of version 8 (yeah the versioning is a bit odd) and has been standardized by the IETF in http://tools.ietf.org/html/rfc6455 so chances are good that all modern browsers will add support for websockets now that they are properly standardized.

@peprasetya

Is there any sample implementation to the websocket at the javascript side?
As I try to connect to ws://(ipaddress):9090/ the websocket is not connected.
There is indication that the TCP connection was created, but no more handshake between XBMC and the browser

Noting, I Use nigthlies xbmc-20111210-410c947 on OSX
And Browser that I used is Chrome 16, Firefox 9, iOS 5.0.1

@Montellese
Member

This is not yet part of XBMC so it is not part of any nightly build and will not be until this has been merged once Eden has been released. So obviously if you connect to TCP and send the WebSocket handshake XBMC does not know what to do with it and will throw it away.

For a sample implementation I always used the demos available on http://www.websocket.org and there's also a JavaScript example on how to use websockets: http://websocket.org/echo.html

@peprasetya

Ohh ok, I was not sure about the status and thinked that it's already on nigthlies.
I'm just updating my add ons and trying some new posibilities.

I'm already used it in my other 2 projects, but it's against Jetty WebServer.
So I was wondered about the url of the websocket that should to be.
Now, I'll wait for next year. for Eden I will strict to Ajax.

@Montellese
Member

The URL you used (ws://[some-ip]:9090) was correct. Unfortunately the webserver we use does not allow us to get control over the underlying socket so we can't provide WebSockets on the webserver port but as we already provide a TCP server we can just use that one instead.

@jmarshallnz
Member

By no means a thorough review, but looks good on the whole, just some minors.

@peprasetya

May i know whatare the minors?

On Mar 19, 2012, at 10:25 AM, jmarshallnzreply@reply.github.com wrote:

By no means a thorough review, but looks good on the whole, just some minors.


Reply to this email directly or view it on GitHub:
#511 (comment)

@jmarshallnz
Member

Comments are in-line.

On Mon, Mar 19, 2012 at 6:24 PM, peprasetya <
reply@reply.github.com

wrote:

May i know whatare the minors?

On Mar 19, 2012, at 10:25 AM, jmarshallnzreply@reply.github.com wrote:

By no means a thorough review, but looks good on the whole, just some
minors.


Reply to this email directly or view it on GitHub:
#511 (comment)


Reply to this email directly or view it on GitHub:
#511 (comment)

@Montellese
Member

@jmarshallnz Thanks a lot for taking a look at the code. I have fixed all your suggestions including the endianness-assumptions. I have also rebased the whole code so it should be ready to go now (in case you don't spot anything else that needs fixing).

@jmarshallnz
Member

Not that you want to go near it, but XBMCHttp.cpp has base64 shenanigans in it. Not a priority, ofc - can be cleaned up (or better, removed) later.

Also, the EndianSwap changes are also in PR 777 (in case you get conflicts)>

@Montellese
Member

I won't touch XBMCHttp.cpp if not absolutely necessary as I plan to remove it ASAP.

Thanks for the heads up on the EndianSwap changes, Github will let me know if it can't automatically merge anymore ;-)

@Montellese
Member

Updated to get rid of the conflict and to use the EndianSwap changes from #777 which has been merged.

@Montellese
Member

Thanks to Memphiz we now also have updated OSX project files for this.

@Montellese Montellese was assigned Mar 23, 2012
@Montellese Montellese merged commit 4d4eac0 into xbmc:master Mar 25, 2012
@fetzerch fetzerch pushed a commit to fetzerch/xbmc that referenced this pull request Apr 25, 2012
@opdenkamp opdenkamp Merge branch 'PR511'. closes #511 65e77d6
@thezoggy

running latest nightly windows build, when sending: {"id":1,"jsonrpc":"2.0","method":"JSONRPC.Version"}

I see it hangs on responding with xbmc's logs showing:
22:19:57 T:3860 DEBUG: JSONRPC Server: New connection detected
22:19:57 T:3860 INFO: JSONRPC Server: New connection added
22:19:57 T:3860 INFO: WebSocket: missing Sec-WebSocket-Version

@Montellese
Member

This is not a user support place. Place post it in the forum or create a bug report on http://trac.xbmc.org (and CC me).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment