{"version":3,"file":"index.mjs","names":[],"sources":["../../src/signal-manager/signal-manager.ts","../../src/signal-manager/edge-signal-manager.ts","../../src/signal-manager/utils.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\nimport * as Context from 'effect/Context';\n\nimport { type Event } from '@dxos/async';\nimport { type Lifecycle } from '@dxos/context';\n\nimport { type SignalMethods, type SignalStatus } from '../signal-methods';\n\n/**\n * Manages a collection of signaling clients.\n */\nexport interface SignalManager extends SignalMethods, Required<Lifecycle> {\n  statusChanged?: Event<SignalStatus[]>;\n  getStatus?: () => SignalStatus[];\n}\n\nexport class SignalManagerService extends Context.Tag('@dxos/messaging/SignalManager')<\n  SignalManagerService,\n  SignalManager\n>() {}\n","//\n// Copyright 2024 DXOS.org\n//\n\n// DX-1059: this client is already DID-only — it never writes the deprecated `identity_key`\n// (proto field 2). The dual-read fallback that still gates removing that field lives on the\n// edge side (which relays peers from not-yet-migrated senders); nothing here needs it.\n\nimport { Event, scheduleMicroTask } from '@dxos/async';\nimport { type Context, Resource, cancelWithContext } from '@dxos/context';\nimport { type EdgeConnection, EdgeIdentityChangedError, protocol } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { EdgeService } from '@dxos/protocols';\nimport { type buf, bufWkt } from '@dxos/protocols/buf';\nimport {\n  type Message as EdgeMessage,\n  type PeerSchema,\n  SwarmRequest_Action as SwarmRequestAction,\n  SwarmRequestSchema,\n  SwarmResponseSchema,\n} from '@dxos/protocols/buf/dxos/edge/messenger_pb';\nimport { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';\nimport { ComplexMap, ComplexSet } from '@dxos/util';\n\nimport {\n  type Message,\n  type PeerInfo,\n  PeerInfoHash,\n  type SubscribeMessagesParams,\n  type SwarmEvent,\n  type UnsubscribeCallback,\n} from '../signal-methods';\nimport { type SignalManager } from './signal-manager';\n\n/**\n * A single message subscription registered on an {@link EdgeSignalManager} (DX-1125). Point-to-point\n * delivery matches `peerKey`; broadcast delivery matches any intersection with `tags`.\n */\ntype MessageSubscription = {\n  peerKey: string;\n  tags: Set<string>;\n  onMessage: (message: Message) => void;\n};\n\nexport class EdgeSignalManager extends Resource implements SignalManager {\n  /**\n   * @deprecated\n   */\n  public swarmEvent = new Event<SwarmEvent>();\n  public swarmState = new Event<SwarmResponse>();\n\n  /**\n   * Active message subscriptions. Routing is encapsulated here (DX-1125): each incoming message is\n   * dispatched to every subscription it matches, and each subscription owns its own teardown.\n   */\n  private readonly _subscriptions = new Set<MessageSubscription>();\n\n  /**\n   * Swarm key -> { peer: <own state payload>, joinedPeers: <state of swarm> }.\n   */\n  // TODO(mykola): This class should not contain swarm state joinedPeers. Temporary before network-manager API changes to accept list of peers.\n  private readonly _swarmPeers = new ComplexMap<\n    PublicKey,\n    { lastState?: Uint8Array; joinedPeers: ComplexSet<PeerInfo> }\n  >(PublicKey.hash);\n\n  /**\n   * OR-subscription tag refcounts for broadcast messages (DX-1125). One count per distinct tag across\n   * all subscribers, so one consumer's unsubscribe releases only its own registration rather than\n   * clobbering another consumer's identical subscription. The effective tag set (the keys) is shared\n   * across all joined swarms; the edge fans out any broadcast whose tags intersect it. Re-sent on\n   * reconnect and whenever a swarm is (re-)joined.\n   */\n  private readonly _subscribedTags = new Map<string, number>();\n\n  private readonly _edgeConnection: EdgeConnection;\n\n  constructor({ edgeConnection }: { edgeConnection: EdgeConnection }) {\n    super();\n    this._edgeConnection = edgeConnection;\n  }\n\n  protected override async _open(): Promise<void> {\n    this._ctx.onDispose(this._edgeConnection.onMessage((message) => this._onMessage(message)));\n    this._ctx.onDispose(\n      this._edgeConnection.onReconnected(() => {\n        scheduleMicroTask(this._ctx, () => this._rejoinAllSwarms());\n      }),\n    );\n  }\n\n  /**\n   * Warning: PeerInfo is inferred from edgeConnection.\n   */\n  async join(ctx: Context, { topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {\n    if (!this._matchSelfPeerInfo(peer)) {\n      // NOTE: Could only join swarm with the same peer info as the edge connection.\n      log.warn('ignoring peer info on join request', {\n        peer,\n        expected: {\n          peerKey: this._edgeConnection.peerKey,\n          identityDid: this._edgeConnection.identityDid,\n        },\n      });\n\n      // DX-1059: advertise only the identity DID; the client no longer sends the hex `identityKey`\n      // (edge derives the connection's identity from auth, not from this message body).\n      peer.identityDid = this._edgeConnection.identityDid;\n      peer.peerKey = this._edgeConnection.peerKey;\n    }\n\n    this._swarmPeers.set(topic, { lastState: peer.state, joinedPeers: new ComplexSet<PeerInfo>(PeerInfoHash) });\n    await this._edgeConnection.send(\n      ctx,\n      protocol.createMessage(SwarmRequestSchema, {\n        serviceId: EdgeService.SWARM,\n        source: createMessageSource(topic, peer),\n        payload: { action: SwarmRequestAction.JOIN, swarmKeys: [topic.toHex()] },\n      }),\n    );\n\n    // Re-establish any broadcast subscription on the newly-joined swarm (DX-1125).\n    if (this._subscribedTags.size > 0) {\n      await this._sendSubscription(ctx);\n    }\n  }\n\n  async leave(ctx: Context, { topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {\n    this._swarmPeers.delete(topic);\n    try {\n      await this._edgeConnection.send(\n        ctx,\n        protocol.createMessage(SwarmRequestSchema, {\n          serviceId: EdgeService.SWARM,\n          source: createMessageSource(topic, peer),\n          payload: { action: SwarmRequestAction.LEAVE, swarmKeys: [topic.toHex()] },\n        }),\n      );\n    } catch (err) {\n      if (err instanceof EdgeIdentityChangedError) {\n        // Note: On edge identity change, the connection is closed and EDGE will remove us from the swarm.\n        //       So we should just delete the swarm from _swarmPeers.\n        return;\n      }\n      throw err;\n    }\n  }\n\n  async query(ctx: Context, { topic }: { topic: PublicKey }): Promise<SwarmResponse> {\n    const response = cancelWithContext(\n      this._ctx,\n      this.swarmState.waitFor((state) => state.swarmKey === topic.toHex()),\n    );\n\n    await this._edgeConnection.send(\n      ctx,\n      protocol.createMessage(SwarmRequestSchema, {\n        serviceId: EdgeService.SWARM,\n        source: createMessageSource(topic, {\n          peerKey: this._edgeConnection.peerKey,\n          identityDid: this._edgeConnection.identityDid,\n        }),\n        payload: { action: SwarmRequestAction.INFO, swarmKeys: [topic.toHex()] },\n      }),\n    );\n\n    return response;\n  }\n\n  async sendMessage(ctx: Context, message: Message): Promise<void> {\n    const { author, recipient, tags, payload } = message;\n    // Exactly one of point-to-point (`recipient`) or broadcast (`tags`) delivery (DX-1125). A broadcast\n    // carries its target swarm in `author.swarmKey` and is published with no `target`; the edge fans it\n    // out to every peer whose subscription tags intersect.\n    invariant((recipient == null) !== !tags?.length, 'Exactly one of `recipient` or `tags` must be set');\n\n    if (!this._matchSelfPeerInfo(author)) {\n      // NOTE: Could only join swarm with the same peer info as the edge connection.\n      log.warn('ignoring author on send request', {\n        author,\n        expected: { peerKey: this._edgeConnection.peerKey, identityDid: this._edgeConnection.identityDid },\n      });\n    }\n\n    await this._edgeConnection.send(\n      ctx,\n      protocol.createMessage(bufWkt.AnySchema, {\n        serviceId: EdgeService.SIGNAL,\n        source: author,\n        target: recipient != null ? [recipient] : undefined,\n        tags,\n        payload: { typeUrl: payload.type_url, value: payload.value },\n      }),\n    );\n  }\n\n  async subscribeMessages({ peer, tags = [], onMessage }: SubscribeMessagesParams): Promise<UnsubscribeCallback> {\n    const subscription: MessageSubscription = { peerKey: peer.peerKey, tags: new Set(tags), onMessage };\n    this._subscriptions.add(subscription);\n\n    // Point-to-point delivery needs no edge registration (the edge relays targeted messages to this\n    // peer's socket). Only tag broadcasts require an OR-subscription registered on the swarm (DX-1125),\n    // refcounted so one subscriber's teardown does not clobber another's identical tags.\n    let changed = false;\n    for (const tag of subscription.tags) {\n      const count = this._subscribedTags.get(tag) ?? 0;\n      this._subscribedTags.set(tag, count + 1);\n      if (count === 0) {\n        changed = true;\n      }\n    }\n    if (changed) {\n      await this._sendSubscription(this._ctx);\n    }\n\n    return async () => {\n      this._subscriptions.delete(subscription);\n      // Release only this subscription's tag registrations; a tag stays live while another holds it.\n      let released = false;\n      for (const tag of subscription.tags) {\n        const count = this._subscribedTags.get(tag);\n        if (count === undefined) {\n          continue;\n        }\n        if (count > 1) {\n          this._subscribedTags.set(tag, count - 1);\n        } else {\n          this._subscribedTags.delete(tag);\n          released = true;\n        }\n      }\n      if (released) {\n        await this._sendSubscription(this._ctx);\n      }\n    };\n  }\n\n  /**\n   * Send the current broadcast tag subscription to every joined swarm (DX-1125). An empty tag set\n   * clears the subscription on the edge.\n   */\n  private async _sendSubscription(ctx: Context): Promise<void> {\n    const swarmKeys = Array.from(this._swarmPeers.keys()).map((topic) => topic.toHex());\n    if (swarmKeys.length === 0) {\n      return;\n    }\n    await this._edgeConnection.send(\n      ctx,\n      protocol.createMessage(SwarmRequestSchema, {\n        serviceId: EdgeService.SWARM,\n        source: {\n          peerKey: this._edgeConnection.peerKey,\n          identityDid: this._edgeConnection.identityDid,\n        },\n        payload: {\n          action: SwarmRequestAction.SUBSCRIBE,\n          swarmKeys,\n          subscribeTags: Array.from(this._subscribedTags.keys()),\n        },\n      }),\n    );\n  }\n\n  private _onMessage(message: EdgeMessage): void {\n    switch (message.serviceId) {\n      case EdgeService.SWARM: {\n        this._processSwarmResponse(message);\n        break;\n      }\n      case EdgeService.SIGNAL: {\n        this._processMessage(message);\n      }\n    }\n  }\n\n  private _processSwarmResponse(message: EdgeMessage): void {\n    invariant(protocol.getPayloadType(message) === SwarmResponseSchema.typeName, 'Wrong payload type');\n    const payload = protocol.getPayload(message, SwarmResponseSchema);\n    this.swarmState.emit(payload);\n    const topic = PublicKey.from(payload.swarmKey);\n    if (!this._swarmPeers.has(topic)) {\n      return;\n    }\n\n    const { joinedPeers: oldPeers } = this._swarmPeers.get(topic)!;\n    const timestamp = message.timestamp ? new Date(Date.parse(message.timestamp)) : new Date();\n    const newPeers = new ComplexSet<PeerInfo>(PeerInfoHash, payload.peers);\n\n    // Emit new available peers in the swarm.\n    for (const peer of newPeers) {\n      if (oldPeers.has(peer)) {\n        continue;\n      }\n      this.swarmEvent.emit({\n        topic,\n        peerAvailable: { peer, since: timestamp },\n      });\n    }\n\n    // Emit peer that left the swarm.\n    for (const peer of oldPeers) {\n      if (newPeers.has(peer)) {\n        continue;\n      }\n      this.swarmEvent.emit({\n        topic,\n        peerLeft: { peer },\n      });\n    }\n\n    this._swarmPeers.get(topic)!.joinedPeers = newPeers;\n  }\n\n  private _processMessage(message: EdgeMessage): void {\n    invariant(protocol.getPayloadType(message) === bufWkt.AnySchema.typeName, 'Wrong payload type');\n    const payload = protocol.getPayload(message, bufWkt.AnySchema);\n    invariant(message.source, 'source is missing');\n\n    // Broadcasts (DX-1125) carry tags and no target; point-to-point messages carry exactly one target.\n    if ((message.tags?.length ?? 0) > 0 && (message.target?.length ?? 0) === 0) {\n      this._deliver({\n        author: message.source,\n        tags: message.tags ?? [],\n        payload: { type_url: payload.typeUrl, value: payload.value },\n      });\n      return;\n    }\n\n    invariant(message.target, 'target is missing');\n    invariant(message.target.length === 1, 'target should have exactly one item');\n\n    this._deliver({\n      author: message.source,\n      recipient: message.target[0],\n      payload: {\n        type_url: payload.typeUrl,\n        value: payload.value,\n      },\n    });\n  }\n\n  /**\n   * Route an incoming message to matching subscriptions (DX-1125): point-to-point by recipient\n   * `peerKey`, broadcasts by tag intersection.\n   */\n  private _deliver(message: Message): void {\n    for (const subscription of this._subscriptions) {\n      if (message.recipient != null) {\n        if (subscription.peerKey === message.recipient.peerKey) {\n          subscription.onMessage(message);\n        }\n      } else if (message.tags?.some((tag) => subscription.tags.has(tag))) {\n        subscription.onMessage(message);\n      }\n    }\n  }\n\n  private _matchSelfPeerInfo(peer: PeerInfo): boolean {\n    return Boolean(\n      peer && (peer.peerKey === this._edgeConnection.peerKey || peer.identityDid === this._edgeConnection.identityDid),\n    );\n  }\n\n  private async _rejoinAllSwarms(): Promise<void> {\n    log('rejoin swarms', { swarms: Array.from(this._swarmPeers.keys()) });\n    for (const [topic, { lastState }] of this._swarmPeers.entries()) {\n      await this.join(this._ctx, {\n        topic,\n        peer: {\n          peerKey: this._edgeConnection.peerKey,\n          identityDid: this._edgeConnection.identityDid,\n          state: lastState,\n        },\n      });\n    }\n    // Re-establish the broadcast subscription across the rejoined swarms (DX-1125).\n    if (this._subscribedTags.size > 0) {\n      await this._sendSubscription(this._ctx);\n    }\n  }\n}\n\nconst createMessageSource = (topic: PublicKey, peerInfo: PeerInfo): buf.MessageInitShape<typeof PeerSchema> => {\n  return {\n    swarmKey: topic.toHex(),\n    ...peerInfo,\n  };\n};\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Runtime from 'effect/Runtime';\n\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { subscribeStream } from '@dxos/protocols';\nimport { DeviceKind } from '@dxos/protocols/proto/dxos/client/services';\nimport { type DevicesService, type IdentityService } from '@dxos/protocols/rpc';\n\nexport const setIdentityTags = ({\n  identityService,\n  devicesService,\n  runtime = Runtime.defaultRuntime,\n  setTag,\n}: {\n  identityService: IdentityService.Client;\n  devicesService: DevicesService.Client;\n  runtime?: Runtime.Runtime<never>;\n  setTag: (k: string, v: string) => void;\n}) => {\n  subscribeStream(runtime, identityService.IdentityService.queryIdentity(undefined), {\n    onData: (idqr) => {\n      if (!idqr?.identity?.identityKey) {\n        log('empty response from identity service', { idqr });\n        return;\n      }\n\n      setTag('identityKey', idqr.identity.identityKey.truncate());\n    },\n  });\n\n  subscribeStream(runtime, devicesService.DevicesService.queryDevices(undefined), {\n    onData: (dqr) => {\n      if (!dqr || !dqr.devices || dqr.devices.length === 0) {\n        log('empty response from device service', { device: dqr });\n        return;\n      }\n      invariant(dqr, 'empty response from device service');\n\n      const thisDevice = dqr.devices.find((device) => device.kind === DeviceKind.CURRENT);\n      if (!thisDevice) {\n        log('no current device', { device: dqr });\n        return;\n      }\n      setTag('deviceKey', thisDevice.deviceKey.truncate());\n    },\n  });\n};\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,IAAa,uBAAb,cAA0C,UAAQ,IAAI,+BAA+B,CAAC,CAGpF,CAAC,CAAC,C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