@rapidaai/react 1.1.45 → 1.1.47

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.
@@ -29357,9 +29357,7 @@ var VoiceAgent = class extends Agent {
29357
29357
  };
29358
29358
  connectDevice = async () => {
29359
29359
  try {
29360
- this.preliminaryInputStream = await navigator.mediaDevices.getUserMedia({
29361
- audio: true
29362
- });
29360
+ this.preliminaryInputStream = await this.waitForUserMediaPermission();
29363
29361
  [this.input, this.output] = await Promise.all([
29364
29362
  Input.create(this.agentConfig.inputOptions.recorderOption),
29365
29363
  Output.create(this.agentConfig.outputOptions.playerOption)
@@ -29370,7 +29368,19 @@ var VoiceAgent = class extends Agent {
29370
29368
  this.preliminaryInputStream = null;
29371
29369
  } catch (error) {
29372
29370
  await this.disconnectAudio();
29373
- console.log(error);
29371
+ console.error("Microphone permission error:", error);
29372
+ }
29373
+ };
29374
+ // Helper method to handle media permissions:
29375
+ waitForUserMediaPermission = async () => {
29376
+ try {
29377
+ return await navigator.mediaDevices.getUserMedia({ audio: true });
29378
+ } catch (error) {
29379
+ console.error(
29380
+ "Permission denied or error while requesting microphone access:",
29381
+ error
29382
+ );
29383
+ throw error;
29374
29384
  }
29375
29385
  };
29376
29386
  /**
@@ -29417,7 +29427,6 @@ var VoiceAgent = class extends Agent {
29417
29427
  console.log("Please call connect first, agent is not connected");
29418
29428
  return;
29419
29429
  }
29420
- const maxVolume = event.data[1];
29421
29430
  if (this.inputChannel == "audio" /* Audio */)
29422
29431
  this.talkingConnection?.write(
29423
29432
  this.createAssistantAudioMessage(
@@ -29483,10 +29492,10 @@ var VoiceAgent = class extends Agent {
29483
29492
  */
29484
29493
  connect = async () => {
29485
29494
  try {
29486
- await this.connectAgent();
29487
29495
  if (this.inputChannel == "audio" /* Audio */) {
29488
29496
  await this.connectAudio();
29489
29497
  }
29498
+ await this.connectAgent();
29490
29499
  } catch (err) {
29491
29500
  console.error("error while connect " + err);
29492
29501
  }
@@ -29544,16 +29553,31 @@ var VoiceAgent = class extends Agent {
29544
29553
  * @param input
29545
29554
  * @returns
29546
29555
  */
29556
+ // public setInputChannel = async (input: Channel) => {
29557
+ // if (this.inputChannel == input) {
29558
+ // return;
29559
+ // }
29560
+ // if (input == Channel.Audio) {
29561
+ // await this.connectAudio();
29562
+ // } else {
29563
+ // await this.disconnectAudio();
29564
+ // }
29565
+ // this.inputChannel = input;
29566
+ // this.emit(AgentEvent.InputChannelChangeEvent, this.inputChannel);
29567
+ // };
29547
29568
  setInputChannel = async (input) => {
29548
- if (this.inputChannel == input) {
29569
+ if (this.inputChannel === input) {
29549
29570
  return;
29550
29571
  }
29551
- if (input == "audio" /* Audio */) {
29552
- await this.connectAudio();
29553
- } else {
29554
- await this.disconnectAudio();
29555
- }
29572
+ await this.disconnectAudio();
29556
29573
  this.inputChannel = input;
29574
+ if (input === "audio" /* Audio */) {
29575
+ if (this.isConnected) {
29576
+ await this.connectAudio();
29577
+ } else {
29578
+ console.log("Audio initialization deferred until connect()");
29579
+ }
29580
+ }
29557
29581
  this.emit("onInputChannelChangeEvent" /* InputChannelChangeEvent */, this.inputChannel);
29558
29582
  };
29559
29583
  /**
@@ -30171,4 +30195,4 @@ export {
30171
30195
  useSelectInputDeviceAgent,
30172
30196
  DeviceSelectorComponent
30173
30197
  };
30174
- //# sourceMappingURL=chunk-DRBNQMZR.mjs.map
30198
+ //# sourceMappingURL=chunk-5UBYT2TF.mjs.map