-
-
Save the-eater/6d5a3625fa0ffe7e66ce90011f72794d to your computer and use it in GitHub Desktop.
`IS_CRHOME` WebRTC hacks
This file contains 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
async renegotiate(msg) { | |
if (IS_CHROME) { | |
// While Firefox gladly reuses open media channels. Chrome doesn't want to. | |
// So server counts amount of tracks are added, | |
// and client creates that amount of new transceivers | |
for (let i = 0; i < msg.newTracks; i++) { | |
this.peer.addTransceiver('audio', { | |
direction: "recvonly" | |
}); | |
} | |
} | |
let size = msg.size + 1; | |
if (this.peer.getTransceivers().length < size) { | |
for (let i = 0; i < (size - this.peer.getTransceivers().length); i++) { | |
this.peer.addTransceiver('audio', { | |
direction: "recvonly" | |
}); | |
} | |
} | |
await this.sendOffer(); | |
} |
This file contains 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
async handleNewTrack(e) { | |
if (IS_CHROME) { | |
// If the stream is not added to an <audio> element | |
// Chrome will not write any audio to the AudioContext. | |
// So add the stream to a muted (and paused?) <audio> element | |
const audio = new Audio(); | |
audio.muted = true; | |
audio.srcObject = e.streams[0]; | |
this.audioElements.set(e.track.id, audio); | |
} | |
let node = new MediaStreamAudioSourceNode(this.audioContext, {mediaStream: e.streams[0]}); | |
node.connect(this.audioContext.destination); | |
this.audioStreams.set(e.track.id, node); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment