BraydenMoore commited on
Commit
5b4bf65
1 Parent(s): dcd87ff

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +39 -21
templates/index.html CHANGED
@@ -177,28 +177,46 @@
177
  // });
178
 
179
 
180
- document.addEventListener("DOMContentLoaded", function() {
181
- var xhr = new XMLHttpRequest();
182
- xhr.open('GET', "{{ url }}", true);
183
- xhr.setRequestHeader('Cache-Control', 'no-cache');
184
- xhr.responseType = 'arraybuffer';
185
-
186
- var image = document.getElementById("feed");
187
- var boundary = null; // You'll need to get this from the server's response header
188
-
189
- xhr.onload = function(e) {
190
- if (xhr.status == 200) {
191
- // Parse and display the image
192
- var arrayBufferView = new Uint8Array(this.response);
193
- var blob = new Blob([arrayBufferView], { type: "image/jpeg" });
194
- var urlCreator = window.URL || window.webkitURL;
195
- var imageUrl = urlCreator.createObjectURL(blob);
196
- image.src = imageUrl;
 
 
 
 
 
 
 
 
197
  }
198
- };
199
-
200
- xhr.send();
201
- });
 
 
 
 
 
 
 
 
 
 
202
  </script>
203
  </body>
204
 
 
177
  // });
178
 
179
 
180
+ document.addEventListener("DOMContentLoaded", function() {
181
+ var xhr = new XMLHttpRequest();
182
+ xhr.open('GET', "{{ url }}", true);
183
+ xhr.setRequestHeader('Cache-Control', 'no-cache');
184
+ xhr.responseType = 'arraybuffer';
185
+
186
+ var image = document.getElementById("feed");
187
+ image.src = "{{ url_for('static', filename='loading.gif') }}"; // Display loading image initially
188
+
189
+ var boundary = "--MOBOTIX_Fast_Serverpush"; // Update based on the server's Content-Type header
190
+
191
+ var buffer = new ArrayBuffer(0);
192
+
193
+ xhr.onprogress = function(e) {
194
+ var arrayBuffer = new Uint8Array(buffer.byteLength + e.loaded);
195
+ arrayBuffer.set(new Uint8Array(buffer), 0);
196
+ arrayBuffer.set(new Uint8Array(xhr.response), buffer.byteLength);
197
+
198
+ // Parse buffer to find the boundary and extract JPEG images
199
+ while (true) {
200
+ var start = arrayBuffer.indexOf(boundary);
201
+ var end = arrayBuffer.indexOf(boundary, start + boundary.length);
202
+
203
+ if (start === -1 || end === -1) {
204
+ break;
205
  }
206
+
207
+ var blob = new Blob([arrayBuffer.slice(start + boundary.length, end)], { type: "image/jpeg" });
208
+ var urlCreator = window.URL || window.webkitURL;
209
+ var imageUrl = urlCreator.createObjectURL(blob);
210
+ image.src = imageUrl;
211
+
212
+ arrayBuffer = arrayBuffer.slice(end);
213
+ }
214
+
215
+ buffer = arrayBuffer;
216
+ };
217
+
218
+ xhr.send();
219
+ });
220
  </script>
221
  </body>
222