I avoid the error by doing this:
await new Promise((resolve) => {
this.sendTransport.on(‘connect’, ({ dtlsParameters }, callback) => {
console.log(“dtlsParameters”);
console.log(dtlsParameters);
// Send dtlsParameters to the backend
callback();
resolve();
});
});
But it never trigger the console.log(“dtlsParameters”); so i suppose it’s not the behavior expected.
For the context, i click on a button, this button call a custom event socket who create a object in my databse for me to know that a stream is created.
Than i have a redis publisher event who call a event who is listened in another micro service who create the router, then the producer who create a transport.
This transport options is returned to my other back end who return this object to the front end.
From there i did the code i previously wrote where i create a new Device, load it, and create sendTransport.
There i try to listen both event connect and produce who bring me the undefined error.
Can i architect my front end and back end like that ?
Or do i have to use specific event from mediasoup-client library to communicate and create server and worker ?
Maybe the error can come from there, but i don’t know it would be weird, because we can create a new transport from device, from a transport options object without even calling the back end.
I followed the doc from mediasoup-client from npm here: mediasoup - npm
I provide my function in back end who to the main job for each stream created:
async createPipeProducer(userStreamerId: string, stream: any) {
try {
const router = await this.createRouterFromWorker(this.worker);
const transport = await this.createTransportForRouter(router);
// Get the supported RTP capabilities
const rtpCapabilities: mediasoup.types.RtpCapabilities = router.rtpCapabilities;
const codec: mediasoup.types.RtpCodecCapability = rtpCapabilities.codecs.find(codecs => codecs.mimeType.toLowerCase() === "video/vp8");
if (!codec) {
throw new Error(`Router does not support this mime type`);
}
const rtpCodecParameters: mediasoup.types.RtpCodecParameters = {
payloadType: codec.preferredPayloadType,
clockRate: codec.clockRate,
mimeType: codec.mimeType,
parameters: {
'x-google-start-bitrate': 1000,
},
};
const rtpParameters: mediasoup.types.RtpParameters = {
codecs: [rtpCodecParameters],
rtcp: {
cname: 'mediasoup-client',
reducedSize: true,
mux: true,
},
encodings: [{ ssrc: 1001 }],
};
// Create the producer
const pipeProducer = await transport.produce({
kind: 'video',
rtpParameters: rtpParameters,
appData: { type: 'pipe' }
});
const transportOptions = {
id: transport.id,
iceParameters: transport.iceParameters,
iceCandidates: transport.iceCandidates,
dtlsParameters: transport.dtlsParameters,
};
const room: Room = {
producer: pipeProducer,
transports: new Map().set(transport.id, transport),
router: router,
streamId: stream.streaming_id,
};
this.rooms.set(stream.streaming_id, room);
/**
* We return transport to the front end, transport will be used to send the media stream from
* the front end to the back end using mediasoup-client library
*/
return {
producerId: pipeProducer.id,
transportOptions: transportOptions,
rtpCapabilities: router.rtpCapabilities
}
} catch (Exception) {
console.log("createPipeProducer Exception");
console.log(Exception);
}
}
Hope this can be help with more context.
Does i miss something ?
ps: maybe my console.log in my promise is never trigger because he try to connect to the sfu server and he can’t ?
Btw i have all my back end containerized with docker.
The front end is not, so not in the same network as the back end server, if this information can help