@pipecat-ai/daily-transport 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1427,7 +1427,7 @@ globalThis.WavRecorder = WavRecorder;
1427
1427
 
1428
1428
 
1429
1429
  var $58d19ff082af5e5c$exports = {};
1430
- $58d19ff082af5e5c$exports = JSON.parse("{\"name\":\"@pipecat-ai/daily-transport\",\"version\":\"0.4.0\",\"license\":\"BSD-2-Clause\",\"main\":\"dist/index.js\",\"module\":\"dist/index.module.js\",\"types\":\"dist/index.d.ts\",\"source\":\"src/index.ts\",\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/pipecat-ai/pipecat-client-web-transports.git\"},\"files\":[\"dist\",\"package.json\",\"README.md\"],\"scripts\":{\"build\":\"parcel build --no-cache\",\"dev\":\"parcel watch\",\"lint\":\"eslint . --ext ts --report-unused-disable-directives --max-warnings 0\"},\"devDependencies\":{\"@pipecat-ai/client-js\":\"^0.4.0\",\"eslint\":\"9.11.1\",\"eslint-config-prettier\":\"^9.1.0\",\"eslint-plugin-simple-import-sort\":\"^12.1.1\"},\"peerDependencies\":{\"@pipecat-ai/client-js\":\"~0.4.0\"},\"dependencies\":{\"@daily-co/daily-js\":\"^0.77.0\"},\"description\":\"Pipecat Daily Transport Package\",\"author\":\"Daily.co\",\"bugs\":{\"url\":\"https://github.com/pipecat-ai/pipecat-client-web-transports/issues\"},\"homepage\":\"https://github.com/pipecat-ai/pipecat-client-web-transports/blob/main/transports/daily-webrtc/README.md\"}");
1430
+ $58d19ff082af5e5c$exports = JSON.parse("{\"name\":\"@pipecat-ai/daily-transport\",\"version\":\"1.0.0\",\"license\":\"BSD-2-Clause\",\"main\":\"dist/index.js\",\"module\":\"dist/index.module.js\",\"types\":\"dist/index.d.ts\",\"source\":\"src/index.ts\",\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/pipecat-ai/pipecat-client-web-transports.git\"},\"files\":[\"dist\",\"package.json\",\"README.md\"],\"scripts\":{\"build\":\"parcel build --no-cache\",\"dev\":\"parcel watch\",\"lint\":\"eslint . --ext ts --report-unused-disable-directives --max-warnings 0\"},\"devDependencies\":{\"@pipecat-ai/client-js\":\"^1.0.0\",\"eslint\":\"9.11.1\",\"eslint-config-prettier\":\"^9.1.0\",\"eslint-plugin-simple-import-sort\":\"^12.1.1\"},\"peerDependencies\":{\"@pipecat-ai/client-js\":\"~1.0.0\"},\"dependencies\":{\"@daily-co/daily-js\":\"^0.77.0\"},\"description\":\"Pipecat Daily Transport Package\",\"author\":\"Daily.co\",\"bugs\":{\"url\":\"https://github.com/pipecat-ai/pipecat-client-web-transports/issues\"},\"homepage\":\"https://github.com/pipecat-ai/pipecat-client-web-transports/blob/main/transports/daily-webrtc/README.md\"}");
1431
1431
 
1432
1432
 
1433
1433
  var $683f111f61e07358$export$ef180de88fd317cc;
