2020-03-28 13:03:49 -04:00
|
|
|
onmessage = function (e): void {
|
2019-04-05 15:57:59 -04:00
|
|
|
const { cmdId, action, data } = e.data;
|
|
|
|
switch (action) {
|
|
|
|
case 0: // Static response
|
|
|
|
postMessage({
|
|
|
|
cmdId,
|
2020-03-28 13:03:49 -04: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 03:49:47 -05:00
|
|
|
postMessage({ cmdId: 3 });
|
2020-01-29 12:54:23 -05:00
|
|
|
close();
|
2019-04-05 15:57:59 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|