-
-
Save murillo128/abc662723b6998b761698aeed8a24a45 to your computer and use it in GitHub Desktop.
//Get mic+cam | |
const stream = await navigator.mediaDevices.getUserMedia({audio:true, video:true}); | |
//Create peerconnection | |
const pc = new RTCPeerConnection(); | |
//Listen for state change events | |
pc.onconnectionstatechange = (event) =>{ | |
switch(pc.connectionState) { | |
case "connected": | |
// The connection has become fully connected | |
break; | |
case "disconnected": | |
case "failed": | |
// One or more transports has terminated unexpectedly or in an error | |
break; | |
case "closed": | |
// The connection has been closed | |
break; | |
} | |
} | |
//Send all tracks | |
for (const track of stream.getTracks()) | |
//You could add simulcast too here | |
pc.addTrack(track); | |
//Create SDP offer | |
const offer = await pc.createOffer(); | |
//Set it | |
await pc.setLocalDescription(offer) | |
//Do the post request to the WHIP endpoint with the SDP offer | |
const fetched = await fetch(url, { | |
method: "POST", | |
body: offer.sdp, | |
headers:{ | |
"Content-Type": "application/sdp" | |
} | |
}); | |
//Get the SDP answer | |
const answer = await fetched.text(); | |
//And set it | |
await pc.setRemoteDescription({type:"answer",sdp: answer}); |
it will work if the whip server is on a public ip address as well.
Sure.
Even though I'm exactly now having a scenario, where this is not working. The WHIP server is behind a public address, the WHIP client is not sending any candidates, neither in offer nor in PATCHes. Connection cannot be established. Server is MediaMTX.
Don't worry, I will go with ICE-LITE
you can use the js lib for propper patch support
Thank. I think I tried that already yesterday. Put that aside, because it didn't work oob with a symmetric NAT connection. Maybe I need to resume, since I noticed that I forgot to add a TURN configuration to my server. I noticed too, that MediaMTX is providing the Link header and that your lib seems to also acknowledge this.
Will report the results. Thanks so far.
Yes, that seems to work now (with a proper TURN configuration for the edge cases).
BTW: I noticed a little problem in whep.js
. There is a function call to trickle()
. I believe it is a forgotten rename to patch
and changed it like so.
https://github.com/medooze/whip-whep-js/blob/13e211ad104f0ecb54465af971a49855d7788dc5/whep.js#L245
I have created two PRs with minor changes.
Thanks for sharing, but it is a bit misleading because it will only work in your local LAN due to the absence of any kind of ICE handling