test
This commit is contained in:
parent
5ef8b4f15c
commit
4574b9daf0
67
app.js
67
app.js
@ -192,15 +192,11 @@ peers.on('connection', async socket => {
|
||||
if (callId) {
|
||||
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
|
||||
if (!videoCalls[callId]) {
|
||||
console.log('[createRoom] callId', callId);
|
||||
videoCalls[callId] = { router: await worker.createRouter({ mediaCodecs }) };
|
||||
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
|
||||
videoCalls[callId].receiverSocket = socket;
|
||||
console.log('------------', videoCalls[callId].receiverSocket);
|
||||
console.log('🟦 videoCalls[callId].receiverSocket.socket.id', videoCalls[callId].receiverSocket.id)
|
||||
} else {
|
||||
videoCalls[callId].initiatorSocket = socket;
|
||||
console.log('🟦 videoCalls[callId].initiatorSocket.id', videoCalls[callId].initiatorSocket.id)
|
||||
}
|
||||
socketDetails[socket.id] = callId;
|
||||
// rtpCapabilities is set for callback
|
||||
@ -228,18 +224,12 @@ peers.on('connection', async socket => {
|
||||
*/
|
||||
socket.on('createWebRtcTransport', async ({ sender }, callback) => {
|
||||
try {
|
||||
console.log('@@@ socket.id', socket.id, 'sender', sender);
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log(`[createWebRtcTransport] socket ${socket.id} | sender ${sender} | callId ${callId}`);
|
||||
if (sender) {
|
||||
console.log('OOOOOOOOOOOOOOOOOO');
|
||||
console.log(!isInitiator(callId, socket.id));
|
||||
console.log('OOOOOOOOOOOOOOOOOO');
|
||||
if(!videoCalls[callId].receiverProducerTransport && !isInitiator(callId, socket.id)) {
|
||||
console.log('1');
|
||||
videoCalls[callId].receiverProducerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
} else if(!videoCalls[callId].initiatorProducerTransport && isInitiator(callId, socket.id)) {
|
||||
console.log('1');
|
||||
videoCalls[callId].initiatorProducerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
} else {
|
||||
console.log(`producerTransport has already been defined | callId ${callId}`);
|
||||
@ -247,10 +237,8 @@ peers.on('connection', async socket => {
|
||||
}
|
||||
} else if (!sender) {
|
||||
if(!videoCalls[callId].receiverConsumerTransport && !isInitiator(callId, socket.id)) {
|
||||
console.log('3');
|
||||
videoCalls[callId].receiverConsumerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
} else if(!videoCalls[callId].initiatorConsumerTransport && isInitiator(callId, socket.id)) {
|
||||
console.log('4');
|
||||
videoCalls[callId].initiatorConsumerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
}
|
||||
}
|
||||
@ -302,39 +290,31 @@ peers.on('connection', async socket => {
|
||||
|
||||
|
||||
|
||||
const router = videoCalls[callId].router;receiverSocket
|
||||
|
||||
router.observer.on("newtransport", (transport) => {
|
||||
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
|
||||
);
|
||||
|
||||
if (!isInitiator(callId, socket.id)) {
|
||||
console.log('🟥 Emit to initiatorSocket');
|
||||
initiatorSocket.emit('new-producer', {
|
||||
callId
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// const router = videoCalls[callId].router;receiverSocket
|
||||
|
||||
// router.observer.on("newtransport", (transport) => {
|
||||
// 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
|
||||
// );
|
||||
|
||||
// if (!isInitiator(callId, socket.id)) {
|
||||
// console.log('🟥 Emit to initiatorSocket');
|
||||
// initiatorSocket.emit('new-producer', {
|
||||
// callId
|
||||
// });
|
||||
|
||||
// } else {
|
||||
// console.log('🟥 Emit to receiverSocket');
|
||||
// receiverSocket.emit('new-producer', {
|
||||
// callId
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
} else {
|
||||
console.log('🟥 Emit to receiverSocket');
|
||||
receiverSocket.emit('new-producer', {
|
||||
callId
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// });
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -655,10 +635,6 @@ const consumeAudio = async (callId, socketId, rtpCapabilities) => {
|
||||
}
|
||||
|
||||
const isInitiator = (callId, socketId) => {
|
||||
console.log('isInitiator', callId, socketId);
|
||||
console.log('videoCalls', videoCalls);
|
||||
console.log('===============videoCalls[callId].initiatorSocket.id', videoCalls[callId]?.initiatorSocket?.id);
|
||||
console.log('===============socketId', socketId);
|
||||
return (videoCalls[callId]?.initiatorSocket?.id === socketId);
|
||||
}
|
||||
|
||||
@ -687,7 +663,6 @@ const createWebRtcTransportLayer = async (callId, callback) => {
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-createWebRtcTransport
|
||||
let transport = await videoCalls[callId].router.createWebRtcTransport(webRtcTransport_options)
|
||||
console.log(`@@@ callId: ${callId} | transport id: ${transport.id}`)
|
||||
|
||||
// Handler for when DTLS(Datagram Transport Layer Security) changes
|
||||
transport.on('dtlsstatechange', dtlsState => {
|
||||
@ -702,8 +677,6 @@ const createWebRtcTransportLayer = async (callId, callback) => {
|
||||
console.log(`transport | closed | calldId ${callId}`);
|
||||
});
|
||||
|
||||
console.log('---------transport', transport);
|
||||
|
||||
const params = {
|
||||
id: transport.id,
|
||||
iceParameters: transport.iceParameters,
|
||||
|
@ -96,9 +96,9 @@ setTimeout(() => {
|
||||
if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() }
|
||||
})
|
||||
|
||||
// socket.on('new-producer', ({ callId }) => {
|
||||
// console.log(`🟥 new-producer | callId: ${callId}`);
|
||||
// })
|
||||
socket.on('new-producer', ({ callId }) => {
|
||||
console.log(`🟥 new-producer | callId: ${callId}`);
|
||||
})
|
||||
}
|
||||
|
||||
if (IS_PRODUCER === true) {
|
||||
|
Loading…
Reference in New Issue
Block a user