neuralworm commited on
Commit
0311360
·
verified ·
1 Parent(s): bfc2fbf

Update experiments/templates/1014ecaa4_index.html

Browse files
experiments/templates/1014ecaa4_index.html CHANGED
@@ -596,14 +596,22 @@
596
 
597
  // --- WEBSOCKET ---
598
  function startWS() {
599
- document.getElementById('session-overlay').style.display = 'none';
600
- ws = new WebSocket(`ws://${location.host}/ws`);
601
- ws.onmessage = (e) => {
602
- const msg = JSON.parse(e.data);
603
- if (msg.type === 'state') updateState(msg);
604
- else if (['chat', 'history'].includes(msg.type)) msg.data.forEach(addMsg);
605
- };
606
- }
 
 
 
 
 
 
 
 
607
 
608
  function setMode(m) {
609
  mode = m;
 
596
 
597
  // --- WEBSOCKET ---
598
  function startWS() {
599
+ document.getElementById('session-overlay').style.display = 'none';
600
+
601
+ // FIX FÜR HUGGINGFACE / HTTPS
602
+ const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
603
+ ws = new WebSocket(`${protocol}//${window.location.host}/ws`);
604
+
605
+ ws.onmessage = (e) => {
606
+ const msg = JSON.parse(e.data);
607
+ if (msg.type === 'state') updateState(msg);
608
+ else if (['chat', 'history'].includes(msg.type)) msg.data.forEach(addMsg);
609
+ };
610
+
611
+ // Optional: Debugging
612
+ ws.onerror = (e) => console.error("WebSocket Error:", e);
613
+ ws.onclose = () => console.log("WebSocket Disconnected");
614
+ }
615
 
616
  function setMode(m) {
617
  mode = m;