* @param {string} serviceName * @param {() => MessagePort|Promise } portProviderFunc
(serviceName, portProviderFunc)
| 32 | * @param {() => MessagePort|Promise<MessagePort>} portProviderFunc |
| 33 | */ |
| 34 | constructor(serviceName, portProviderFunc) { |
| 35 | super(); |
| 36 | |
| 37 | this.#serviceName = serviceName; |
| 38 | this.#portProviderFunc = portProviderFunc; |
| 39 | |
| 40 | this.#clientId = this.#getClientId(); |
| 41 | |
| 42 | // Connect to the current provider and future providers. |
| 43 | this.#providerPort = this.#providerChange(); |
| 44 | this.#clientChannel.addEventListener('message', ({data}) => { |
| 45 | if (data?.type === 'provider' && data?.sharedService === this.#serviceName) { |
| 46 | // A context (possibly this one) announced itself as the new provider. |
| 47 | // Discard any old provider and connect to the new one. |
| 48 | this.#closeProviderPort(this.#providerPort); |
| 49 | this.#providerPort = this.#providerChange(); |
| 50 | } |
| 51 | }, { signal: this.#onClose.signal }); |
| 52 | |
| 53 | this.proxy = this.#createProxy(); |
| 54 | } |
| 55 | |
| 56 | activate() { |
| 57 | if (this.#onDeactivate) return; |
nothing calls this directly
no test coverage detected