Files
user/public/js/shared-worker.js
2025-07-02 21:56:37 +09:00

22 lines
452 B
JavaScript

const clients = [];
self.onconnect = function(e) {
console.log(1)
const port = e.ports[0];
clients.push(port)
port.onmessage = function(e) {
const message = e.data;
clients.forEach(client => client.postMessage(message))
}
port.isMaster = function() {
clients.forEach(client => client.postMessage({tabId: port.tabId}))
}
port.setMaster = function(tabId) {
port.tabId = tabId;
}
}