-
-
Save inscapist/14ebd9fc61c68deddebe4039eedb1124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rtcConnection = null; | |
let rtcLoopbackConnection = null; | |
let loopbackStream = new MediaStream(); // this is the stream you will read from for actual audio output | |
const offerOptions = { | |
offerVideo: true, | |
offerAudio: true, | |
offerToReceiveAudio: false, | |
offerToReceiveVideo: false, | |
}; | |
let offer, answer; | |
// initialize the RTC connections | |
this.rtcConnection = new RTCPeerConnection(); | |
this.rtcLoopbackConnection = new RTCPeerConnection(); | |
this.rtcConnection.onicecandidate = e => | |
e.candidate && this.rtcLoopbackConnection.addIceCandidate(new RTCIceCandidate(e.candidate)); | |
this.rtcLoopbackConnection.onicecandidate = e => | |
e.candidate && this.rtcConnection.addIceCandidate(new RTCIceCandidate(e.candidate)); | |
this.rtcLoopbackConnection.ontrack = e => | |
e.streams[0].getTracks().forEach(track => this.loopbackStream.addTrack(track)); | |
// setup the loopback | |
this.rtcConnection.addStream(stream); // this stream would be the processed stream coming out of Web Audio API destination node | |
offer = await this.rtcConnection.createOffer(offerOptions); | |
await this.rtcConnection.setLocalDescription(offer); | |
await this.rtcLoopbackConnection.setRemoteDescription(offer); | |
answer = await this.rtcLoopbackConnection.createAnswer(); | |
await this.rtcLoopbackConnection.setLocalDescription(answer); | |
await this.rtcConnection.setRemoteDescription(answer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment