Send answer and connect to transport layer created with 7s delay

This commit is contained in:
Sergiu Toma 2022-09-05 18:11:13 +03:00
parent ab540b276a
commit 42dffe1cbb

View File

@ -208,24 +208,6 @@ const getRtpCapabilities = () => {
const createSendTransport = () => { const createSendTransport = () => {
setTimeout(() => {
const answer = {
origin_asset_id: ASSET_ID,
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
type: 'notify-answer',
origin_asset_priority: 1,
origin_asset_type_name: ASSET_TYPE,
origin_asset_name: ASSET_NAME,
video_call_id: callId,
answer: 'accepted', // answer: 'rejected'
};
console.log('SEND answer', answer);
hub.emit(
'video',
JSON.stringify(answer)
);
// see server's socket.on('createWebRtcTransport', sender?, ...) // see server's socket.on('createWebRtcTransport', sender?, ...)
// this is a call from Producer, so sender = true // this is a call from Producer, so sender = true
socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => { socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => {
@ -287,52 +269,47 @@ const createSendTransport = () => {
}) })
connectSendTransport() connectSendTransport()
}) })
}, 7000);
} }
const connectSendTransport = async () => { const connectSendTransport = async () => {
console.log('[connectSendTransport]'); setTimeout(() => {
// we now call produce() to instruct the producer transport console.log('[connectSendTransport]');
// to send media to the Router // we now call produce() to instruct the producer transport
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce // to send media to the Router
// this action will trigger the 'connect' and 'produce' events above // https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
producer = await producerTransport.produce(params) // this action will trigger the 'connect' and 'produce' events above
producer = await producerTransport.produce(params)
producer.on('trackended', () => { producer.on('trackended', () => {
console.log('track ended') console.log('track ended')
// close video track // close video track
}) })
producer.on('transportclose', () => { producer.on('transportclose', () => {
console.log('transport ended') console.log('transport ended')
// close video track // close video track
}) })
const answer = { // Enable Close call button
origin_asset_id: ASSET_ID, const closeCallBtn = document.getElementById('btnCloseCall');
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')), closeCallBtn.removeAttribute('disabled');
type: 'notify-answer',
origin_asset_priority: 1,
origin_asset_type_name: ASSET_TYPE,
origin_asset_name: ASSET_NAME,
video_call_id: callId,
answer: 'accepted', // answer: 'rejected'
};
console.log('SEND answer', answer);
// setTimeout(() => { const answer = {
// hub.emit( origin_asset_id: ASSET_ID,
// 'video', dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
// JSON.stringify(answer) type: 'notify-answer',
// ); origin_asset_priority: 1,
// }, 7000); origin_asset_type_name: ASSET_TYPE,
origin_asset_name: ASSET_NAME,
// Enable Close call button video_call_id: callId,
const closeCallBtn = document.getElementById('btnCloseCall'); answer: 'accepted', // answer: 'rejected'
closeCallBtn.removeAttribute('disabled'); };
console.log('SEND answer', answer);
hub.emit(
'video',
JSON.stringify(answer)
);
}, 7000);
} }
const createRecvTransport = async () => { const createRecvTransport = async () => {