// // Copyright 2020 DXOS.org // import { type Event } from '@dxos/async'; import { schema } from '@dxos/protocols/proto'; import type { ContactsService, DevicesService, EdgeAgentService, IdentityService, InvitationsService, LoggingService, NetworkService, QueueService, SpacesService, SystemService, } from '@dxos/protocols/proto/dxos/client/services'; import type { DevtoolsHost } from '@dxos/protocols/proto/dxos/devtools/host'; import type { QueryService } from '@dxos/protocols/proto/dxos/echo/query'; import type { DataService } from '@dxos/protocols/proto/dxos/echo/service'; import type { AppService, ShellService, WorkerService } from '@dxos/protocols/proto/dxos/iframe'; import type { BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge'; import { type ServiceBundle, createServiceBundle } from '@dxos/rpc'; export type { QueueService } from '@dxos/protocols/proto/dxos/client/services'; // // NOTE: Should contain client/proxy dependencies only. // export type ClientServices = { SystemService: SystemService; NetworkService: NetworkService; LoggingService: LoggingService; IdentityService: IdentityService; InvitationsService: InvitationsService; DevicesService: DevicesService; SpacesService: SpacesService; DataService: DataService; QueryService: QueryService; QueueService: QueueService; ContactsService: ContactsService; EdgeAgentService: EdgeAgentService; // TODO(burdon): Deprecated. DevtoolsHost: DevtoolsHost; }; /** * Provide access to client services definitions and service handler. */ export interface ClientServicesProvider { /** * The connection to the services provider was terminated. * This should fire if the services disconnect unexpectedly or during a client reset. */ closed: Event; /** * The underlying service connection was re-established. * Fires after all reconnection callbacks have completed. */ reconnected?: Event; /** * Register a callback to be invoked when services reconnect. * The callback should re-establish any RPC streams. * Reconnection waits for all callbacks to complete before emitting `reconnected`. */ onReconnect?: (callback: () => Promise) => void; descriptors: ServiceBundle; services: Partial; // TODO(burdon): Should take context from parent? open(): Promise; close(): Promise; } /** * Services supported by host. */ export const clientServiceBundle = createServiceBundle({ SystemService: schema.getService('dxos.client.services.SystemService'), NetworkService: schema.getService('dxos.client.services.NetworkService'), LoggingService: schema.getService('dxos.client.services.LoggingService'), IdentityService: schema.getService('dxos.client.services.IdentityService'), QueryService: schema.getService('dxos.echo.query.QueryService'), InvitationsService: schema.getService('dxos.client.services.InvitationsService'), DevicesService: schema.getService('dxos.client.services.DevicesService'), SpacesService: schema.getService('dxos.client.services.SpacesService'), DataService: schema.getService('dxos.echo.service.DataService'), ContactsService: schema.getService('dxos.client.services.ContactsService'), EdgeAgentService: schema.getService('dxos.client.services.EdgeAgentService'), QueueService: schema.getService('dxos.client.services.QueueService'), // TODO(burdon): Deprecated. DevtoolsHost: schema.getService('dxos.devtools.host.DevtoolsHost'), }); export type IframeServiceBundle = { BridgeService: BridgeService; }; export const iframeServiceBundle: ServiceBundle = { BridgeService: schema.getService('dxos.mesh.bridge.BridgeService'), }; export type WorkerServiceBundle = { WorkerService: WorkerService; }; export const workerServiceBundle: ServiceBundle = { WorkerService: schema.getService('dxos.iframe.WorkerService'), }; export type AppServiceBundle = { AppService: AppService; }; export const appServiceBundle: ServiceBundle = { AppService: schema.getService('dxos.iframe.AppService'), }; export type ShellServiceBundle = { ShellService: ShellService; }; export const shellServiceBundle: ServiceBundle = { ShellService: schema.getService('dxos.iframe.ShellService'), };