2021-08-05 13:08:58 +02:00
|
|
|
onmessage = function (e) {
|
2019-04-05 15:57:59 -04:00
|
|
|
const { cmdId, action, data } = e.data;
|
|
|
|
switch (action) {
|
|
|
|
case 0: // Static response
|
|
|
|
postMessage({
|
|
|
|
cmdId,
|
2020-03-29 04:03:49 +11:00
|
|
|
data: "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n",
|
2019-04-05 15:57:59 -04:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 1: // Respond with request data
|
|
|
|
postMessage({ cmdId, data });
|
|
|
|
break;
|
|
|
|
case 2: // Ping
|
|
|
|
postMessage({ cmdId });
|
|
|
|
break;
|
|
|
|
case 3: // Close
|
2020-01-21 09:49:47 +01:00
|
|
|
postMessage({ cmdId: 3 });
|
2020-01-29 18:54:23 +01:00
|
|
|
close();
|
2019-04-05 15:57:59 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|