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