mirror of
https://git.hmsn.ink/kospo/helptalk/user.git
synced 2026-03-20 01:12:26 +09:00
22 lines
452 B
JavaScript
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;
|
|
}
|
|
} |