-
Notifications
You must be signed in to change notification settings - Fork 8
/
InputServiceWorker.ts
29 lines (26 loc) · 1.05 KB
/
InputServiceWorker.ts
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
/**
* Default service worker to process user input using HTTP requests
*/
// Import service worker provided by the Papyros-package
import { InputWorker } from "./workers/input/InputWorker";
// Strip away the filename of the script to obtain the scope
// let domain = location.href;
// domain = domain.slice(0, domain.lastIndexOf("/") + 1);
const domain = ""; // Disable SharedArrayBuffers to use same environment as Dodona
const inputHandler = new InputWorker(domain);
addEventListener("fetch", async function (event: FetchEvent) {
if (!await inputHandler.handleInputRequest(event)) {
// Not a Papyros-specific request
// Fetch as we would handle a normal request
// Default action is to let browser handle it by not responding here
return;
}
});
// Prevent needing to reload page to have working input
addEventListener("install", function (event: ExtendableEvent) {
event.waitUntil(skipWaiting());
});
addEventListener("activate", function (event: ExtendableEvent) {
event.waitUntil(clients.claim());
});
export { };