-
Notifications
You must be signed in to change notification settings - Fork 14
/
nodecg-widget-obs.js
96 lines (84 loc) · 1.97 KB
/
nodecg-widget-obs.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(function () {
const namespaces = nodecg.Replicant('_obs:namespaces');
/**
* `nodecg-widget-obs`
* A NodeCG utility that provides a UI for configuring a connection to OBS via obs-websocket
*
* @customElement
* @polymer
*/
class NodecgWidgetObs extends Polymer.Element {
static get is() {
return 'nodecg-widget-obs';
}
static get properties() {
return {
selected: {
type: Number,
value: 0,
notify: true
},
namespaces: {
type: Array,
value() {
return [];
}
},
numNamespaces: {
type: Number,
computed: '_computeNumNamespaces(namespaces)'
}
};
}
ready() {
super.ready();
namespaces.on('change', newVal => {
this.namespaces = newVal.slice(0);
if (this.selected < 0) {
this.selected = 0;
}
});
}
_computeNumNamespaces(namespaces) {
return namespaces.length;
}
_lessThan(a, b) {
return a < b;
}
_handleControlsStatusChanged(e) {
const leds = this.shadowRoot.querySelectorAll('nodecg-widget-obs-led');
const led = leds[e.model.index];
/* istanbul ignore next: just a safety, not worth the hassle of testing */
if (!led) {
return;
}
switch (e.target.status) {
case 'connected':
led.color = 'green';
break;
case 'connecting':
led.color = 'yellow';
break;
case 'disconnected':
case 'error':
led.color = 'red';
break;
/* istanbul ignore next */
default:
// Do nothing.
}
}
_handleControlsConnected(e) {
this.$.toast.show(`OBS #${e.model.index + 1}: Connected!`);
}
_handleControlsDisconnected(e) {
this.$.toast.show(`OBS #${e.model.index + 1}: Disconnected.`);
}
_handleControlsConnectionFailure(e) {
const error = e.detail;
this.$.toast.show(`OBS #${e.model.index + 1}: Failed to connect: ${error.message ? error.message : error}`);
}
}
window.NodecgWidgetObs = NodecgWidgetObs;
window.customElements.define(NodecgWidgetObs.is, NodecgWidgetObs);
})();