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

This commit is contained in:
Sergiu Toma 2022-09-05 18:23:43 +03:00
parent 42dffe1cbb
commit dbd4202d3e
2 changed files with 51 additions and 48 deletions

View File

@ -20653,8 +20653,8 @@ module.exports = yeast;
},{}],95:[function(require,module,exports){ },{}],95:[function(require,module,exports){
module.exports = { module.exports = {
hubAddress: 'https://hub.dev.linx.safemobile.com/', hubAddress: 'https://hub.dev.linx.safemobile.com/',
// mediasoupAddress: 'https://video.safemobile.org/mediasoup', mediasoupAddress: 'https://video.safemobile.org/mediasoup',
mediasoupAddress: 'http://localhost:3000/mediasoup', // mediasoupAddress: 'http://localhost:3000/mediasoup',
} }
},{}],96:[function(require,module,exports){ },{}],96:[function(require,module,exports){
const io = require('socket.io-client') const io = require('socket.io-client')
@ -20866,6 +20866,7 @@ const getRtpCapabilities = () => {
} }
const createSendTransport = () => { const createSendTransport = () => {
// 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 }) => {
@ -20876,7 +20877,7 @@ const createSendTransport = () => {
return return
} }
console.log(params) console.log('params', params)
// creates a new WebRTC Transport to send media // creates a new WebRTC Transport to send media
// based on the server's producer transport params // based on the server's producer transport params
@ -20903,7 +20904,7 @@ const createSendTransport = () => {
}) })
producerTransport.on('produce', async (parameters, callback, errback) => { producerTransport.on('produce', async (parameters, callback, errback) => {
console.log(parameters) console.log('produce', parameters)
try { try {
// tell the server to create a Producer // tell the server to create a Producer
@ -20915,56 +20916,59 @@ const createSendTransport = () => {
rtpParameters: parameters.rtpParameters, rtpParameters: parameters.rtpParameters,
appData: parameters.appData, appData: parameters.appData,
}, ({ id }) => { }, ({ id }) => {
console.log('[transport-produce] callback | id', id);
// Tell the transport that parameters were transmitted and provide it with the // Tell the transport that parameters were transmitted and provide it with the
// server side producer's id. // server side producer's id.
callback({ id }) callback({ id })
}) })
} catch (error) { } catch (error) {
console.log('ERROR | produce |', error);
errback(error) errback(error)
} }
}) })
connectSendTransport() connectSendTransport()
}) })
} }
const connectSendTransport = async () => { const connectSendTransport = async () => {
console.log('[connectSendTransport]');
// we now call produce() to instruct the producer transport // we now call produce() to instruct the producer transport
// to send media to the Router // to send media to the Router
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce // https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
// this action will trigger the 'connect' and 'produce' events above // this action will trigger the 'connect' and 'produce' events above
producer = await producerTransport.produce(params) producer = await producerTransport.produce(params)
producer.on('trackended', () => { setTimeout(() => {
console.log('track ended') producer.on('trackended', () => {
// close video track console.log('track ended')
}) // 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);
hub.emit( const answer = {
'video', origin_asset_id: ASSET_ID,
JSON.stringify(answer) dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
); type: 'notify-answer',
origin_asset_priority: 1,
// Enable Close call button origin_asset_type_name: ASSET_TYPE,
const closeCallBtn = document.getElementById('btnCloseCall'); origin_asset_name: ASSET_NAME,
closeCallBtn.removeAttribute('disabled'); video_call_id: callId,
answer: 'accepted', // answer: 'rejected'
};
console.log('SEND answer', answer);
hub.emit(
'video',
JSON.stringify(answer)
);
}, 7000);
} }
const createRecvTransport = async () => { const createRecvTransport = async () => {
@ -21009,7 +21013,6 @@ const createRecvTransport = async () => {
} }
const resetCallSettings = () => { const resetCallSettings = () => {
socket.emit('transportclose', { callId })
localVideo.srcObject = null localVideo.srcObject = null
remoteVideo.srcObject = null remoteVideo.srcObject = null
consumer = null consumer = null
@ -21060,9 +21063,9 @@ const closeCall = () => {
// Emit 'notify-end' to Hub so the consumer will know to close the video // Emit 'notify-end' to Hub so the consumer will know to close the video
const notifyEnd = { const notifyEnd = {
origin_asset_id: ASSET_ID, origin_asset_id: ASSET_ID,
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')), dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
type: 'notify-end', type: 'notify-end',
video_call_id: callId video_call_id: callId
} }
console.log('notifyEnd', notifyEnd) console.log('notifyEnd', notifyEnd)
@ -21072,7 +21075,7 @@ const closeCall = () => {
const closeCallBtn = document.getElementById('btnCloseCall') const closeCallBtn = document.getElementById('btnCloseCall')
closeCallBtn.setAttribute('disabled', '') closeCallBtn.setAttribute('disabled', '')
// Reset settings and send closeTransport to video server // Reset settings
resetCallSettings() resetCallSettings()
} }

View File

@ -272,14 +272,14 @@ const createSendTransport = () => {
} }
const connectSendTransport = async () => { const connectSendTransport = async () => {
setTimeout(() => { console.log('[connectSendTransport]');
console.log('[connectSendTransport]'); // we now call produce() to instruct the producer transport
// we now call produce() to instruct the producer transport // to send media to the Router
// to send media to the Router // https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce // this action will trigger the 'connect' and 'produce' events above
// this action will trigger the 'connect' and 'produce' events above producer = await producerTransport.produce(params)
producer = await producerTransport.produce(params)
setTimeout(() => {
producer.on('trackended', () => { producer.on('trackended', () => {
console.log('track ended') console.log('track ended')
// close video track // close video track