forked from greyshirtguy/Pro7SinglePresentationRemote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPro7SinglePresentationRemote.html
215 lines (176 loc) · 9.06 KB
/
Pro7SinglePresentationRemote.html
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
padding: 10px;
gap: 10px;
}
.slide {
background-color: #f1f1f1;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.3);
}
</style>
</head>
<body>
<h3 onClick="window.location.reload();" style="color:darkcyan;cursor: pointer;padding-left: 10px;margin:0">Refresh Presentation</h3>
<i><pre id="status-message" style="color:gray;padding-left: 10px;margin:0">Tap <q>Refresh Presentation</q> To Refresh Slides</pre></body></i>
<div id="grid-container" class="grid-container">
</div>
</body>
<script>
// TODO: live feedback of active slide if Pro7 active slide changes by means other than this web app telling it to.
// TODO: live feedback for lose of control if active presentation changes away from controllable presentation
// TODO: Consider a nicer method to lock down to desired presentation instead of hard coded name - Perhaps an electron app as middle-man where operator can select a presentation to make it controllable?)
// TODO: make grid/slides more "responsive" (scale up and down the slides as container is resized and/or dynamic # of columns)
var currentSlideIndex = -1;
var slideCount;
var currentPresentationUUID;
var currentPresentationName;
var presentationInfo;
var missingParametersFlag = false;
var xmlHttp = new XMLHttpRequest();
var url = new URL(window.location.href);
var ipAddressOfProPresenterComputer = url.searchParams.get("address"); // Hostname can used used here also if you have hostname resolution for your ProPresenter computer
var networkPortOfProPresenter = url.searchParams.get("port"); // See ProPresenter network prefs
var nameOfPresentationToControl = url.searchParams.get("presentation"); // This web page will be able to control any active presentation if it's name that matches
if (nameOfPresentationToControl != null) {
nameOfPresentationToControl = nameOfPresentationToControl.toLowerCase()
}
var slideQuality = url.searchParams.get("quality");
if (slideQuality == null) {
slideQuality = "600";
}
var containerWidth = document.getElementById('grid-container').clientWidth;
if (ipAddressOfProPresenterComputer == null || networkPortOfProPresenter == null) {
document.querySelector('#status-message').innerText = ('Missing one or more required URL parameters: address=... and/or port=...');
missingParametersFlag = true;
}
try {
if (!missingParametersFlag) {
xmlHttp.open( 'GET', 'http://' + ipAddressOfProPresenterComputer + ':' + networkPortOfProPresenter + '/v1/presentation/slide_index');
}
} catch (error) {
document.querySelector('#status-message').innerText = (error + ' while trying to open: ' + 'http://' + ipAddressOfProPresenterComputer + ':' + networkPortOfProPresenter + '/v1/presentation/slide_index');
}
xmlHttp.onload = function(e) {
if (xmlHttp.status == 200) {
try {
presentationInfo = JSON.parse(xmlHttp.response);
currentPresentationUUID = presentationInfo.presentation.presentation_id.uuid;
currentPresentationName = presentationInfo.presentation.presentation_id.name.toLowerCase();
currentSlideIndex = presentationInfo.presentation.index;
if (currentPresentationName != nameOfPresentationToControl) {
document.querySelector('#status-message').innerText = 'Not Controllable. Tap "Refresh Presentation" To Refresh Slides'
} else {
document.querySelector('#status-message').innerText = 'Controllable - Tap any slide to Trigger. (Spacebar and Arrow keys also work). Tap "Refresh Presentation" To Refresh Slides'
}
console.log('Response: ' + xmlHttp.response);
slideCount = 0;
getSlide(0); // start recursively getting all slide thumbs...
} catch (error) {
document.querySelector('#status-message').innerText = 'Error: ' + error;
}
}
};
xmlHttp.onerror = function(e) {
document.querySelector('#status-message').innerText = 'Could NOT connect to ProPresenter at: ' +'http://' + ipAddressOfProPresenterComputer + ':' + networkPortOfProPresenter;
}
if (!missingParametersFlag) {
xmlHttp.send();
}
function getSlide(slideIndex) {
var xhr = new XMLHttpRequest();
try {
xhr.open('GET', 'http://' + ipAddressOfProPresenterComputer + ':' + networkPortOfProPresenter + '/v1/presentation/' + currentPresentationUUID + '/thumbnail/' + slideIndex + '?quality=' + slideQuality, true);
} catch (error) {
document.querySelector('#status-message').innerText = ('error:' + error);
}
xhr.responseType = 'blob';
xhr.onload = () => {
if (xhr.status == 200) {
// Add new slide to grid...
slideElement = document.createElement('img');
slideElement.slideIndex = slideIndex;
slideElement.setAttribute('class','slide');
slideElement.setAttribute('src', window.URL.createObjectURL(xhr.response)); // create a temporary blob object to hold the image data and be the src for the image element
//slideElement.style["width"] = String(parseInt(slideQuality)/2) + 'px';
slideElement.style["width"] = String(parseInt((containerWidth-50)/4)) + 'px';
slideElement.style["outline-color"] = "orange";
slideElement.style["outline-width"] = "7px";;
// Check if presentation has correct name to allow control
if (currentPresentationName != nameOfPresentationToControl) {
slideElement.style["opacity"] = '0.5'; // set low opacity to create a disabled "ghosted" effect (shows user they cannot control this presentation)
}
// Show current active slide with highlighted border
if (slideElement.slideIndex == currentSlideIndex) {
slideElement.style["outline-style"] = "solid";
}
slideElement.addEventListener("click", handleClick); // Add click handler to all slides (logic to check if clicking a slide show allow control is done in the triggerSlide function)
document.querySelector('.grid-container').appendChild(slideElement);
slideCount++; // Keep track of how many slides we have.
// Keep calling this getSlide function recursively for the next slide thumbnail until we fail with a 404 - need to do it this way since there is no way to astertain # of slides when a presentation has a custom arrangement active.
getSlide(slideIndex+1);
}
};
xhr.send();
}
document.addEventListener("keydown",handleKeyDown) // Allow keyboard control (both space and arrow keys)
function handleKeyDown (event) {
if (event.key == " " || event.keyCode == 39) {
event.preventDefault();
if (currentSlideIndex < slideCount-1) { // Do not try to trigger past last slide
triggerSlide(currentSlideIndex+1);
}
}
if (event.keyCode == 37) {
event.preventDefault();
if (currentSlideIndex > 0) { // do not try to trigger before first slide
triggerSlide(currentSlideIndex-1);
}
}
}
function handleClick(event) {
triggerSlide(event.currentTarget.slideIndex);
}
function triggerSlide(slideIndex) {
console.log("triggerSlide: " + slideIndex);
// Perform a quick check of current presentation - confirm if it has correct name before sending any trigger commands!
xmlHttp.open( 'GET', 'http://' + ipAddressOfProPresenterComputer + ':' + networkPortOfProPresenter + '/v1/presentation/slide_index');
xmlHttp.onload = function(e) {
if (xmlHttp.status == 200) {
try {
presentationInfo = JSON.parse(xmlHttp.response);
if (presentationInfo.presentation.presentation_id.name.toLowerCase() == nameOfPresentationToControl.toLowerCase() && presentationInfo.presentation.presentation_id.name.toLowerCase() == currentPresentationName.toLowerCase()) { // Only send triggers if current presentation has correct name
document.querySelector('#status-message').innerText = 'Controllable - Tap any slide to Trigger. (Spacebar and Arrow keys also work). Tap "Refresh Presentation" To Refresh Slides'
xmlHttp.open( 'GET', 'http://' + ipAddressOfProPresenterComputer + ':' + networkPortOfProPresenter + '/v1/presentation/' + currentPresentationUUID + '/trigger/' + slideIndex);
xmlHttp.onload = function(e) {
// Remove highlighted border from previously selected/triggered slide...
if (currentSlideIndex >=0) {
document.querySelectorAll(".slide")[currentSlideIndex].style["outline-style"] = null;
// Update record of which slide is highlighted/triggered.
currentSlideIndex = slideIndex;
// Highlight border to newly triggered slide:
document.querySelectorAll(".slide")[currentSlideIndex].style["outline-style"] = 'solid';
}
}
xmlHttp.send( null );
}
if (presentationInfo.presentation.presentation_id.name.toLowerCase() != currentPresentationName.toLowerCase()) {
// Active presentation has changed away since last refresh....Let user know
document.querySelector('#status-message').innerText = 'Active presentation changed. Tap "Refresh Presentation" To Refresh Slides'
}
} catch (error) {
document.querySelector('#status-message').innerText = ('error:' + error);
}
}
};
xmlHttp.send()
}
</script>
</html>