LAPI-675: Update server go emit new-producer; Update client to handle this event

This commit is contained in:
Sergiu Toma 2023-01-13 18:32:11 +02:00
parent eece7d2ee3
commit 9b4e0186ac
2 changed files with 27 additions and 63 deletions

78
app.js
View File

@ -28,8 +28,8 @@ let worker;
* initiatorConsumerVideo: Consumer,
* initiatorConsumerAudio: Consumer,
* initiatorConsumerTransport: Consumer Transport
* initiatorSockerId
* receiverSocketId
* initiatorSocket
* receiverSocket
* }
*
**/
@ -193,11 +193,11 @@ peers.on('connection', async socket => {
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
if (!videoCalls[callId]) {
console.log('[createRoom] callId', callId);
videoCalls[callId] = { router: await worker.createRouter({ mediaCodecs }) }
videoCalls[callId] = { router: await worker.createRouter({ mediaCodecs }) };
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
videoCalls[callId].receiverSocketId = socket.id
videoCalls[callId].receiverSocket = socket;
} else {
videoCalls[callId].initiatorSockerId = socket.id
videoCalls[callId].initiatorSocket = socket;
}
socketDetails[socket.id] = callId;
// rtpCapabilities is set for callback
@ -299,68 +299,28 @@ peers.on('connection', async socket => {
// videoCalls[callId].router
const router = videoCalls[callId].router;
router.observer.on("newtransport", (transport) => {
transport.observer.on("newproducer", (producer) => {
router.observer.on("newtransport", (transport) =>
{
console.log(
"new transport created [worker.pid:%d, router.id:%s, transport.id:%s]",
worker.pid, router.id, transport.id);
transport.observer.on("close", () =>
{
console.log("transport closed [transport.id:%s]", transport.id);
});
transport.observer.on("newproducer", (producer) =>
{
console.log(
"new producer created [worker.pid:%d, router.id:%s, transport.id:%s, producer.id:%s]",
worker.pid, router.id, transport.id, producer.id);
worker.pid, router.id, transport.id, producer.id
);
producer.observer.on("close", () =>
{
console.log("producer closed [producer.id:%s]", producer.id);
});
if (!isInitiator(callId, socket.id)) {
console.log('🟥 Emit to initiatorSocket');
initiatorSocket.emit('new-producer', {
callId
});
transport.observer.on("newconsumer", (consumer) =>
{
console.log(
"new consumer created [worker.pid:%d, router.id:%s, transport.id:%s, consumer.id:%s]",
worker.pid, router.id, transport.id, consumer.id);
consumer.observer.on("close", () =>
{
console.log("consumer closed [consumer.id:%s]", consumer.id);
});
});
transport.observer.on("newdataproducer", (dataProducer) =>
{
console.log(
"new data producer created [worker.pid:%d, router.id:%s, transport.id:%s, dataProducer.id:%s]",
worker.pid, router.id, transport.id, dataProducer.id);
dataProducer.observer.on("close", () =>
{
console.log("data producer closed [dataProducer.id:%s]", dataProducer.id);
});
});
transport.observer.on("newdataconsumer", (dataConsumer) =>
{
console.log(
"new data consumer created [worker.pid:%d, router.id:%s, transport.id:%s, dataConsumer.id:%s]",
worker.pid, router.id, transport.id, dataConsumer.id);
dataConsumer.observer.on("close", () =>
{
console.log("data consumer closed [dataConsumer.id:%s]", dataConsumer.id);
} else {
console.log('🟥 Emit to receiverSocket');
receiverSocket.emit('new-producer', {
callId
});
}
});
});
@ -684,7 +644,7 @@ const consumeAudio = async (callId, socketId, rtpCapabilities) => {
}
const isInitiator = (callId, socketId) => {
return (videoCalls[callId].initiatorSockerId === socketId);
return (videoCalls[callId].initiatorSocket.id === socketId);
}
/*

View File

@ -95,6 +95,10 @@ setTimeout(() => {
}
if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() }
})
socket.on('new-producer', ({ callId }) => {
console.log(`🟥 new-producer | callId: ${callId}`);
})
}
if (IS_PRODUCER === true) {