@hivegpt/hiveai-angular 0.0.429 → 0.0.431

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.
@@ -1271,6 +1271,8 @@
1271
1271
  this.callObject = null;
1272
1272
  this.localStream = null;
1273
1273
  this.localSessionId = null;
1274
+ /** Explicit playback of remote (bot) audio; required in some browsers. */
1275
+ this.remoteAudioElement = null;
1274
1276
  this.speakingSubject = new rxjs.BehaviorSubject(false);
1275
1277
  this.userSpeakingSubject = new rxjs.BehaviorSubject(false);
1276
1278
  this.micMutedSubject = new rxjs.BehaviorSubject(false);
@@ -1291,20 +1293,20 @@
1291
1293
  */
1292
1294
  DailyVoiceClientService.prototype.connect = function (roomUrl, token) {
1293
1295
  return __awaiter(this, void 0, void 0, function () {
1294
- var stream, audioTrack, callObject, participants, err_1;
1295
- return __generator(this, function (_c) {
1296
- switch (_c.label) {
1296
+ var stream, audioTrack, callObject, joinOptions, participants, err_1;
1297
+ return __generator(this, function (_e) {
1298
+ switch (_e.label) {
1297
1299
  case 0:
1298
1300
  if (!this.callObject) return [3 /*break*/, 2];
1299
1301
  return [4 /*yield*/, this.disconnect()];
1300
1302
  case 1:
1301
- _c.sent();
1302
- _c.label = 2;
1303
+ _e.sent();
1304
+ _e.label = 2;
1303
1305
  case 2:
1304
- _c.trys.push([2, 5, , 6]);
1306
+ _e.trys.push([2, 5, , 6]);
1305
1307
  return [4 /*yield*/, navigator.mediaDevices.getUserMedia({ audio: true })];
1306
1308
  case 3:
1307
- stream = _c.sent();
1309
+ stream = _e.sent();
1308
1310
  audioTrack = stream.getAudioTracks()[0];
1309
1311
  if (!audioTrack) {
1310
1312
  stream.getTracks().forEach(function (t) { return t.stop(); });
@@ -1318,11 +1320,13 @@
1318
1320
  });
1319
1321
  this.callObject = callObject;
1320
1322
  this.setupEventHandlers(callObject);
1321
- // Join room; Daily handles playback of remote (bot) audio automatically
1322
- return [4 /*yield*/, callObject.join({ url: roomUrl, token: token })];
1323
+ joinOptions = { url: roomUrl };
1324
+ if (typeof token === 'string' && token.trim() !== '') {
1325
+ joinOptions.token = token;
1326
+ }
1327
+ return [4 /*yield*/, callObject.join(joinOptions)];
1323
1328
  case 4:
1324
- // Join room; Daily handles playback of remote (bot) audio automatically
1325
- _c.sent();
1329
+ _e.sent();
1326
1330
  participants = callObject.participants();
1327
1331
  if (participants === null || participants === void 0 ? void 0 : participants.local) {
1328
1332
  this.localSessionId = participants.local.session_id;
@@ -1331,7 +1335,7 @@
1331
1335
  this.micMutedSubject.next(!callObject.localAudio());
1332
1336
  return [3 /*break*/, 6];
1333
1337
  case 5:
1334
- err_1 = _c.sent();
1338
+ err_1 = _e.sent();
1335
1339
  this.cleanup();
1336
1340
  throw err_1;
1337
1341
  case 6: return [2 /*return*/];
@@ -1357,16 +1361,21 @@
1357
1361
  _this.speakingSubject.next(!isLocal);
1358
1362
  });
1359
1363
  });
1360
- // track-started / track-stopped: fallback for immediate feedback when
1361
- // remote (bot) audio track starts or stops. Ensures talking indicator
1362
- // flips as soon as agent audio begins, without waiting for active-speaker-change.
1364
+ // track-started / track-stopped: play remote (bot) audio explicitly and update speaking state.
1365
+ // Browsers often do not auto-play remote WebRTC audio; attaching to an HTMLAudioElement and
1366
+ // calling play() ensures the user hears the agent.
1363
1367
  call.on('track-started', function (event) {
1364
1368
  _this.ngZone.run(function () {
1365
- var _a, _b;
1369
+ var _a, _b, _c, _d;
1366
1370
  var p = event === null || event === void 0 ? void 0 : event.participant;
1367
1371
  var type = (_a = event === null || event === void 0 ? void 0 : event.type) !== null && _a !== void 0 ? _a : (_b = event === null || event === void 0 ? void 0 : event.track) === null || _b === void 0 ? void 0 : _b.kind;
1372
+ var track = event === null || event === void 0 ? void 0 : event.track;
1368
1373
  if (p && !p.local && type === 'audio') {
1369
1374
  _this.speakingSubject.next(true);
1375
+ var audioTrack = track !== null && track !== void 0 ? track : (_d = (_c = p.tracks) === null || _c === void 0 ? void 0 : _c.audio) === null || _d === void 0 ? void 0 : _d.track;
1376
+ if (audioTrack && typeof audioTrack === 'object') {
1377
+ _this.playRemoteTrack(audioTrack);
1378
+ }
1370
1379
  }
1371
1380
  });
1372
1381
  });
@@ -1377,6 +1386,7 @@
1377
1386
  var type = (_a = event === null || event === void 0 ? void 0 : event.type) !== null && _a !== void 0 ? _a : (_b = event === null || event === void 0 ? void 0 : event.track) === null || _b === void 0 ? void 0 : _b.kind;
1378
1387
  if (p && !p.local && type === 'audio') {
1379
1388
  _this.speakingSubject.next(false);
1389
+ _this.stopRemoteAudio();
1380
1390
  }
1381
1391
  });
1382
1392
  });
@@ -1391,6 +1401,39 @@
1391
1401
  });
