Spaces:
Paused
Paused
File size: 2,803 Bytes
46c7a16 |
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 |
<script>
import { BareMuxConnection } from '@mercuryworkshop/bare-mux';
const conn = new BareMuxConnection('/baremux/worker.js');
//load all of the scripts required to use uv/rh (this is not loaded by default due to the size)
//Usage: await window.loadProxyScripts or window.loadProxyScript.then(() => {})
window.loadProxyScripts = async function () {
await window.setTransport(localStorage.getItem('incog||transport') || 'epoxy');
return new Promise<void>((resolve) => {
const uvBundle = document.createElement('script');
uvBundle.src = '/uv/uv.bundle.js';
uvBundle.defer = true;
document.body.appendChild(uvBundle);
const uvConfig = document.createElement('script');
uvConfig.src = '/uv/uv.config.js';
uvConfig.defer = true;
document.body.appendChild(uvConfig);
const search = document.createElement('script');
search.src = '/search.js';
search.defer = true;
document.body.appendChild(search);
const sj = document.createElement('script');
sj.src = "/scram/scramjet.controller.js";
sj.defer = true;
document.body.appendChild(sj);
const checkScripts = setInterval(() => {
//If both of these aren't defined this will repeat until they are
//this allows use to wait for all of the scripts to be ready *before* we setup the serviceworker
if (typeof __uv$config !== 'undefined' && typeof ScramjetController !== 'undefined') {
clearInterval(checkScripts);
resolve();
}
}, 100);
});
};
//function to set a transport between the *defined* transports
//Usage: await window.setTransport("epoxy") or window.setTransport("epoxy").then(() => {})
window.setTransport = function (transport: string) {
return new Promise<void>((resolve) => {
localStorage.setItem('incog||transport', transport);
const wispUrl = (location.protocol === 'https:' ? 'wss://' : 'ws://') +
location.host + '/wisp/';
switch (transport) {
case 'epoxy':
conn.setTransport('/epoxy/index.mjs', [{ wisp: wispUrl }]);
break;
case 'libcurl':
conn.setTransport('/libcurl/index.mjs', [{ wisp: wispUrl }]);
break;
default:
conn.setTransport('/epoxy/index.mjs', [{ wisp: wispUrl }]);
}
resolve();
});
//the promise here is to really make everything look the same even though most of this is synchronous code
};
</script>
|