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

86
app.js
View File

@ -28,8 +28,8 @@ let worker;
* initiatorConsumerVideo: Consumer, * initiatorConsumerVideo: Consumer,
* initiatorConsumerAudio: Consumer, * initiatorConsumerAudio: Consumer,
* initiatorConsumerTransport: Consumer Transport * initiatorConsumerTransport: Consumer Transport
* initiatorSockerId * initiatorSocket
* receiverSocketId * receiverSocket
* } * }
* *
**/ **/
@ -193,11 +193,11 @@ peers.on('connection', async socket => {
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`); console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
if (!videoCalls[callId]) { if (!videoCalls[callId]) {
console.log('[createRoom] callId', 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}`); console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
videoCalls[callId].receiverSocketId = socket.id videoCalls[callId].receiverSocket = socket;
} else { } else {
videoCalls[callId].initiatorSockerId = socket.id videoCalls[callId].initiatorSocket = socket;
} }
socketDetails[socket.id] = callId; socketDetails[socket.id] = callId;
// rtpCapabilities is set for callback // rtpCapabilities is set for callback
@ -295,72 +295,32 @@ peers.on('connection', async socket => {
// videoCalls[callId].router
const router = 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( console.log(
"new producer created [worker.pid:%d, router.id:%s, transport.id:%s, producer.id:%s]", "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", () =>
{ if (!isInitiator(callId, socket.id)) {
console.log("producer closed [producer.id:%s]", producer.id); console.log('🟥 Emit to initiatorSocket');
}); initiatorSocket.emit('new-producer', {
}); callId
});
transport.observer.on("newconsumer", (consumer) =>
{ } else {
console.log( console.log('🟥 Emit to receiverSocket');
"new consumer created [worker.pid:%d, router.id:%s, transport.id:%s, consumer.id:%s]", receiverSocket.emit('new-producer', {
worker.pid, router.id, transport.id, consumer.id); callId
});
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);
});
}); });
}); });
@ -684,7 +644,7 @@ const consumeAudio = async (callId, socketId, rtpCapabilities) => {
} }
const isInitiator = (callId, socketId) => { 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() } if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() }
}) })
socket.on('new-producer', ({ callId }) => {
console.log(`🟥 new-producer | callId: ${callId}`);
})
} }
if (IS_PRODUCER === true) { if (IS_PRODUCER === true) {