jez500 / chorus

A Web UI for XBMC, focused on user experience and music. Get the latest version here: https://github.com/xbmc/chorus2
357 stars 55 forks source link

Better Reverse Proxy Support (WebSocket Problem) #120

Open EldonMcGuinness opened 9 years ago

EldonMcGuinness commented 9 years ago

Any chance the web-socket calls could be changed from just using the ws://location.hostname:9090/jsonrpc to something that is more reverse proxy friendly? The main issue comes in when you try to use a reverse proxy to access two devices within the same domain name.

While doing a proxy based on a subdomain works just fine, using a custom path to access individual KODI servers does not.

Examples: http://kodi1.site.com [WORKS] http://kodi2.site.com [WORKS] http://site.com/kodi1 [BROKEN] http://site.com/kodi2 [BROKEN]

The later two are broken as only one device can collect the /jsonrpc and they are hard coded to use port 9090. Perhaps the best way to resolve this is to check if the path is just "/" and if not then use the current hostname and pathname.

Code

wsConn = 'ws://' + location.hostname + (( location.pathname == "/" ) ? ':9090/jsonrpc' : location.pathname + 'jsonrpc');

Result http://site.com/kodi1 ( routed to http://10.0.1.50:8080 ) http://site.com/kodi1/jsonrpc ( routed to http://10.0.1.50:9090 ) http://site.com/kodi2 ( routed to http://10.0.1.51:8080 ) http://site.com/kodi2/jsonrpc ( routed to http://10.0.1.51:9090 )

lukasmrtvy commented 9 years ago

+1

I am using reverse proxy for SSL, but proxy doesnt work propertly, because chorus interface wants to join on ws:// url. Thats an error, because for SSL it has to connect on wss:// or chrome will say bulshits about mixed content.

Mixed Content: The page at 'https://10.0.0.47:8070/xbmc/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://10.0.0.47:9090/jsonrpc?chorus'. This request has been blocked; this endpoint must be available over WSS.

It would be great if you can choose url to websocket manualy

EldonMcGuinness commented 9 years ago

@muhahacz If you are only using one device you might want to consider catching the /jsonrpc call and then properly redirecting it to the desired device/port. You can get this working with one device in this manner.

lukasmrtvy commented 9 years ago

unfortunately i don't know how to do this in apache. Because the url to websocket is hardcoded, so interface will connect always to ws://

To fix it, ill need to do: 1.) Use mod_proxy_wstunnel to proxy ws to wss ProxyPass /xbmc/ ws://localhost:6680/xbmc/ ProxyPassReverse /xbmc/ ws://localhost:6680/xbmc/

2.) Able to choose url in chorus to connect on wss://localhost:6680/xbmc/

lukasmrtvy commented 9 years ago

@jez500 2.) There should be a something like this

 var protocol = (typeof document !== "undefined" &&
        document.location.protocol === "https:") ? "wss://" : "ws://";

wsConn: protocol + location.hostname + ':9090/jsonrpc?chorus',

instead of

wsConn: 'ws://' + location.hostname + ':9090/jsonrpc?chorus',
lukasmrtvy commented 9 years ago

@jez500 or you will support only chorus2 version? Thanks