@pipecat-ai/daily-transport 0.3.5 → 0.3.7
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.
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -25
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +83 -25
- package/dist/index.module.js.map +1 -1
- package/package.json +3 -3
package/dist/index.module.js
CHANGED
|
@@ -1427,6 +1427,49 @@ var $683f111f61e07358$export$ef180de88fd317cc;
|
|
|
1427
1427
|
DailyRTVIMessageType["AUDIO_BUFFERING_STARTED"] = "audio-buffering-started";
|
|
1428
1428
|
DailyRTVIMessageType["AUDIO_BUFFERING_STOPPED"] = "audio-buffering-stopped";
|
|
1429
1429
|
})($683f111f61e07358$export$ef180de88fd317cc || ($683f111f61e07358$export$ef180de88fd317cc = {}));
|
|
1430
|
+
class $683f111f61e07358$var$DailyCallWrapper {
|
|
1431
|
+
constructor(daily){
|
|
1432
|
+
this._daily = daily;
|
|
1433
|
+
this._proxy = new Proxy(this._daily, {
|
|
1434
|
+
get: (target, prop, receiver)=>{
|
|
1435
|
+
if (typeof target[prop] === "function") {
|
|
1436
|
+
let errMsg;
|
|
1437
|
+
switch(String(prop)){
|
|
1438
|
+
// Disable methods that modify the lifecycle of the call. These operations
|
|
1439
|
+
// should be performed via the RTVI client in order to keep state in sync.
|
|
1440
|
+
case "preAuth":
|
|
1441
|
+
errMsg = `Calls to preAuth() are disabled. Please use Transport.preAuth()`;
|
|
1442
|
+
break;
|
|
1443
|
+
case "startCamera":
|
|
1444
|
+
errMsg = `Calls to startCamera() are disabled. Please use RTVIClient.initDevices() or Transport.initDevices()`;
|
|
1445
|
+
break;
|
|
1446
|
+
case "join":
|
|
1447
|
+
errMsg = `Calls to join() are disabled. Please use RTVIClient.connect()`;
|
|
1448
|
+
break;
|
|
1449
|
+
case "leave":
|
|
1450
|
+
errMsg = `Calls to leave() are disabled. Please use RTVIClient.disconnect()`;
|
|
1451
|
+
break;
|
|
1452
|
+
case "destroy":
|
|
1453
|
+
errMsg = `Calls to destroy() are disabled.`;
|
|
1454
|
+
break;
|
|
1455
|
+
}
|
|
1456
|
+
if (errMsg) return ()=>{
|
|
1457
|
+
throw new Error(errMsg);
|
|
1458
|
+
};
|
|
1459
|
+
// Forward other method calls
|
|
1460
|
+
return (...args)=>{
|
|
1461
|
+
return target[prop](...args);
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
// Forward property access
|
|
1465
|
+
return Reflect.get(target, prop, receiver);
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
get proxy() {
|
|
1470
|
+
return this._proxy;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1430
1473
|
class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
1431
1474
|
constructor({ dailyFactoryOptions: dailyFactoryOptions = {}, bufferLocalAudioUntilBotReady: bufferLocalAudioUntilBotReady = false } = {}){
|
|
1432
1475
|
super();
|
|
@@ -1436,8 +1479,14 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1436
1479
|
this._selectedSpeaker = {};
|
|
1437
1480
|
this._currentAudioTrack = null;
|
|
1438
1481
|
this._audioQueue = [];
|
|
1482
|
+
this._callbacks = {};
|
|
1439
1483
|
this._dailyFactoryOptions = dailyFactoryOptions;
|
|
1440
1484
|
this._bufferLocalAudioUntilBotReady = bufferLocalAudioUntilBotReady;
|
|
1485
|
+
this._daily = (0, $7zbD8$dailycodailyjs).createCallObject({
|
|
1486
|
+
...this._dailyFactoryOptions,
|
|
1487
|
+
allowMultipleCallInstances: true
|
|
1488
|
+
});
|
|
1489
|
+
this._dailyWrapper = new $683f111f61e07358$var$DailyCallWrapper(this._daily);
|
|
1441
1490
|
}
|
|
1442
1491
|
setupRecorder() {
|
|
1443
1492
|
this._mediaStreamRecorder = new (0, $5fc11d7bc0d20724$export$2934cf2d25c67a48)({
|
|
@@ -1467,9 +1516,9 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1467
1516
|
return btoa(String.fromCharCode(...pcmByteArray));
|
|
1468
1517
|
});
|
|
1469
1518
|
const rtviMessage = {
|
|
1470
|
-
id:
|
|
1471
|
-
label:
|
|
1472
|
-
type:
|
|
1519
|
+
id: "raw-audio-batch",
|
|
1520
|
+
label: "rtvi-ai",
|
|
1521
|
+
type: "raw-audio-batch",
|
|
1473
1522
|
data: {
|
|
1474
1523
|
base64AudioBatch: encodedBatch,
|
|
1475
1524
|
sampleRate: $683f111f61e07358$export$b1ca982aa1e488c1.RECORDER_SAMPLE_RATE,
|
|
@@ -1482,20 +1531,17 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1482
1531
|
if (this._bufferLocalAudioUntilBotReady) this.setupRecorder();
|
|
1483
1532
|
this._callbacks = options.callbacks ?? {};
|
|
1484
1533
|
this._onMessage = messageHandler;
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
this.
|
|
1488
|
-
|
|
1489
|
-
// Default is cam off
|
|
1490
|
-
startVideoOff: options.enableCam != true,
|
|
1491
|
-
// Default is mic on
|
|
1492
|
-
startAudioOff: options.enableMic == false,
|
|
1493
|
-
allowMultipleCallInstances: true
|
|
1494
|
-
});
|
|
1534
|
+
if (this._dailyFactoryOptions.startVideoOff == null || options.enableCam != null) // Default is cam off
|
|
1535
|
+
this._dailyFactoryOptions.startVideoOff = !(options.enableCam ?? false);
|
|
1536
|
+
if (this._dailyFactoryOptions.startAudioOff == null || options.enableMic != null) // Default is mic on
|
|
1537
|
+
this._dailyFactoryOptions.startAudioOff = !(options.enableMic ?? true);
|
|
1495
1538
|
this.attachEventListeners();
|
|
1496
1539
|
this.state = "disconnected";
|
|
1497
1540
|
(0, $7zbD8$logger).debug("[RTVI Transport] Initialized");
|
|
1498
1541
|
}
|
|
1542
|
+
get dailyCallClient() {
|
|
1543
|
+
return this._dailyWrapper.proxy;
|
|
1544
|
+
}
|
|
1499
1545
|
get state() {
|
|
1500
1546
|
return this._state;
|
|
1501
1547
|
}
|
|
@@ -1566,7 +1612,7 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1566
1612
|
return this._daily.localScreenAudio() || this._daily.localScreenVideo();
|
|
1567
1613
|
}
|
|
1568
1614
|
tracks() {
|
|
1569
|
-
const participants = this._daily
|
|
1615
|
+
const participants = this._daily.participants() ?? {};
|
|
1570
1616
|
const bot = participants?.[this._botId];
|
|
1571
1617
|
const tracks = {
|
|
1572
1618
|
local: {
|
|
@@ -1584,7 +1630,7 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1584
1630
|
}
|
|
1585
1631
|
async startRecording() {
|
|
1586
1632
|
try {
|
|
1587
|
-
(0, $7zbD8$logger).info(
|
|
1633
|
+
(0, $7zbD8$logger).info("[RTVI Transport] Initializing recording");
|
|
1588
1634
|
await this._mediaStreamRecorder.record((data)=>{
|
|
1589
1635
|
this.handleUserAudioStream(data.mono);
|
|
1590
1636
|
}, $683f111f61e07358$export$b1ca982aa1e488c1.RECORDER_CHUNK_SIZE);
|
|
@@ -1592,12 +1638,16 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1592
1638
|
type: $683f111f61e07358$export$ef180de88fd317cc.AUDIO_BUFFERING_STARTED,
|
|
1593
1639
|
data: {}
|
|
1594
1640
|
});
|
|
1595
|
-
(0, $7zbD8$logger).info(
|
|
1641
|
+
(0, $7zbD8$logger).info("[RTVI Transport] Recording Initialized");
|
|
1596
1642
|
} catch (e) {
|
|
1597
1643
|
const err = e;
|
|
1598
1644
|
if (!err.message.includes("Already recording")) (0, $7zbD8$logger).error("Error starting recording", e);
|
|
1599
1645
|
}
|
|
1600
1646
|
}
|
|
1647
|
+
async preAuth(dailyFactoryOptions) {
|
|
1648
|
+
this._dailyFactoryOptions = dailyFactoryOptions;
|
|
1649
|
+
await this._daily.preAuth(dailyFactoryOptions);
|
|
1650
|
+
}
|
|
1601
1651
|
async initDevices() {
|
|
1602
1652
|
if (!this._daily) throw new (0, $7zbD8$RTVIError)("Transport instance not initialized");
|
|
1603
1653
|
this.state = "initializing";
|
|
@@ -1606,14 +1656,14 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1606
1656
|
const cams = devices.filter((d)=>d.kind === "videoinput");
|
|
1607
1657
|
const mics = devices.filter((d)=>d.kind === "audioinput");
|
|
1608
1658
|
const speakers = devices.filter((d)=>d.kind === "audiooutput");
|
|
1659
|
+
this._selectedCam = infos.camera;
|
|
1660
|
+
this._selectedMic = infos.mic;
|
|
1661
|
+
this._selectedSpeaker = infos.speaker;
|
|
1609
1662
|
this._callbacks.onAvailableCamsUpdated?.(cams);
|
|
1610
1663
|
this._callbacks.onAvailableMicsUpdated?.(mics);
|
|
1611
1664
|
this._callbacks.onAvailableSpeakersUpdated?.(speakers);
|
|
1612
|
-
this._selectedCam = infos.camera;
|
|
1613
1665
|
this._callbacks.onCamUpdated?.(infos.camera);
|
|
1614
|
-
this._selectedMic = infos.mic;
|
|
1615
1666
|
this._callbacks.onMicUpdated?.(infos.mic);
|
|
1616
|
-
this._selectedSpeaker = infos.speaker;
|
|
1617
1667
|
this._callbacks.onSpeakerUpdated?.(infos.speaker);
|
|
1618
1668
|
// Instantiate audio observers
|
|
1619
1669
|
if (!this._daily.isLocalAudioLevelObserverRunning()) await this._daily.startLocalAudioLevelObserver(100);
|
|
@@ -1624,14 +1674,15 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1624
1674
|
if (!this._daily) throw new (0, $7zbD8$RTVIError)("Transport instance not initialized");
|
|
1625
1675
|
if (abortController.signal.aborted) return;
|
|
1626
1676
|
this.state = "connecting";
|
|
1677
|
+
const opts = this._dailyFactoryOptions;
|
|
1678
|
+
opts.url = authBundle.room_url ?? opts.url;
|
|
1679
|
+
if (authBundle.token != null) opts.token = authBundle.token;
|
|
1627
1680
|
try {
|
|
1628
|
-
await this._daily.join(
|
|
1629
|
-
url: authBundle.room_url,
|
|
1630
|
-
token: authBundle.token
|
|
1631
|
-
});
|
|
1681
|
+
await this._daily.join(opts);
|
|
1632
1682
|
const room = await this._daily.room();
|
|
1633
1683
|
if (room && "id" in room) this._expiry = room.config?.exp;
|
|
1634
1684
|
} catch (e) {
|
|
1685
|
+
(0, $7zbD8$logger).error("Failed to join room", e);
|
|
1635
1686
|
this.state = "error";
|
|
1636
1687
|
throw new (0, $7zbD8$TransportStartError)();
|
|
1637
1688
|
}
|
|
@@ -1677,16 +1728,17 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1677
1728
|
this._daily.on("remote-participants-audio-level", this.handleRemoteAudioLevel.bind(this));
|
|
1678
1729
|
this._daily.on("app-message", this.handleAppMessage.bind(this));
|
|
1679
1730
|
this._daily.on("left-meeting", this.handleLeftMeeting.bind(this));
|
|
1731
|
+
this._daily.on("error", this.handleFatalError.bind(this));
|
|
1680
1732
|
this._daily.on("nonfatal-error", this.handleNonFatalError.bind(this));
|
|
1681
1733
|
}
|
|
1682
1734
|
async disconnect() {
|
|
1735
|
+
this.state = "disconnecting";
|
|
1683
1736
|
this._daily.stopLocalAudioLevelObserver();
|
|
1684
1737
|
this._daily.stopRemoteParticipantsAudioLevelObserver();
|
|
1685
1738
|
this._audioQueue = [];
|
|
1686
1739
|
this._currentAudioTrack = null;
|
|
1687
1740
|
this.stopRecording();
|
|
1688
1741
|
await this._daily.leave();
|
|
1689
|
-
await this._daily.destroy();
|
|
1690
1742
|
}
|
|
1691
1743
|
sendMessage(message) {
|
|
1692
1744
|
this._daily.sendAppMessage(message, "*");
|
|
@@ -1778,10 +1830,16 @@ class $683f111f61e07358$export$b1ca982aa1e488c1 extends (0, $7zbD8$Transport) {
|
|
|
1778
1830
|
}
|
|
1779
1831
|
}
|
|
1780
1832
|
handleLeftMeeting() {
|
|
1781
|
-
this.state = "
|
|
1833
|
+
this.state = "disconnected";
|
|
1782
1834
|
this._botId = "";
|
|
1783
1835
|
this._callbacks.onDisconnected?.();
|
|
1784
1836
|
}
|
|
1837
|
+
handleFatalError(ev) {
|
|
1838
|
+
(0, $7zbD8$logger).error("Daily fatal error", ev.errorMsg);
|
|
1839
|
+
this.state = "error";
|
|
1840
|
+
this._botId = "";
|
|
1841
|
+
this._callbacks.onError?.((0, $7zbD8$RTVIMessage).error(ev.errorMsg, true));
|
|
1842
|
+
}
|
|
1785
1843
|
handleNonFatalError(ev) {
|
|
1786
1844
|
switch(ev.type){
|
|
1787
1845
|
case "screen-share-error":
|