@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.
@@ -1,4 +1,4 @@
1
- export { ei as DeviceSelectorComponent } from '../device-selector-D7AEGpZu.mjs';
1
+ export { ei as DeviceSelectorComponent } from '../device-selector-CoAQBhd-.mjs';
2
2
  import 'react';
3
3
  import 'google-protobuf';
4
4
  import 'google-protobuf/google/protobuf/any_pb';
@@ -1,4 +1,4 @@
1
- export { ei as DeviceSelectorComponent } from '../device-selector-D7AEGpZu.js';
1
+ export { ei as DeviceSelectorComponent } from '../device-selector-CoAQBhd-.js';
2
2
  import 'react';
3
3
  import 'google-protobuf';
4
4
  import 'google-protobuf/google/protobuf/any_pb';
@@ -28613,9 +28613,7 @@ var VoiceAgent = class extends Agent {
28613
28613
  };
28614
28614
  connectDevice = async () => {
28615
28615
  try {
28616
- this.preliminaryInputStream = await navigator.mediaDevices.getUserMedia({
28617
- audio: true
28618
- });
28616
+ this.preliminaryInputStream = await this.waitForUserMediaPermission();
28619
28617
  [this.input, this.output] = await Promise.all([
28620
28618
  Input.create(this.agentConfig.inputOptions.recorderOption),
28621
28619
  Output.create(this.agentConfig.outputOptions.playerOption)
@@ -28626,7 +28624,19 @@ var VoiceAgent = class extends Agent {
28626
28624
  this.preliminaryInputStream = null;
28627
28625
  } catch (error) {
28628
28626
  await this.disconnectAudio();
28629
- console.log(error);
28627
+ console.error("Microphone permission error:", error);
28628
+ }
28629
+ };
28630
+ // Helper method to handle media permissions:
28631
+ waitForUserMediaPermission = async () => {
28632
+ try {
28633
+ return await navigator.mediaDevices.getUserMedia({ audio: true });
28634
+ } catch (error) {
28635
+ console.error(
28636
+ "Permission denied or error while requesting microphone access:",
28637
+ error
28638
+ );
28639
+ throw error;
28630
28640
  }
28631
28641
  };
28632
28642
  /**
@@ -28673,7 +28683,6 @@ var VoiceAgent = class extends Agent {
28673
28683
  console.log("Please call connect first, agent is not connected");
28674
28684
  return;
28675
28685
  }
28676
- const maxVolume = event.data[1];
28677
28686
  if (this.inputChannel == "audio" /* Audio */)
28678
28687
  this.talkingConnection?.write(
28679
28688
  this.createAssistantAudioMessage(
@@ -28739,10 +28748,10 @@ var VoiceAgent = class extends Agent {
28739
28748
  */
28740
28749
  connect = async () => {
28741
28750
  try {
28742
- await this.connectAgent();
28743
28751
  if (this.inputChannel == "audio" /* Audio */) {
28744
28752
  await this.connectAudio();
28745
28753
  }
28754
+ await this.connectAgent();
28746
28755
  } catch (err) {
28747
28756
  console.error("error while connect " + err);
28748
28757
  }
@@ -28800,16 +28809,31 @@ var VoiceAgent = class extends Agent {
28800
28809
  * @param input
28801
28810
  * @returns
28802
28811
  */
28812
+ // public setInputChannel = async (input: Channel) => {
28813
+ // if (this.inputChannel == input) {
28814
+ // return;
28815
+ // }
28816
+ // if (input == Channel.Audio) {
28817
+ // await this.connectAudio();
28818
+ // } else {
28819
+ // await this.disconnectAudio();
28820
+ // }
28821
+ // this.inputChannel = input;
28822
+ // this.emit(AgentEvent.InputChannelChangeEvent, this.inputChannel);
28823
+ // };
28803
28824
  setInputChannel = async (input) => {
28804
- if (this.inputChannel == input) {
28825
+ if (this.inputChannel === input) {
28805
28826
  return;
28806
28827
  }
28807
- if (input == "audio" /* Audio */) {
28808
- await this.connectAudio();
28809
- } else {
28810
- await this.disconnectAudio();
28811
- }
28828
+ await this.disconnectAudio();
28812
28829
  this.inputChannel = input;
28830
+ if (input === "audio" /* Audio */) {
28831
+ if (this.isConnected) {
28832
+ await this.connectAudio();
28833
+ } else {
28834
+ console.log("Audio initialization deferred until connect()");
28835
+ }
28836
+ }
28813
28837
  this.emit("onInputChannelChangeEvent" /* InputChannelChangeEvent */, this.inputChannel);
28814
28838
  };
28815
28839
  /**