Skip to content

Commit

Permalink
fix(api/shared-worker/worker.js): tracker active connections, replace…
Browse files Browse the repository at this point in the history
… duplicates
  • Loading branch information
jwerle committed Aug 20, 2024
1 parent bdbf6e6 commit f03c470
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/shared-worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const SHARED_WORKER_READY_TOKEN = { __shared_worker_ready: true }

// state
export const module = { exports: {} }
export const connections = new Set()

// event listeners
hooks.onReady(onReady)
Expand Down Expand Up @@ -200,6 +201,15 @@ export async function onMessage (event) {
SharedWorkerMessagePort
})))

for (const entry of connections) {
if (entry.id === connection.port.id) {
entry.close(false)
connections.delete(entry)
break
}
}

connections.add(connection.port)
const connectEvent = new MessageEvent('connect')
Object.defineProperty(connectEvent, 'ports', {
configurable: false,
Expand Down

0 comments on commit f03c470

Please sign in to comment.