|
|
|
|
|
|
|
|
// How this has happened I don't understand... |
|
|
// How this has happened I don't understand... |
|
|
// deregister from that source |
|
|
// deregister from that source |
|
|
const count = source.deregister(port); |
|
|
const count = source.deregister(port); |
|
|
// Clean-up |
|
|
|
|
|
|
|
|
// Clean-up |
|
|
if (count === 0) { |
|
|
if (count === 0) { |
|
|
source.close(); |
|
|
source.close(); |
|
|
sourcesByUrl[source.url] = null; |
|
|
sourcesByUrl[source.url] = null; |
|
|
|
|
|
|
|
|
source.register(port); |
|
|
source.register(port); |
|
|
sourcesByUrl[url] = source; |
|
|
sourcesByUrl[url] = source; |
|
|
sourcesByPort[port] = source; |
|
|
sourcesByPort[port] = source; |
|
|
return; |
|
|
|
|
|
} else if (event.data.type === 'listen') { |
|
|
} else if (event.data.type === 'listen') { |
|
|
const source = sourcesByPort[port]; |
|
|
const source = sourcesByPort[port]; |
|
|
source.listen(event.data.eventType); |
|
|
source.listen(event.data.eventType); |
|
|
return; |
|
|
|
|
|
} else if (event.data.type === 'close') { |
|
|
} else if (event.data.type === 'close') { |
|
|
const source = sourcesByPort[port]; |
|
|
const source = sourcesByPort[port]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sourcesByUrl[source.url] = null; |
|
|
sourcesByUrl[source.url] = null; |
|
|
sourcesByPort[port] = null; |
|
|
sourcesByPort[port] = null; |
|
|
} |
|
|
} |
|
|
return; |
|
|
|
|
|
} else if (event.data.type === 'status') { |
|
|
} else if (event.data.type === 'status') { |
|
|
const source = sourcesByPort[port]; |
|
|
const source = sourcesByPort[port]; |
|
|
if (!source) { |
|
|
if (!source) { |
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
source.status(port); |
|
|
source.status(port); |
|
|
return; |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// just send it back |
|
|
// just send it back |
|
|
port.postMessage({ |
|
|
port.postMessage({ |
|
|
type: 'error', |
|
|
type: 'error', |
|
|
message: `received but don't know how to handle: ${event.data}`, |
|
|
message: `received but don't know how to handle: ${event.data}`, |
|
|
}); |
|
|
}); |
|
|
return; |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
port.start(); |
|
|
port.start(); |