Optional config settings for websocket host and port

This commit is contained in:
Nick Steel 2015-04-26 00:38:43 +01:00
parent 83c04b693f
commit b598dbd90d
6 changed files with 36 additions and 16 deletions

View File

@ -53,8 +53,12 @@ Project resources
Changelog
=========
v2.0 (26-3-2015)
----------------
v2.0.1 (UNRELEASED)
-------------------
- Added optional websocket_host and websocket_port config settings.
v2.0.0 (26-3-2015)
------------------
- Pausing a stream will now actually stop it.
- Fix keyboard shortcuts in some browsers.
- Use relative path for script files to fix proxy support.

View File

@ -20,6 +20,8 @@ class MusicBoxExtension(ext.Extension):
def get_config_schema(self):
schema = super(MusicBoxExtension, self).get_config_schema()
schema['musicbox'] = config.Boolean()
schema['websocket_host'] = config.Hostname(optional=True)
schema['websocket_port'] = config.Port(optional=True)
return schema
def setup(self, registry):

View File

@ -1,3 +1,5 @@
[musicbox_webclient]
enabled = true
musicbox = false
websocket_host =
websocket_port =

View File

@ -7,13 +7,10 @@
<link rel="stylesheet" type="text/css" href="css/jquery.mobile.flatui.css"/>
<!-- <script type='application/javascript' src='js/fastclick.js'></script> -->
<script>
//configuration
// var wsLocation = location.host + ':6680'; //for normal operation of mopidy http
var wsLocation = location.host; //for running on port 80
if (wsLocation == location.hostname) {
wsLocation = location.hostname + ':6680';
}
var isMusicBox = {{musicbox}}; // Remove MusicBox only content (e.g. settings, system pages)
//configuration
var isMusicBox = {{musicbox}}; // Remove MusicBox only content (e.g. settings, system pages)
var websocketUrl = '{{websocket_url}}'
//{{title}}
$(document).bind("mobileinit", function () {
$.extend($.mobile, {

View File

@ -463,12 +463,13 @@ $(document).ready(function(event) {
$(window).hashchange();
// Connect to server
// mopidy = new Mopidy();
// console.log(wsLocation);
// $.getScript( wsLocation + '/mopidy/mopidy.min.js');
mopidy = new Mopidy({
webSocketUrl: 'ws://' + wsLocation + '/mopidy/ws/' // wslocation is set in index.html "ws://localhost:6680/mopidy/ws/"
});
if (websocketUrl) {
mopidy = new Mopidy({
webSocketUrl: websocketUrl // wslocation is set in index.html from the extention config.
});
} else {
mopidy = new Mopidy();
}
// mopidy.on(console.log.bind(console)); // Log all events
// mopidy.on(console.error.bind(console));
//initialize events

View File

@ -29,9 +29,23 @@ class IndexHandler(tornado.web.RequestHandler):
def initialize(self, config, path):
ext_config = config[MusicBoxExtension.ext_name]
host, port = ext_config['websocket_host'], ext_config['websocket_port']
ws_url = ''
if host or port:
if not host:
host = self.request.host.partition(':')[0]
logger.warning('Musicbox websocket_host not specified, '
'using %s', host)
elif not port:
port = config['http']['port']
logger.warning('Musicbox websocket_port not specified, '
'using %s', port)
ws_url = "ws://%s:%d/mopidy/ws" % (host, port)
self.__dict = {
'version': MusicBoxExtension.version,
'musicbox': int(ext_config['musicbox'])
'musicbox': int(ext_config['musicbox']),
'websocket_url': ws_url
}
self.__path = path
self.__title = string.Template('MusicBox on $hostname')