-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
overlay-channels.ts
47 lines (40 loc) · 1.34 KB
/
overlay-channels.ts
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
// Imports
import xpath from 'xpath'
import _ from 'lodash'
// Types
import { OverlayChannel } from '../types/overlay-channel'
/**
* Overlay channels from XML API
*/
export default class OverlayChannels {
/**
* Returns the overlay channels state read from XML document as an object
*
* @param {Document} xmlDocument
* @returns { [key:number]: OverlayChannel }
*/
static extract(xmlDocument: Document): { [key: number]: OverlayChannel } {
const overlayChannelNodesFound: Element[] = xpath.select("//vmix/overlays/overlay", xmlDocument) as Element[]
return _.keyBy(
overlayChannelNodesFound.map((overlayNode: Element) => {
const overlayChannelNumberAttr = overlayNode.attributes.getNamedItem('number')
const previewAttr = overlayNode.attributes.getNamedItem('preview')
// No overlay channel number found
if (!overlayChannelNumberAttr) {
throw new Error('Overlay channel did not contain channel number')
}
const channelNumber: number = Number(overlayChannelNumberAttr.value)
// // Guard channel number
// if (channelNumber < 1 || channelNumber > 8) {
// throw new Error('Invalid channel number')
// }
return {
channelNumber,
inputNumber: overlayNode.textContent ? Number(overlayNode.textContent) : null,
inPreview: previewAttr?.value === 'True'
}
}),
'channelNumber'
)
}
}