@anganyai/voice-sdk 0.0.1 → 0.0.2

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.cts CHANGED
@@ -1703,6 +1703,6 @@ declare function hasErrorCode(error: unknown, code: string): boolean;
1703
1703
  * SDK version
1704
1704
  * This is automatically updated during the release process
1705
1705
  */
1706
- declare const VERSION = "0.0.1";
1706
+ declare const VERSION = "0.0.2";
1707
1707
 
1708
1708
  export { AnganyError, AnganyVoice, type AuthError, type AuthEvents, AuthManager, type AuthOptions, type AuthState, type AuthStatus, AuthenticationError, type BackendAuthOptions, type ClientCredentials, ConfigurationError, Conversation, ConversationError, type ConversationOptions, type ConversationState, type ConversationStatus, ErrorCodes, EventEmitter, type FrontendAuthOptions, type LogLevel, MediaError, NetworkError, PermissionError, ResourceError, type ServiceAccountAuthOptions, type ServiceAccountCredentials, type SpeakOptions, type TokenSet, type TranscriptionEvent, type UserInfo, VERSION, ValidationError, type VoiceConfig, type VoiceResource, hasErrorCode, isAnganyError };
package/dist/index.d.ts CHANGED
@@ -1703,6 +1703,6 @@ declare function hasErrorCode(error: unknown, code: string): boolean;
1703
1703
  * SDK version
1704
1704
  * This is automatically updated during the release process
1705
1705
  */
1706
- declare const VERSION = "0.0.1";
1706
+ declare const VERSION = "0.0.2";
1707
1707
 
1708
1708
  export { AnganyError, AnganyVoice, type AuthError, type AuthEvents, AuthManager, type AuthOptions, type AuthState, type AuthStatus, AuthenticationError, type BackendAuthOptions, type ClientCredentials, ConfigurationError, Conversation, ConversationError, type ConversationOptions, type ConversationState, type ConversationStatus, ErrorCodes, EventEmitter, type FrontendAuthOptions, type LogLevel, MediaError, NetworkError, PermissionError, ResourceError, type ServiceAccountAuthOptions, type ServiceAccountCredentials, type SpeakOptions, type TokenSet, type TranscriptionEvent, type UserInfo, VERSION, ValidationError, type VoiceConfig, type VoiceResource, hasErrorCode, isAnganyError };
package/dist/index.js CHANGED
@@ -16236,6 +16236,26 @@ var UserAgent = class _UserAgent {
16236
16236
  }
16237
16237
  };
16238
16238
 
16239
+ // src/utils/platform.ts
16240
+ function detectPlatform() {
16241
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
16242
+ return "react-native";
16243
+ }
16244
+ if (typeof window !== "undefined" && typeof document !== "undefined" && typeof navigator !== "undefined") {
16245
+ return "browser";
16246
+ }
16247
+ return "node";
16248
+ }
16249
+ function isReactNative() {
16250
+ return detectPlatform() === "react-native";
16251
+ }
16252
+ function isBrowser() {
16253
+ return detectPlatform() === "browser";
16254
+ }
16255
+ function hasAudioContext() {
16256
+ return typeof AudioContext !== "undefined" || typeof globalThis.webkitAudioContext !== "undefined";
16257
+ }
16258
+
16239
16259
  // src/services/SipManager.ts
