export namespace SharedWorker { export type ProtocolIdentifier = 'experimental'; export type FactoryOptions = { negotiateProtocol (supported: readonly ['experimental']): Experimental.Protocol; // Add overloads for additional protocols. }; export type Factory = (options: FactoryOptions) => void; export namespace Experimental { export type Protocol = { readonly initialData: Data; readonly protocol: 'experimental'; broadcast: (data: Data) => BroadcastMessage; ready: () => Protocol; subscribe: () => AsyncIterableIterator>; testWorkers: () => AsyncIterableIterator>; }; export type BroadcastMessage = { readonly id: string; replies: () => AsyncIterableIterator>; }; export type PublishedMessage = { readonly id: string; replies: () => AsyncIterableIterator>; }; export type ReceivedMessage = { readonly data: Data; readonly id: string; readonly testWorker: TestWorker; reply: (data: Data) => PublishedMessage; }; export type TestWorker = { readonly id: string; readonly file: string; publish: (data: Data) => PublishedMessage; subscribe: () => AsyncIterableIterator>; teardown: void> (fn: TeardownFn) => TeardownFn; }; } export namespace Plugin { export type RegistrationOptions = { readonly filename: string; readonly initialData?: Data; readonly supportedProtocols: readonly Identifier[]; readonly teardown?: () => void; }; export namespace Experimental { export type Protocol = { readonly available: Promise; readonly currentlyAvailable: boolean; readonly protocol: 'experimental'; publish: (data: Data) => PublishedMessage; subscribe: () => AsyncIterableIterator>; }; export type PublishedMessage = { readonly id: string; replies: () => AsyncIterableIterator>; }; export type ReceivedMessage = { readonly data: Data; readonly id: string; reply: (data: Data) => PublishedMessage; }; } } } export function registerSharedWorker(options: SharedWorker.Plugin.RegistrationOptions<'experimental', Data>): SharedWorker.Plugin.Experimental.Protocol; // Add overloads for additional protocols.