@@ -1444,18 +1444,18 @@ class $683f111f61e07358$var$DailyCallWrapper {
1444
1444
  let errMsg;
1445
1445
  switch(String(prop)){
1446
1446
  // Disable methods that modify the lifecycle of the call. These operations
1447
- // should be performed via the RTVI client in order to keep state in sync.
1447
+ // should be performed via the PipecatClient in order to keep state in sync.
1448
1448
  case "preAuth":
1449
1449
  errMsg = `Calls to preAuth() are disabled. Please use Transport.preAuth()`;
1450
1450
  break;
1451
1451
  case "startCamera":
1452
- errMsg = `Calls to startCamera() are disabled. Please use RTVIClient.initDevices()`;
1452
+ errMsg = `Calls to startCamera() are disabled. Please use PipecatClient.initDevices()`;
1453
1453
  break;
1454
1454
  case "join":
1455
- errMsg = `Calls to join() are disabled. Please use RTVIClient.connect()`;
1455
+ errMsg = `Calls to join() are disabled. Please use PipecatClient.connect()`;
1456
1456
  break;
1457
1457
  case "leave":
1458
- errMsg = `Calls to leave() are disabled. Please use RTVIClient.disconnect()`;
1458
+ errMsg = `Calls to leave() are disabled. Please use PipecatClient.disconnect()`;
1459
1459
  break;
1460
1460
  case "destroy":
1461
1461
  errMsg = `Calls to destroy() are disabled.`;
@@ -1479,7 +1479,7 @@ class $683f111f61e07358$var$DailyCallWrapper {
1479
1479
  }
1480
1480
  }
1481
1481
  class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1482
- constructor({ dailyFactoryOptions: dailyFactoryOptions = {}, bufferLocalAudioUntilBotReady: bufferLocalAudioUntilBotReady = false } = {}){
1482
+ constructor(opts = {}){
1483
1483
  super();
1484
1484
  this._botId = "";
1485
1485
  this._selectedCam = {};
@@ -1488,8 +1488,9 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1488
1488
  this._currentAudioTrack = null;
1489
1489
  this._audioQueue = [];
1490
1490
  this._callbacks = {};
1491
- this._dailyFactoryOptions = dailyFactoryOptions;
1492
- this._bufferLocalAudioUntilBotReady = bufferLocalAudioUntilBotReady;
1491
+ const { bufferLocalAudioUntilBotReady: bufferLocalAudioUntilBotReady, ...dailyOpts } = opts;
1492
+ this._dailyFactoryOptions = dailyOpts;
1493
+ this._bufferLocalAudioUntilBotReady = bufferLocalAudioUntilBotReady || false;
1493
1494
  this._daily = (0, $7zbD8$dailycodailyjs).createCallObject({
1494
1495
  ...this._dailyFactoryOptions,
1495
1496
  allowMultipleCallInstances: true
@@ -1523,7 +1524,7 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1523
1524
  const pcmByteArray = new Uint8Array(data);
1524
1525
  return btoa(String.fromCharCode(...pcmByteArray));
1525
1526
  });
1526
- const rtviMessage = {
1527
+ const audioMessage = {
1527
1528
  id: "raw-audio-batch",
1528
1529
  label: "rtvi-ai",
1529
1530
  type: "raw-audio-batch",
@@ -1533,7 +1534,7 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1533
1534
  numChannels: 1
1534
1535
  }
1535
1536
  };
1536
- this.sendMessage(rtviMessage);
1537
+ this.sendMessage(audioMessage);
1537
1538
  }
1538
1539
  initialize(options, messageHandler) {
1539
1540
  if (this._bufferLocalAudioUntilBotReady) this.setupRecorder();
@@ -1545,7 +1546,7 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1545
1546
  this._dailyFactoryOptions.startAudioOff = !(options.enableMic ?? true);
1546
1547
  this.attachEventListeners();
1547
1548
  this.state = "disconnected";
1548
- (0, $7zbD8$logger).debug("[RTVI Transport] Initialized", (0, (/*@__PURE__*/$parcel$interopDefault($58d19ff082af5e5c$exports))).version);
1549
+ (0, $7zbD8$logger).debug("[Daily Transport] Initialized", (0, (/*@__PURE__*/$parcel$interopDefault($58d19ff082af5e5c$exports))).version);
1549
1550
  }
1550
1551
  get dailyCallClient() {
1551
1552
  return this._dailyWrapper.proxy;
@@ -1558,6 +1559,9 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1558
1559
  this._state = state;
1559
1560
  this._callbacks.onTransportStateChanged?.(state);
1560
1561
  }
1562
+ getSessionInfo() {
1563
+ return this._daily.meetingSessionSummary();
1564
+ }
1561
1565
  async getAllCams() {
1562
1566
  const { devices: devices } = await this._daily.enumerateDevices();
1563
1567
  return devices.filter((d)=>d.kind === "videoinput");
@@ -1638,23 +1642,20 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1638
1642
  }
1639
1643
  async startRecording() {
1640
1644
  try {
1641
- (0, $7zbD8$logger).info("[RTVI Transport] Initializing recording");
1645
+ (0, $7zbD8$logger).info("[Daily Transport] Initializing recording");
1642
1646
  await this._mediaStreamRecorder.record((data)=>{
1643
1647
  this.handleUserAudioStream(data.mono);
1644
1648
  }, $683f111f61e07358$export$b1ca982aa1e488c1.RECORDER_CHUNK_SIZE);
1645
- this._onMessage({
1646
- type: $683f111f61e07358$export$ef180de88fd317cc.AUDIO_BUFFERING_STARTED,
1647
- data: {}
1648
- });
1649
- (0, $7zbD8$logger).info("[RTVI Transport] Recording Initialized");
1649
+ this._callbacks.onAudioBufferingStarted?.();
1650
+ (0, $7zbD8$logger).info("[Daily Transport] Recording Initialized");
1650
1651
  } catch (e) {
1651
1652
  const err = e;
1652
1653
  if (!err.message.includes("Already recording")) (0, $7zbD8$logger).error("Error starting recording", e);
1653
1654
  }
1654
1655
  }
1655
- async preAuth(dailyFactoryOptions) {
1656
- this._dailyFactoryOptions = dailyFactoryOptions;
1657
- await this._daily.preAuth(dailyFactoryOptions);
1656
+ async preAuth(dailyCallOptions) {
1657
+ this._dailyFactoryOptions = dailyCallOptions;
1658
+ await this._daily.preAuth(dailyCallOptions);
1658
1659
  }
1659
1660
  async initDevices() {
1660
1661
  if (!this._daily) throw new (0, $7zbD8$RTVIError)("Transport instance not initialized");
@@ -1678,23 +1679,33 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1678
1679
  if (!this._daily.isRemoteParticipantsAudioLevelObserverRunning()) await this._daily.startRemoteParticipantsAudioLevelObserver(100);
1679
1680
  this.state = "initialized";
1680
1681
  }
1681
- async connect(authBundle, abortController) {
1682
+ _validateConnectionParams(connectParams) {
1683
+ if (connectParams === undefined || connectParams === null) return undefined;
1684
+ if (typeof connectParams !== "object") throw new (0, $7zbD8$RTVIError)("Invalid connection parameters");
1685
+ const tmpParams = connectParams;
1686
+ if (tmpParams.room_url) {
1687
+ tmpParams.url = tmpParams.room_url;
1688
+ delete tmpParams.room_url;
1689
+ }
1690
+ if (!tmpParams.token) // Daily doesn't like token being in the map and undefined or null
1691
+ delete tmpParams.token;
1692
+ return tmpParams;
1693
+ }
1694
+ async _connect(connectParams) {
1682
1695
  if (!this._daily) throw new (0, $7zbD8$RTVIError)("Transport instance not initialized");
1683
- if (abortController.signal.aborted) return;
1696
+ if (connectParams) this._dailyFactoryOptions = {
1697
+ ...this._dailyFactoryOptions,
1698
+ ...connectParams
1699
+ };
1684
1700
  this.state = "connecting";
1685
- const opts = this._dailyFactoryOptions;
1686
- opts.url = authBundle.room_url ?? opts.url;
1687
- if (authBundle.token != null) opts.token = authBundle.token;
1688
1701
  try {
1689
- await this._daily.join(opts);
1690
- const room = await this._daily.room();
1691
- if (room && "id" in room) this._expiry = room.config?.exp;
1702
+ await this._daily.join(this._dailyFactoryOptions);
1692
1703
  } catch (e) {
1693
1704
  (0, $7zbD8$logger).error("Failed to join room", e);
1694
1705
  this.state = "error";
1695
1706
  throw new (0, $7zbD8$TransportStartError)();
1696
1707
  }
1697
- if (abortController.signal.aborted) return;
1708
+ if (this._abortController?.signal.aborted) return;
1698
1709
  this.state = "connected";
1699
1710
  this._callbacks.onConnected?.();
1700
1711
  }
@@ -1712,12 +1723,21 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1712
1723
  this.stopRecording();
1713
1724
  resolve();
1714
1725
  };
1726
+ for(const id in this._daily.participants()){
1727
+ const p = this._daily.participants()[id];
1728
+ if (!p.local && p.tracks?.audio?.persistentTrack) {
1729
+ // If we already have a remote audio track, we can send the ready message immediately
1730
+ sendReadyMessage();
1731
+ resolve();
1732
+ return;
1733
+ }
1734
+ }
1715
1735
  const readyHandler = (ev)=>{
1716
1736
  if (!ev.participant?.local) {
1717
1737
  this._daily.off("track-started", readyHandler);
1718
1738
  // Check if it's an iOS device
1719
1739
  if (isIOS()) {
1720
- (0, $7zbD8$logger).debug("[RTVI Transport] iOS device detected, adding 0.5 second delay before sending ready message");
1740
+ (0, $7zbD8$logger).debug("[Daily Transport] iOS device detected, adding 0.5 second delay before sending ready message");
1721
1741
  // Add 500ms delay for iOS devices:
1722
1742
  // This is a workaround for iOS devices clipping a portion
1723
1743
  // of the audio after the track becomes playable.
@@ -1733,10 +1753,7 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1733
1753
  if (this._mediaStreamRecorder && this._mediaStreamRecorder.getStatus() !== "ended") {
1734
1754
  // disconnecting, we don't need to record anymore
1735
1755
  this._mediaStreamRecorder.end();
1736
- this._onMessage({
1737
- type: $683f111f61e07358$export$ef180de88fd317cc.AUDIO_BUFFERING_STOPPED,
1738
- data: {}
1739
- });
1756
+ this._callbacks.onAudioBufferingStopped?.();
1740
1757
  }
1741
1758
  }
1742
1759
  attachEventListeners() {
@@ -1753,7 +1770,7 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
1753
1770
  this._daily.on("error", this.handleFatalError.bind(this));
1754
1771
  this._daily.on("nonfatal-error", this.handleNonFatalError.bind(this));
1755
1772
  }
1756
- async disconnect() {
1773
+ async _disconnect() {
1757
1774
  this.state = "disconnecting";
1758
1775
  this._daily.stopLocalAudioLevelObserver();
1759
1776
  this._daily.stopRemoteParticipantsAudioLevelObserver();