MCPcopy Create free account
hub / github.com/rhashimoto/wa-sqlite / constructor

Method constructor

demo/SharedService/SharedService.js:34–54  ·  view source on GitHub ↗

* @param {string} serviceName * @param {() => MessagePort|Promise } portProviderFunc

(serviceName, portProviderFunc)

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 4

#getClientIdMethod · 0.95
#providerChangeMethod · 0.95
#closeProviderPortMethod · 0.95
#createProxyMethod · 0.95

Tested by

no test coverage detected