16240
16260
  var SipManager = class extends EventEmitter {
16241
16261
  constructor() {
@@ -16534,7 +16554,9 @@ var SipManager = class extends EventEmitter {
16534
16554
  }
16535
16555
  }
16536
16556
  setupAudioHandling(session) {
16537
- this.logger.debug("Setting up audio handling using SIP.js streams");
16557
+ this.logger.debug("Setting up audio handling using SIP.js streams", {
16558
+ platform: isReactNative() ? "react-native" : "browser"
16559
+ });
16538
16560
  const sessionDescriptionHandler = session.sessionDescriptionHandler;
16539
16561
  if (sessionDescriptionHandler) {
16540
16562
  this.logger.debug("Session description handler found");
@@ -16542,18 +16564,22 @@ var SipManager = class extends EventEmitter {
16542
16564
  if (remoteStream) {
16543
16565
  this.logger.info("Remote media stream available");
16544
16566
  this.remoteStream = remoteStream;
16545
- this.createAudioElement();
16546
- if (this.audioElement) {
16547
- this.audioElement.srcObject = remoteStream;
16548
- this.audioElement.play().catch((error) => {
16549
- this.logger.warn("Autoplay prevented, enabling controls for user interaction", {
16550
- error
16567
+ if (isReactNative()) {
16568
+ this.logger.info("React Native: Remote audio will be played automatically by WebRTC");
16569
+ } else {
16570
+ this.createAudioElement();
16571
+ if (this.audioElement) {
16572
+ this.audioElement.srcObject = remoteStream;
16573
+ this.audioElement.play().catch((error) => {
16574
+ this.logger.warn("Autoplay prevented, enabling controls for user interaction", {
16575
+ error
16576
+ });
16577
+ if (this.audioElement) {
16578
+ this.audioElement.controls = true;
16579
+ this.audioElement.style.display = "block";
16580
+ }
16551
16581
  });
16552
- if (this.audioElement) {
16553
- this.audioElement.controls = true;
16554
- this.audioElement.style.display = "block";
16555
- }
16556
- });
16582
+ }
16557
16583
  }
16558
16584
  this.startAudioMonitoring();
16559
16585
  } else {
@@ -16572,16 +16598,20 @@ var SipManager = class extends EventEmitter {
16572
16598
  if (event.streams[0]) {
16573
16599
  this.remoteStream = event.streams[0];
16574
16600
  this.logger.info("Remote audio stream received via ontrack fallback");
16575
- this.createAudioElement();
16576
- if (this.audioElement && this.remoteStream) {
16577
- this.audioElement.srcObject = this.remoteStream;
16578
- this.audioElement.play().catch((error) => {
16579
- this.logger.warn("Failed to auto-play remote audio", { error });
16580
- if (this.audioElement) {
16581
- this.audioElement.controls = true;
16582
- this.audioElement.style.display = "block";
16583
- }
16584
- });
16601
+ if (isReactNative()) {
16602
+ this.logger.info("React Native: Remote audio from ontrack will be played automatically");
16603
+ } else {
16604
+ this.createAudioElement();
16605
+ if (this.audioElement && this.remoteStream) {
16606
+ this.audioElement.srcObject = this.remoteStream;
16607
+ this.audioElement.play().catch((error) => {
16608
+ this.logger.warn("Failed to auto-play remote audio", { error });
16609
+ if (this.audioElement) {
16610
+ this.audioElement.controls = true;
16611
+ this.audioElement.style.display = "block";
16612
+ }
16613
+ });
16614
+ }
16585
16615
  }
16586
16616
  this.startAudioMonitoring();
16587
16617
  }
@@ -16610,8 +16640,17 @@ var SipManager = class extends EventEmitter {
16610
16640
  }
16611
16641
  /**
16612
16642
  * Create and configure the audio element for remote audio playback
16643
+ * In React Native, audio is handled differently through WebRTC streams
16613
16644
  */
16614
16645
  createAudioElement() {
16646
+ if (isReactNative()) {
16647
+ this.logger.debug("React Native detected - skipping audio element creation (handled by WebRTC)");
16648
+ return;
16649
+ }
16650
+ if (!isBrowser()) {
16651
+ this.logger.debug("Non-browser environment - skipping audio element creation");
16652
+ return;
16653
+ }
16615
16654
  if (this.audioElement) {
16616
16655
  return;
16617
16656
  }
@@ -16670,6 +16709,22 @@ var SipManager = class extends EventEmitter {
16670
16709
  if (!this.localStream || this.audioMonitorInterval) {
16671
16710
  return;
16672
16711
  }
16712
+ if (isReactNative() || !hasAudioContext()) {
16713
+ this.logger.debug("AudioContext not available - using simulated audio monitoring");
16714
+ this.audioMonitorInterval = setInterval(() => {
16715
+ if (this.state === "incall" && this.localStream) {
16716
+ const audioTrack = this.localStream.getAudioTracks()[0];
16717
+ if (audioTrack && audioTrack.enabled) {
16718
+ const simulatedLevel = 0.2 + Math.random() * 0.5;
16719
+ this.emit("audioLevel", simulatedLevel);
16720
+ } else {
16721
+ this.emit("audioLevel", 0);
16722
+ }
16723
+ }
16724
+ }, 100);
16725
+ this.logger.debug("Simulated audio monitoring started");
16726
+ return;
16727
+ }
16673
16728
  try {
16674
16729
  this.audioContext = new AudioContext();
16675
16730
  const source = this.audioContext.createMediaStreamSource(this.localStream);
@@ -16701,9 +16756,11 @@ var SipManager = class extends EventEmitter {
16701
16756
  delete this.audioAnalyser;
16702
16757
  }
16703
16758
  cleanupAudioResources() {
16704
- this.logger.debug("\u{1F9F9} Performing complete audio resource cleanup...");
16759
+ this.logger.debug("\u{1F9F9} Performing complete audio resource cleanup...", {
16760
+ platform: isReactNative() ? "react-native" : "browser"
16761
+ });
16705
16762
  this.stopAudioMonitoring();
16706
- if (this.audioElement) {
16763
+ if (this.audioElement && isBrowser()) {
16707
16764
  this.logger.debug("\u{1F9F9} Cleaning up audio element...");
16708
16765
  if (this.audioElement.srcObject) {
16709
16766
  const tracks = this.audioElement.srcObject.getTracks();
@@ -17795,7 +17852,7 @@ var AnganyVoice = class extends EventEmitter {
17795
17852
  };
17796
17853
 
17797
17854
  // src/version.ts
17798
- var VERSION = "0.0.1";
17855
+ var VERSION = "0.0.2";
17799
17856
 
17800
17857
  export { AnganyError, AnganyVoice, AuthManager, AuthenticationError, ConfigurationError, Conversation, ConversationError, ErrorCodes, EventEmitter, MediaError, NetworkError, PermissionError, ResourceError, VERSION, ValidationError, hasErrorCode, isAnganyError };
17801
17858
  //# sourceMappingURL=index.js.map