stear/example/connect.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-06-09 17:33:54 +02:00
import l1 from "../stear/extra/Elements/loading1.js";
2022-06-09 21:37:23 +02:00
import showStatus from "../stear/extra/Pages/showStatus.js";
2022-06-09 16:26:27 +02:00
import { _ } from "../stear/main.js";
import { fadein, fadeout, wait } from "../stear/utils.js";
2022-06-09 15:29:53 +02:00
export const preRender = true;
export const render = ({},{}) =>
_({find:"main"},[
_({type:"p",find:"text",style:{
position: "absolute",
minWidth: "90%",
textAlign: "center",
top: "25%",
left: "50%",
transform: "translate(-50%,-50%)",
}}),
_({style:{
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
2022-06-09 16:49:03 +02:00
}}, l1())
2022-06-09 15:29:53 +02:00
]);
2022-06-09 16:26:27 +02:00
export const call = async (stear, { find, resolve, render, call }, {name,id}) => {
2022-06-09 15:29:53 +02:00
find.text._.innerText = "Connecting to: " + name + " (" + id + ")";
2022-06-09 16:49:03 +02:00
await fadein(find.main._, 200, true);
2022-06-09 15:29:53 +02:00
//do connection
await wait(1000);
2022-06-09 21:37:23 +02:00
if (Math.random() > 0.25){
call(showStatus, { text: "Connected" });
2022-06-09 15:29:53 +02:00
await fadeout(find.main._);
return resolve(true);
}else{
2022-06-09 21:37:23 +02:00
call(showStatus, { text: "Error while Connecting to: "+name, color:"red" });
2022-06-09 15:29:53 +02:00
await fadeout(find.main._);
return resolve(false);
}
}