-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsocket.js
More file actions
73 lines (57 loc) · 2.17 KB
/
Copy pathsocket.js
File metadata and controls
73 lines (57 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
///
/// socket events
///
var Socket = Socket || {};
var target = location.origin;
Socket.socket = io.connect(target);
Socket.socket.on('topology-change', function (data) {
Sonos.grouping = {};
var stateTime = new Date().valueOf();
var shouldRenderVolumes = false;
data.forEach(function (player) {
player.stateTime = stateTime;
Sonos.players[player.uuid] = player;
if (!Sonos.grouping[player.coordinator]) Sonos.grouping[player.coordinator] = [];
Sonos.grouping[player.coordinator].push(player.uuid);
});
// If the selected group dissappeared, select a new one.
if (!Sonos.grouping[Sonos.currentState.selectedZone]) {
// just get first zone available
for (var uuid in Sonos.grouping) {
Sonos.currentState.selectedZone = uuid;
break;
}
// we need queue as well!
Socket.socket.emit('queue', {uuid:Sonos.currentState.selectedZone});
shouldRenderVolumes = true;
}
if (Socket.topologyChanged instanceof Function) Socket.topologyChanged(shouldRenderVolumes);
});
Socket.socket.on('transport-state', function (player) {
player.stateTime = new Date().valueOf();
Sonos.players[player.uuid] = player;
if (Socket.transportStateChanged instanceof Function) Socket.transportStateChanged(player);
});
Socket.socket.on('group-volume', function (data) {
if (Socket.groupVolumeChanged instanceof Function) Socket.groupVolumeChanged(data);
});
Socket.socket.on('volume', function (data) {
if (Socket.volumeChanged instanceof Function) Socket.volumeChanged(data);
});
Socket.socket.on('group-mute', function (data) {
Sonos.players[data.uuid].groupState.mute = data.newMute;
if (Socket.groupMuteChanged instanceof Function) Socket.groupMuteChanged(data);
});
Socket.socket.on('mute', function (data) {
if (Socket.muteChanged instanceof Function) Socket.muteChanged(data);
});
Socket.socket.on('favorites', function (data) {
if (Socket.favoritesChanged instanceof Function) Socket.favoritesChanged(data);
});
Socket.socket.on('queue', function (data) {
if (Socket.queueChanged instanceof Function) Socket.queueChanged(data);
});
Socket.socket.on('search-result', function (data) {
if (Socket.searchResultReceived instanceof Function) Socket.searchResultReceived(data);
})