1392
1402
  });
1393
1403
  };
1404
+ /**
1405
+ * Play remote (bot) audio track via a dedicated audio element.
1406
+ * Required in many browsers where Daily's internal playback does not output to speakers.
1407
+ */
1408
+ DailyVoiceClientService.prototype.playRemoteTrack = function (track) {
1409
+ this.stopRemoteAudio();
1410
+ try {
1411
+ var stream = new MediaStream([track]);
1412
+ var audio = new Audio();
1413
+ audio.autoplay = true;
1414
+ audio.srcObject = stream;
1415
+ this.remoteAudioElement = audio;
1416
+ var p = audio.play();
1417
+ if (p && typeof p.catch === 'function') {
1418
+ p.catch(function (err) {
1419
+ console.warn('DailyVoiceClient: remote audio play failed (may need user gesture)', err);
1420
+ });
1421
+ }
1422
+ }
1423
+ catch (err) {
1424
+ console.warn('DailyVoiceClient: failed to create remote audio element', err);
1425
+ }
1426
+ };
1427
+ DailyVoiceClientService.prototype.stopRemoteAudio = function () {
1428
+ if (this.remoteAudioElement) {
1429
+ try {
1430
+ this.remoteAudioElement.pause();
1431
+ this.remoteAudioElement.srcObject = null;
1432
+ }
1433
+ catch (_) { }
1434
+ this.remoteAudioElement = null;
1435
+ }
1436
+ };
1394
1437
  /** Set mic muted state. */
1395
1438
  DailyVoiceClientService.prototype.setMuted = function (muted) {
1396
1439
  if (!this.callObject)
@@ -1402,22 +1445,22 @@
1402
1445
  DailyVoiceClientService.prototype.disconnect = function () {
1403
1446
  return __awaiter(this, void 0, void 0, function () {
1404
1447
  var e_1;
1405
- return __generator(this, function (_c) {
1406
- switch (_c.label) {
1448
+ return __generator(this, function (_e) {
1449
+ switch (_e.label) {
1407
1450
  case 0:
1408
1451
  if (!this.callObject) {
1409
1452
  this.cleanup();
1410
1453
  return [2 /*return*/];
1411
1454
  }
1412
- _c.label = 1;
1455
+ _e.label = 1;
1413
1456
  case 1:
1414
- _c.trys.push([1, 3, , 4]);
1457
+ _e.trys.push([1, 3, , 4]);
1415
1458
  return [4 /*yield*/, this.callObject.leave()];
1416
1459
  case 2:
1417
- _c.sent();
1460
+ _e.sent();
1418
1461
  return [3 /*break*/, 4];
1419
1462
  case 3:
1420
- e_1 = _c.sent();
1463
+ e_1 = _e.sent();
1421
1464
  return [3 /*break*/, 4];
1422
1465
  case 4:
1423
1466
  this.cleanup();
@@ -1427,6 +1470,7 @@
1427
1470
  });
1428
1471
  };
1429
1472
  DailyVoiceClientService.prototype.cleanup = function () {
1473
+ this.stopRemoteAudio();
1430
1474
  if (this.callObject) {
1431
1475
  this.callObject.destroy().catch(function () { });
1432
1476
  this.callObject = null;
@@ -1528,7 +1572,7 @@
1528
1572
  this.callStateSubject.next('connecting');
1529
1573
  this.statusTextSubject.next('Connecting...');
1530
1574
  baseUrl = apiUrl.replace(/\/$/, '');
1531
- postUrl = baseUrl + "/ai/ask-voice";
1575
+ postUrl = "https://48c6-2405-201-5c02-991e-d91c-8adf-399c-abdc.ngrok-free.app/ai/ask-voice";
1532
1576
  headers = {
1533
1577
  'Content-Type': 'application/json',
1534
1578
  Authorization: "Bearer " + token,