-
Notifications
You must be signed in to change notification settings - Fork 1
/
variables.js
92 lines (87 loc) · 2.89 KB
/
variables.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
export function getVariables() {
const variables = []
for (let s in this.sources) {
let source = this.sources[s]
let validSourceName = source.display_name?.replace(/[\W]/gi, '_')
variables.push({
name: `${source.display_name} Recording Status`,
variableId: `rec_status_${validSourceName}`,
})
variables.push({
name: `${source.display_name} Recording Time Elapsed`,
variableId: `rec_time_elapsed_${validSourceName}`,
})
variables.push({
name: `${source.display_name} Recording Time Remaining`,
variableId: `rec_time_remaining_${validSourceName}`,
})
variables.push({
name: `${source.display_name} Recording Name`,
variableId: `rec_name_${validSourceName}`,
})
variables.push({
name: `${source.display_name} Recording Destinations`,
variableId: `rec_destinations_${validSourceName}`,
})
variables.push({
name: `${source.display_name} Video Format`,
variableId: `video_format_${validSourceName}`,
})
variables.push({
name: `${source.display_name} Scheduled Recordings`,
variableId: `scheduled_rec_${validSourceName}`,
})
}
return variables
}
function getElapsedTime(startDate) {
let currentTime = new Date()
let recStart = new Date(startDate)
let elapsed = Math.round((currentTime - recStart) / 1000)
let elapsedTime = new Date(elapsed * 1000).toISOString().substr(11, 8)
return elapsedTime
}
function getRemainingTime(endDate) {
let currentTime = new Date()
let recEnd = new Date(endDate)
let remaining = Math.round((recEnd - currentTime) / 1000)
let elapsedTime = new Date(remaining * 1000).toISOString().substr(11, 8)
return elapsedTime
}
export function updateSourceVariables() {
for (let s in this.sources) {
let source = this.sources[s]
let validSourceName = source.display_name?.replace(/[\W]/gi, '_')
let status = ''
let elapsedTime = '00:00:00'
let remainingTime = '00:00:00'
let sourceDestinations = []
let destinations = ''
if (source.is_recording && source.is_paused) {
status = 'Paused'
elapsedTime = '00:00:00'
} else if (source.is_recording) {
status = 'Recording'
elapsedTime = getElapsedTime(source.recording_start_date)
if (source.recording_end_date != '') {
remainingTime = getRemainingTime(source.recording_end_date)
}
} else {
status = 'Stopped'
elapsedTime = '00:00:00'
}
for (let s in source.enabled_destinations) {
let destination = source.enabled_destinations[s]
sourceDestinations.push(destination.destination_name)
}
destinations = sourceDestinations.length ? sourceDestinations.join('\\n') : 'None'
this.setVariableValues({
[`rec_status_${validSourceName}`]: status,
[`rec_time_elapsed_${validSourceName}`]: elapsedTime,
[`rec_time_remaining_${validSourceName}`]: remainingTime,
[`rec_name_${validSourceName}`]: source.recording_name,
[`rec_destinations_${validSourceName}`]: destinations,
[`video_format_${validSourceName}`]: source.video_format,
})
}
}