@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.cjs +82 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +82 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -16238,6 +16238,26 @@ var UserAgent = class _UserAgent {
|
|
|
16238
16238
|
}
|
|
16239
16239
|
};
|
|
16240
16240
|
|
|
16241
|
+
// src/utils/platform.ts
|
|
16242
|
+
function detectPlatform() {
|
|
16243
|
+
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
16244
|
+
return "react-native";
|
|
16245
|
+
}
|
|
16246
|
+
if (typeof window !== "undefined" && typeof document !== "undefined" && typeof navigator !== "undefined") {
|
|
16247
|
+
return "browser";
|
|
16248
|
+
}
|
|
16249
|
+
return "node";
|
|
16250
|
+
}
|
|
16251
|
+
function isReactNative() {
|
|
16252
|
+
return detectPlatform() === "react-native";
|
|
16253
|
+
}
|
|
16254
|
+
function isBrowser() {
|
|
16255
|
+
return detectPlatform() === "browser";
|
|
16256
|
+
}
|
|
16257
|
+
function hasAudioContext() {
|
|
16258
|
+
return typeof AudioContext !== "undefined" || typeof globalThis.webkitAudioContext !== "undefined";
|
|
16259
|
+
}
|
|
16260
|
+
|
|
16241
16261
|
// src/services/SipManager.ts
|
|
16242
16262
|
var SipManager = class extends EventEmitter {
|
|
16243
16263
|
constructor() {
|
|
@@ -16536,7 +16556,9 @@ var SipManager = class extends EventEmitter {
|
|
|
16536
16556
|
}
|
|
16537
16557
|
}
|
|
16538
16558
|
setupAudioHandling(session) {
|
|
16539
|
-
this.logger.debug("Setting up audio handling using SIP.js streams"
|
|
16559
|
+
this.logger.debug("Setting up audio handling using SIP.js streams", {
|
|
16560
|
+
platform: isReactNative() ? "react-native" : "browser"
|
|
16561
|
+
});
|
|
16540
16562
|
const sessionDescriptionHandler = session.sessionDescriptionHandler;
|
|
16541
16563
|
if (sessionDescriptionHandler) {
|
|
16542
16564
|
this.logger.debug("Session description handler found");
|
|
@@ -16544,18 +16566,22 @@ var SipManager = class extends EventEmitter {
|
|
|
16544
16566
|
if (remoteStream) {
|
|
16545
16567
|
this.logger.info("Remote media stream available");
|
|
16546
16568
|
this.remoteStream = remoteStream;
|
|
16547
|
-
|
|
16548
|
-
|
|
16549
|
-
|
|
16550
|
-
this.
|
|
16551
|
-
|
|
16552
|
-
|
|
16569
|
+
if (isReactNative()) {
|
|
16570
|
+
this.logger.info("React Native: Remote audio will be played automatically by WebRTC");
|
|
16571
|
+
} else {
|
|
16572
|
+
this.createAudioElement();
|
|
16573
|
+
if (this.audioElement) {
|
|
16574
|
+
this.audioElement.srcObject = remoteStream;
|
|
16575
|
+
this.audioElement.play().catch((error) => {
|
|
16576
|
+
this.logger.warn("Autoplay prevented, enabling controls for user interaction", {
|
|
16577
|
+
error
|
|
16578
|
+
});
|
|
16579
|
+
if (this.audioElement) {
|
|
16580
|
+
this.audioElement.controls = true;
|
|
16581
|
+
this.audioElement.style.display = "block";
|
|
16582
|
+
}
|
|
16553
16583
|
});
|
|
16554
|
-
|
|
16555
|
-
this.audioElement.controls = true;
|
|
16556
|
-
this.audioElement.style.display = "block";
|
|
16557
|
-
}
|
|
16558
|
-
});
|
|
16584
|
+
}
|
|
16559
16585
|
}
|
|
16560
16586
|
this.startAudioMonitoring();
|
|
16561
16587
|
} else {
|
|
@@ -16574,16 +16600,20 @@ var SipManager = class extends EventEmitter {
|
|
|
16574
16600
|
if (event.streams[0]) {
|
|
16575
16601
|
this.remoteStream = event.streams[0];
|
|
16576
16602
|
this.logger.info("Remote audio stream received via ontrack fallback");
|
|
16577
|
-
|
|
16578
|
-
|
|
16579
|
-
|
|
16580
|
-
this.
|
|
16581
|
-
|
|
16582
|
-
|
|
16583
|
-
|
|
16584
|
-
this.
|
|
16585
|
-
|
|
16586
|
-
|
|
16603
|
+
if (isReactNative()) {
|
|
16604
|
+
this.logger.info("React Native: Remote audio from ontrack will be played automatically");
|
|
16605
|
+
} else {
|
|
16606
|
+
this.createAudioElement();
|
|
16607
|
+
if (this.audioElement && this.remoteStream) {
|
|
16608
|
+
this.audioElement.srcObject = this.remoteStream;
|
|
16609
|
+
this.audioElement.play().catch((error) => {
|
|
16610
|
+
this.logger.warn("Failed to auto-play remote audio", { error });
|
|
16611
|
+
if (this.audioElement) {
|
|
16612
|
+
this.audioElement.controls = true;
|
|
16613
|
+
this.audioElement.style.display = "block";
|
|
16614
|
+
}
|
|
16615
|
+
});
|
|
16616
|
+
}
|
|
16587
16617
|
}
|
|
16588
16618
|
this.startAudioMonitoring();
|
|
16589
16619
|
}
|
|
@@ -16612,8 +16642,17 @@ var SipManager = class extends EventEmitter {
|
|
|
16612
16642
|
}
|
|
16613
16643
|
/**
|
|
16614
16644
|
* Create and configure the audio element for remote audio playback
|
|
16645
|
+
* In React Native, audio is handled differently through WebRTC streams
|
|
16615
16646
|
*/
|
|
16616
16647
|
createAudioElement() {
|
|
16648
|
+
if (isReactNative()) {
|
|
16649
|
+
this.logger.debug("React Native detected - skipping audio element creation (handled by WebRTC)");
|
|
16650
|
+
return;
|
|
16651
|
+
}
|
|
16652
|
+
if (!isBrowser()) {
|
|
16653
|
+
this.logger.debug("Non-browser environment - skipping audio element creation");
|
|
16654
|
+
return;
|
|
16655
|
+
}
|
|
16617
16656
|
if (this.audioElement) {
|
|
16618
16657
|
return;
|
|
16619
16658
|
}
|
|
@@ -16672,6 +16711,22 @@ var SipManager = class extends EventEmitter {
|
|
|
16672
16711
|
if (!this.localStream || this.audioMonitorInterval) {
|
|
16673
16712
|
return;
|
|
16674
16713
|
}
|
|
16714
|
+
if (isReactNative() || !hasAudioContext()) {
|
|
16715
|
+
this.logger.debug("AudioContext not available - using simulated audio monitoring");
|
|
16716
|
+
this.audioMonitorInterval = setInterval(() => {
|
|
16717
|
+
if (this.state === "incall" && this.localStream) {
|
|
16718
|
+
const audioTrack = this.localStream.getAudioTracks()[0];
|
|
16719
|
+
if (audioTrack && audioTrack.enabled) {
|
|
16720
|
+
const simulatedLevel = 0.2 + Math.random() * 0.5;
|
|
16721
|
+
this.emit("audioLevel", simulatedLevel);
|
|
16722
|
+
} else {
|
|
16723
|
+
this.emit("audioLevel", 0);
|
|
16724
|
+
}
|
|
16725
|
+
}
|
|
16726
|
+
}, 100);
|
|
16727
|
+
this.logger.debug("Simulated audio monitoring started");
|
|
16728
|
+
return;
|
|
16729
|
+
}
|
|
16675
16730
|
try {
|
|
16676
16731
|
this.audioContext = new AudioContext();
|
|
16677
16732
|
const source = this.audioContext.createMediaStreamSource(this.localStream);
|
|
@@ -16703,9 +16758,11 @@ var SipManager = class extends EventEmitter {
|
|
|
16703
16758
|
delete this.audioAnalyser;
|
|
16704
16759
|
}
|
|
16705
16760
|
cleanupAudioResources() {
|
|
16706
|
-
this.logger.debug("\u{1F9F9} Performing complete audio resource cleanup..."
|
|
16761
|
+
this.logger.debug("\u{1F9F9} Performing complete audio resource cleanup...", {
|
|
16762
|
+
platform: isReactNative() ? "react-native" : "browser"
|
|
16763
|
+
});
|
|
16707
16764
|
this.stopAudioMonitoring();
|
|
16708
|
-
if (this.audioElement) {
|
|
16765
|
+
if (this.audioElement && isBrowser()) {
|
|
16709
16766
|
this.logger.debug("\u{1F9F9} Cleaning up audio element...");
|
|
16710
16767
|
if (this.audioElement.srcObject) {
|
|
16711
16768
|
const tracks = this.audioElement.srcObject.getTracks();
|
|
@@ -17797,7 +17854,7 @@ var AnganyVoice = class extends EventEmitter {
|
|
|
17797
17854
|
};
|
|
17798
17855
|
|
|
17799
17856
|
// src/version.ts
|
|
17800
|
-
var VERSION = "0.0.
|
|
17857
|
+
var VERSION = "0.0.2";
|
|
17801
17858
|
|
|
17802
17859
|
exports.AnganyError = AnganyError;
|
|
17803
17860
|
exports.AnganyVoice = AnganyVoice;
|