{"version":3,"file":"RemoteDataTrack.mjs","sources":["../../../../src/room/data-track/RemoteDataTrack.ts"],"sourcesContent":["import type Participant from '../participant/Participant';\nimport { type DataTrackFrame } from './frame';\nimport type IncomingDataTrackManager from './incoming/IncomingDataTrackManager';\nimport {\n  DataTrackSymbol,\n  type IDataTrack,\n  type IRemoteTrack,\n  TrackSymbol,\n} from './track-interfaces';\nimport { type DataTrackInfo, type RemoteDataTrackPipelineOptions } from './types';\n\ntype RemoteDataTrackOptions = {\n  publisherIdentity: Participant['identity'];\n};\n\nexport type DataTrackSubscribeOptions = {\n  signal?: AbortSignal;\n\n  /** The number of {@link DataTrackFrame}s to hold in the ReadableStream before disgarding extra\n   * frames. Defaults to 16, but this may not be good enough for especially high frequency data. */\n  bufferSize?: number;\n};\n\nexport default class RemoteDataTrack implements IRemoteTrack, IDataTrack {\n  readonly trackSymbol = TrackSymbol;\n\n  readonly isLocal = false;\n\n  readonly typeSymbol = DataTrackSymbol;\n\n  info: DataTrackInfo;\n\n  publisherIdentity: Participant['identity'];\n\n  protected manager: IncomingDataTrackManager;\n\n  /** @internal */\n  constructor(\n    info: DataTrackInfo,\n    manager: IncomingDataTrackManager,\n    options: RemoteDataTrackOptions,\n  ) {\n    this.info = info;\n    this.manager = manager;\n    this.publisherIdentity = options.publisherIdentity;\n  }\n\n  /** Subscribes to the data track to receive frames.\n   *\n   * # Returns\n   *\n   * A stream that yields {@link DataTrackFrame}s as they arrive.\n   *\n   * # Multiple Subscriptions\n   *\n   * An application may call `subscribe` more than once to process frames in\n   * multiple places. For example, one async task might plot values on a graph\n   * while another writes them to a file.\n   *\n   * Internally, only the first call to `subscribe` communicates with the SFU and\n   * allocates the resources required to receive frames. Additional subscriptions\n   * reuse the same underlying pipeline and do not trigger additional signaling.\n   *\n   * Note that newly created subscriptions only receive frames published after\n   * the initial subscription is established.\n   */\n  subscribe(options?: DataTrackSubscribeOptions): ReadableStream<DataTrackFrame> {\n    try {\n      const [stream, sfuSubscriptionComplete] = this.manager.openSubscriptionStream(\n        this.info.sid,\n        options?.signal,\n        options?.bufferSize,\n      );\n      // Prevent uncaught promise rejections from bubbling up if rejections occur after the\n      // readable stream is discarded.\n      sfuSubscriptionComplete.catch(() => {});\n      return stream;\n    } catch (err) {\n      // NOTE: Rethrow errors to break Throws<...> type boundary\n      throw err;\n    }\n  }\n\n  /** Configure how incoming frames for this track are processed before they are handed out to\n   * subscribers (the \"pipeline\"). These options apply to all current and future subscriptions\n   * of this track, and may be set at any time. */\n  setPipelineOptions(options: RemoteDataTrackPipelineOptions): void {\n    this.manager.setPipelineOptions(this.info.sid, options);\n  }\n}\n"],"names":["RemoteDataTrack","constructor","info","manager","options","trackSymbol","TrackSymbol","isLocal","typeSymbol","DataTrackSymbol","publisherIdentity","subscribe","_this$manager$openSub","openSubscriptionStream","sid","signal","bufferSize","_this$manager$openSub2","_slicedToArray","stream","sfuSubscriptionComplete","catch","err","setPipelineOptions"],"mappings":"2OAuBc,MAAOA,eAAe,CAAA;AAalC;AACAC,EAAAA,WAAAA,CACEC,IAAmB,EACnBC,OAAiC,EACjCC,OAA+B,EAAA;IAhBxB,IAAA,CAAAC,WAAW,GAAGC,WAAW;IAEzB,IAAA,CAAAC,OAAO,GAAG,KAAK;IAEf,IAAA,CAAAC,UAAU,GAAGC,eAAe;IAcnC,IAAI,CAACP,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;AACtB,IAAA,IAAI,CAACO,iBAAiB,GAAGN,OAAO,CAACM,iBAAiB;AACpD,EAAA;AAEA;;;;;;;;;;;;;;;;;;AAkBG;EACHC,SAASA,CAACP,OAAmC,EAAA;IAC3C,IAAI;MACF,MAAAQ,qBAAA,GAA0C,IAAI,CAACT,OAAO,CAACU,sBAAsB,CAC3E,IAAI,CAACX,IAAI,CAACY,GAAG,EACbV,OAAO,KAAA,IAAA,IAAPA,OAAO,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAPA,OAAO,CAAEW,MAAM,EAC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