My front code is this in nextjs
const createRecvTransport = async () => {
socket.emit('createWebRtcTransport', { consumer: true }, async (params: WebRtcTransportParams) => {
recvTransport = await device.createRecvTransport(params.params);
recvTransport.on('connect', ({ dtlsParameters }, callback, errback) => {
socket.emit('connectConsumerTransport', {
transportId: recvTransport.id,
dtlsParameters,
});
callback();
});
// After the transport is created, emit the consumeMedia event
socket.emit('consumeMedia', { rtpCapabilities: device.rtpCapabilities }, (response) => {
console.log('Consume media response:', response);
// Handle the response here (e.g., set up video elements, etc.)
});
});
};
back end code is below
socket.on("createWebRtcTransport", async ({ consumer }, callback) => {
console.log("listen createWebRtcTransport");
const roomId = peers[socket.id].roomId;
const router = rooms[roomId].router;
console.log("createWebRtcTransport", roomId);
createWebRtcTransport(router).then(
(transport) => {
callback({
params: {
id: transport.id,
iceParameters: transport.iceParameters,
iceCandidates: transport.iceCandidates,
dtlsParameters: transport.dtlsParameters,
},
});
// add transport to Peer's properties
addTransport(transport, roomId, consumer);
},
(error) => {
console.log(error);
}
);
});
const createWebRtcTransport = async (
router: any
): Promise<WebRtcTransport> => {
return new Promise(async (resolve, reject) => {
try {
const webRtcTransport_options = {
listenIps: [
{
ip:'0.0.0.0',
announcedIp:process.env.PUBLIC_IP,
},
// {
// ip: process.env.PUBLIC_IP, // replace with relevant IP address
// announcedIp: "127.0.0.1",
// },
],
enableUdp: true,
enableTcp: true,
preferUdp: true,
};
console.log("webRtcTransport_options", webRtcTransport_options);
const transport: WebRtcTransport = await router.createWebRtcTransport(
webRtcTransport_options
);
console.log(`transport id: ${transport.id}`);
transport.on("dtlsstatechange", (dtlsState) => {
if (dtlsState === "closed") {
transport.close();
}
});
transport.on("@close", () => {
console.log("transport closed");
});
resolve(transport);
} catch (error) {
reject(error);
}
});
};
RecvTransport.on('connect) does not trigger i don’t where i am doing mistake