-remote audio fix

This commit is contained in:
ajukes
2023-07-03 16:41:32 +01:00
parent 284f0c9275
commit 2aa6e9888b
3 changed files with 20 additions and 12 deletions

View File

@@ -33,7 +33,9 @@ export default class SipAudioElements {
}
pauseRinging(): void {
this.#ringing.pause();
if (!this.#ringing.paused) {
this.#ringing.pause();
}
}
playFailed(volume: number | undefined): void {
@@ -60,4 +62,9 @@ export default class SipAudioElements {
this.#remote.srcObject = stream;
this.#remote.play();
}
isPLaying(audio: HTMLAudioElement) {
return audio.currentTime > 0 && !audio.paused && !audio.ended
&& audio.readyState > audio.HAVE_CURRENT_DATA;
}
}

View File

@@ -174,16 +174,16 @@ export default class SipSession extends events.EventEmitter {
direction: this.#rtcSession.direction
})
});
pc.addEventListener('track', (event: RTCPeerConnectionEventMap["track"]): void => {
const stream: MediaStream = new MediaStream([event.track])
if (this.#rtcSession.direction === 'outgoing') {
this.#audio.pauseRinging();
}
this.#audio.playRemote(stream);
this.emit(SipConstants.SESSION_TRACK, {
direction: this.#rtcSession.direction
});
});
// pc.addEventListener('track', (event: RTCPeerConnectionEventMap["track"]): void => {
// const stream: MediaStream = new MediaStream([event.track])
// if (this.#rtcSession.direction === 'outgoing') {
// this.#audio.pauseRinging();
// }
// this.#audio.playRemote(stream, "track");
// this.emit(SipConstants.SESSION_TRACK, {
// direction: this.#rtcSession.direction
// });
// });
};
get rtcSession() {

View File

@@ -1,5 +1,5 @@
import * as events from "events";
import {UA, WebSocketInterface} from "jssip";
import {UA, WebSocketInterface, debug} from "jssip";
import {DisconnectEvent} from "jssip/lib/WebSocketInterface";
import {RTCSession} from "jssip/lib/RTCSession";
import {
@@ -26,6 +26,7 @@ export default class SipUA extends events.EventEmitter {
constructor(client: SipModel.ClientAuth, settings: SipModel.ClientOptions) {
super();
debug.enable('JsSIP:*');
this.#sessionManager = new SessionManager();
this.#rtcConfig = settings.pcConfig;
this.#ua = new UA({