<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>ImJoy Plugin Template</title>
    <meta name="description" content="Template for ImJoy plugin">
    <meta name="author" content="ImJoy-Team">
</head>

<body>
<script id="worker" type="javascript/worker">
window = self;

self.onmessage = function(e) {
const config = e.data
importScripts("https://cdn.jsdelivr.net/npm/imjoy-rpc@0.3.34/dist/imjoy-rpc-socketio.min.js")

imjoyRPCSocketIO.connectToServer(config).then(async (api)=>{
await imjoyRPCSocketIO.loadRequirements([{% for req in requirements %}"{{req}}", {% endfor %}])
{{ script | safe }}
}).catch(console.error)
}
</script>
    <script>
        const blob = new Blob([
          document.querySelector('#worker').textContent
        ], { type: "text/javascript" })
        const worker = new Worker(window.URL.createObjectURL(blob));
        worker.onerror = console.error
        worker.onmessage = console.log
        const cfg = {{ config | tojson(indent=2) }}
        const config = Object.assign(cfg, Object.fromEntries(new URLSearchParams(window.location.search)));
        if(!config.server_url) config.server_url = window.location.origin;
        worker.postMessage(config); 
    </script>
</body>
</html>