Added support for setting/changing group streams on Snapcast
This commit is contained in:
parent
35292968ed
commit
80bd5b684c
4 changed files with 104 additions and 18 deletions
|
@ -121,19 +121,24 @@
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.snapcast-form > .snapcast-group-stream,
|
||||||
.snapcast-form > .snapcast-client-delete {
|
.snapcast-form > .snapcast-client-delete {
|
||||||
width: 30%;
|
width: 30%;
|
||||||
margin: 1em auto 0 auto;
|
margin: 1em auto 0 auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.snapcast-form > .snapcast-group-stream > label,
|
||||||
.snapcast-form > .snapcast-client-delete > label {
|
.snapcast-form > .snapcast-client-delete > label {
|
||||||
display: inline;
|
display: inline;
|
||||||
margin-left: .5em;
|
margin-left: .5em;
|
||||||
color: rgba(200, 44, 23, 1.0);
|
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.snapcast-form > .snapcast-client-delete > label {
|
||||||
|
color: rgba(200, 44, 23, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
.snapcast-form * > .snapcast-group-clients {
|
.snapcast-form * > .snapcast-group-clients {
|
||||||
max-width: 15em;
|
max-width: 15em;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var serverInfo = {},
|
var serverInfo = {},
|
||||||
clientInfo = {},
|
clientInfo = {},
|
||||||
|
serverStreams = {},
|
||||||
|
groupStreams = {},
|
||||||
$container = $('#snapcast-container');
|
$container = $('#snapcast-container');
|
||||||
|
|
||||||
var createPowerToggleElement = function(data) {
|
var createPowerToggleElement = function(data) {
|
||||||
|
@ -71,6 +73,8 @@ $(document).ready(function() {
|
||||||
$container.html('');
|
$container.html('');
|
||||||
serverInfo = {};
|
serverInfo = {};
|
||||||
clientInfo = {};
|
clientInfo = {};
|
||||||
|
serverStreams = {};
|
||||||
|
groupStreams = {};
|
||||||
|
|
||||||
var hosts = Object.keys(window.config.snapcast_hosts);
|
var hosts = Object.keys(window.config.snapcast_hosts);
|
||||||
|
|
||||||
|
@ -78,6 +82,8 @@ $(document).ready(function() {
|
||||||
var status = statuses[i];
|
var status = statuses[i];
|
||||||
var host = hosts[i];
|
var host = hosts[i];
|
||||||
var name = status.server.host.name || status.server.host.ip;
|
var name = status.server.host.name || status.server.host.ip;
|
||||||
|
|
||||||
|
serverStreams[host] = status.streams;
|
||||||
serverInfo[host] = status.server.host;
|
serverInfo[host] = status.server.host;
|
||||||
serverInfo[host].serverName = status.server.snapserver.serverName;
|
serverInfo[host].serverName = status.server.snapserver.serverName;
|
||||||
serverInfo[host].version = status.server.snapserver.version;
|
serverInfo[host].version = status.server.snapserver.version;
|
||||||
|
@ -114,6 +120,8 @@ $(document).ready(function() {
|
||||||
|
|
||||||
for (var group of status.groups) {
|
for (var group of status.groups) {
|
||||||
var groupName = group.name || group.stream_id;
|
var groupName = group.name || group.stream_id;
|
||||||
|
groupStreams[group.id] = group.stream_id;
|
||||||
|
|
||||||
var $group = $('<div></div>')
|
var $group = $('<div></div>')
|
||||||
.addClass('snapcast-group-container')
|
.addClass('snapcast-group-container')
|
||||||
.data('name', groupName)
|
.data('name', groupName)
|
||||||
|
@ -336,6 +344,23 @@ $(document).ready(function() {
|
||||||
$label.appendTo($row);
|
$label.appendTo($row);
|
||||||
$row.appendTo($clientsList);
|
$row.appendTo($clientsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var $streams = $form.find('.snapcast-group-stream').find('select[name=stream]');
|
||||||
|
$streams.html('');
|
||||||
|
|
||||||
|
for (var stream of serverStreams[host]) {
|
||||||
|
var $option = $('<option></option>').val(stream.id)
|
||||||
|
.text(stream.id);
|
||||||
|
|
||||||
|
if (stream.id === groupStreams[groupId]) {
|
||||||
|
$option.prop('selected', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$option.appendTo($streams);
|
||||||
|
}
|
||||||
|
|
||||||
|
$form.find('.snapcast-group-stream')
|
||||||
|
.find('select[name=stream]').html($streams.html());
|
||||||
});
|
});
|
||||||
|
|
||||||
$container.on('click touch', '.snapcast-client-settings', function(evt) {
|
$container.on('click touch', '.snapcast-client-settings', function(evt) {
|
||||||
|
@ -431,36 +456,48 @@ $(document).ready(function() {
|
||||||
clients.push($(c).attr('name'));
|
clients.push($(c).attr('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = {
|
var streamId = $form.find('.snapcast-group-stream')
|
||||||
type: 'request',
|
.find('select[name=stream]').val();
|
||||||
action: 'music.snapcast.group_set_clients',
|
|
||||||
args: {
|
|
||||||
host: host,
|
|
||||||
port: window.config.snapcast_hosts[host],
|
|
||||||
group: groupId,
|
|
||||||
clients: clients,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
$form.find('input').prop('disabled', true);
|
var promises = [
|
||||||
|
execute({
|
||||||
|
type: 'request',
|
||||||
|
action: 'music.snapcast.group_set_clients',
|
||||||
|
args: {
|
||||||
|
host: host,
|
||||||
|
port: window.config.snapcast_hosts[host],
|
||||||
|
group: groupId,
|
||||||
|
clients: clients,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
execute({
|
||||||
|
type: 'request',
|
||||||
|
action: 'music.snapcast.group_set_stream',
|
||||||
|
args: {
|
||||||
|
host: host,
|
||||||
|
port: window.config.snapcast_hosts[host],
|
||||||
|
group: groupId,
|
||||||
|
stream_id: streamId,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
execute(
|
$.when.apply($, promises)
|
||||||
request,
|
.fail(
|
||||||
(response) => {
|
|
||||||
redraw();
|
|
||||||
},
|
|
||||||
(xhr, status, error) => {
|
(xhr, status, error) => {
|
||||||
createNotification({
|
createNotification({
|
||||||
'icon': 'exclamation',
|
'icon': 'exclamation',
|
||||||
'text': status + ': ' + error,
|
'text': status + ': ' + error,
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
).always(
|
||||||
() => {
|
() => {
|
||||||
$form.find('input').prop('disabled', false);
|
$form.find('input').prop('disabled', false);
|
||||||
$modal.fadeOut();
|
$modal.fadeOut();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$form.find('input').prop('disabled', true);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -77,6 +77,10 @@
|
||||||
<div class="row snapcast-group-clients-container">
|
<div class="row snapcast-group-clients-container">
|
||||||
<div class="row snapcast-group-clients"></div>
|
<div class="row snapcast-group-clients"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row snapcast-group-stream">
|
||||||
|
<select name="stream"></select>
|
||||||
|
<label for="stream">Stream</label>
|
||||||
|
</div>
|
||||||
<div class="row snapcast-form-bottom">
|
<div class="row snapcast-form-bottom">
|
||||||
<div class="six columns offset-by-six forms-btns">
|
<div class="six columns offset-by-six forms-btns">
|
||||||
<input type="button" class="btn-default" data-dismiss-modal="#snapcast-group-modal"
|
<input type="button" class="btn-default" data-dismiss-modal="#snapcast-group-modal"
|
||||||
|
|
|
@ -493,4 +493,44 @@ class MusicSnapcastPlugin(Plugin):
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
|
|
||||||
|
@action
|
||||||
|
def group_set_stream(self, group, stream_id, host=None, port=None):
|
||||||
|
"""
|
||||||
|
Sets the active stream for a group.
|
||||||
|
|
||||||
|
:param group: Group name or ID
|
||||||
|
:type group: str
|
||||||
|
|
||||||
|
:param stream_id: Stream ID
|
||||||
|
:type stream_id: str
|
||||||
|
|
||||||
|
:param host: Snapcast server (default: default configured host)
|
||||||
|
:type host: str
|
||||||
|
|
||||||
|
:param port: Snapcast server port (default: default configured port)
|
||||||
|
:type port: int
|
||||||
|
"""
|
||||||
|
|
||||||
|
sock = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
sock = self._connect(host or self.host, port or self.port)
|
||||||
|
group = self._get_group(sock, group)
|
||||||
|
request = {
|
||||||
|
'id': self._get_req_id(),
|
||||||
|
'jsonrpc':'2.0',
|
||||||
|
'method': 'Group.SetStream',
|
||||||
|
'params': {
|
||||||
|
'id': group['id'],
|
||||||
|
'stream_id': stream_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self._send(sock, request)
|
||||||
|
return self._recv(sock)
|
||||||
|
finally:
|
||||||
|
try: sock.close()
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue