Unfortunately, this doesn’t seem to work. I don’t know how to test, but I tried to use VLC to connect to udp stream with the form udp://127.0.0.1:${rtpTransport.tuple.port}
If comedia is enabled in this plain transport and SRTP is not, connect must not be called.
I also tried without comedia but connect requires ip & port which I don’t know because I’d like to just consume rtp stream. Maybe I don’t have the correct representation of rtp, might not be just a pull request as you would do with http
I cannot explain here how RTP protocol works (no matter how you would like it to be), sorry. The docs are clear: don’t use comedia mode if the remote endpoint just wishes to consume RTP. You need to provide the PlainTransport.connect() method with the remote endpoint’s IP and port in which it wishes to receive RTP.
send a special RTP packet from consumer client to mediasoup comedia:true RTP listen port is easy, i use the follow nodejs script:
/* remoteRTPPort is webrtc server side's listen rtpPort with the following code:
const transport = await this.mediasoupRouter.createPlainTransport({
listenIp: "0.0.0.0",
rtcpMux: false,
comedia: true
});
const rtpPort = transport.tuple.localPort;
*/
async function getLocalRTPPort(remoteRTPPort){
const rtpPacket = Uint8Array.from([128,20,1,0,43,32,0,0,89,7,0,0,1,2,3,4]);
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const localRTPPort = await new Promise((resolve, reject)=>{
client.send(rtpPacket, remoteRTPPort, WEBRTC_SERVER_IP, async (err) => {
if(err){
reject(err);
}else{
const localClientUdpPort = client.address().port; //This port may be port-mapped by NAT;
client.close();
resolve(localClientUdpPort);
}
});
});
return localRTPPort;
}
Unfortunately, this does NOT work when NAT gateways are there and don’t do reverse DNAT with port mapping, but WebRTC consumer client (like chrome webpage) works. Which puzzles me…