LAPI-675: Update server go emit new-producer; Update client to handle this event
This commit is contained in:
parent
eece7d2ee3
commit
9b4e0186ac
82
app.js
82
app.js
@ -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
|
||||||
@ -299,68 +299,28 @@ 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('🟥 Emit to initiatorSocket');
|
||||||
console.log("producer closed [producer.id:%s]", producer.id);
|
initiatorSocket.emit('new-producer', {
|
||||||
});
|
callId
|
||||||
});
|
});
|
||||||
|
|
||||||
transport.observer.on("newconsumer", (consumer) =>
|
} else {
|
||||||
{
|
console.log('🟥 Emit to receiverSocket');
|
||||||
console.log(
|
receiverSocket.emit('new-producer', {
|
||||||
"new consumer created [worker.pid:%d, router.id:%s, transport.id:%s, consumer.id:%s]",
|
callId
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user