Skip to content

Commit

Permalink
Feature/trc fe fix (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanfarming authored Nov 20, 2023
1 parent a0f5f3e commit ecc4662
Showing 1 changed file with 106 additions and 53 deletions.
159 changes: 106 additions & 53 deletions orch/_statics/turkeyreturncenter.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@

<body>
<img id="logo" class="logo" src="https://storage.googleapis.com/turkey-assets/logos/logos_hubs-dark-logo.png" />
<div class="contents">
<div id="prod" class="contents">
<div class="card">
<h1>Reactivating Your Hub</h1>
<p>Your hub was paused to do inactivity. Please give us a moment to reactivate, estimate time for reactivation is 3 to 5 minuts.</p>
Expand All @@ -180,59 +180,112 @@ <h1>Reactivating Your Hub</h1>
</div>
</div>
</div>
<script>
var socket = new WebSocket("wss://" + window.location.host + "/websocket")
var countdown = 10;
var state = 0;


/**
Watch for ready
**/
socket.onmessage = function (event) {
if (event.data == "_refresh_") {
setInterval(async function () {
const timeout = new Promise((resolve, reject) => {
setTimeout(resolve, 1000, false);
})
const readinessCheck = Promise.all([
fetch("https://" + window.location.host + "/manifest.webmanifest").then(response => response.status),
fetch("https://" + window.location.host + "/api/v1/media/search?source=rooms&filter=public&cursor=0").then(response => response.status)
]).then(([status1, status2]) => status1 === 200 && status2 === 200);
const ready = await Promise.race([timeout, readinessCheck])
console.log("ready: ", ready)
if (ready) {
location.reload();
}
}, 10000);
return
}

};

socket.onopen = function (event) {
socket.send("hi")
};

window.addEventListener('keypress', function (event) {
socket.send("keyCode:" + event.keyCode)
});

unpausingLoop = setInterval(async function () {
switch (state) {
case 1:
if (!document.hidden) {
countdown--;
}
if (countdown <= 0 || countdown > 20) {
socket.send("_r_: 1")
state = 2
clearInterval(unpausingLoop);
}
break;
}
}, 1000);
<div id="dev" class="contents" style="display:none">
<img id="duckPic" src="https://storage.googleapis.com/turkey-assets/logos/hubsduck.png"/>
<div id="msg_line0">this hubs' paused due to inactivity. </div>
<div id="msg_line1"></div>
<div id="msg_line2">[]</div>
<div id="msg_line3"></div>
</div>

<script>
var socket = new WebSocket("wss://" + window.location.host+"/websocket")
var countdown=10;
var state=0;
var wait=30;
var tokenStr=""

updateDuckRotation(countdown)

socket.onmessage = function (event) {
if (event.data.startsWith("token:")){
state=1
tokenStr=event.data
return
}
if (event.data == "_ok_"){
state=3
document.getElementById('msg_line2').innerText += ":";
document.getElementById('msg_line1').innerText = "unpausing."
return
}
if (event.data == "..."){
document.getElementById('msg_line2').innerText = "[ error, sry, please contact support ]"
return
}
document.getElementById('msg_line2').innerText = "[ "+event.data+" ]"
};
socket.onopen = function (event) {
socket.send("hi")
};
window.addEventListener('keypress', function (event) {
if (event.keyCode==96)
toggleDivs()
});

unpausingLoop = setInterval(async function() {
switch(state) {
case 1:
if (!document.hidden){
countdown--;
updateDuckRotation(countdown)
document.getElementById('msg_line2').innerText = "[ unpausing start in: " + countdown + " sec ]";
}
if (countdown <= 0 ) {
socket.send(tokenStr)
state=2
document.getElementById('msg_line0').innerText = ""
document.getElementById('msg_line1').innerText = "unpausing requested."
document.getElementById('msg_line2').innerText = "";
}
break
case 2:
document.getElementById('msg_line2').innerText += "'";
break
case 3:
console.log("start poking")
state=4
setInterval(async function() {
document.getElementById('msg_line1').innerText = "waiting for backend"
const timeout = new Promise((resolve, reject) => { setTimeout(resolve, 2000, false);})
const readinessCheck = Promise.all([
fetch("https://"+window.location.host+"/manifest.webmanifest").then(response => response.status),
fetch("https://"+window.location.host+"/api/v1/media/search?source=rooms&filter=public&cursor=0").then(response => response.status)
]).then(([status1, status2]) => status1 < 300 && status2 < 300);
const ready=await Promise.race([timeout, readinessCheck])
console.log("ready: ", ready)
if (ready) {
location.reload();
}
document.getElementById('msg_line2').innerText += "0"
}, 15000);
break
case 4:
msg2=document.getElementById('msg_line2').innerText
msg2+="."
msg2=msg2.replace('.....', 'v')
msg2=msg2.replace('vv', 'x')
document.getElementById('msg_line2').innerText =msg2

}
}, 1000);

function updateDuckRotation(countdown){
document.getElementById('duckPic').style.transform='rotate(' + (countdown * 18).toString() + 'deg)';
}
// window.addEventListener('click', function (evt) {
// if (evt.detail === 4) {
// toggleDivs()
// }
// });
function toggleDivs(){
var divs = [document.getElementById("dev"),document.getElementById("prod")]
divs.forEach(element => {
if (element.style.display == "")
element.style.display = "none";
else element.style.display = "";
});
}
</script>
</body>

Expand Down

0 comments on commit ecc4662

Please sign in to comment.