Update server
This commit is contained in:
parent
fc745a5879
commit
4bb23def42
@ -20527,23 +20527,9 @@ const getLocalStream = () => {
|
|||||||
|
|
||||||
navigator.permissions.query(
|
navigator.permissions.query(
|
||||||
{ name: 'microphone' }
|
{ name: 'microphone' }
|
||||||
).then(function(permissionStatus) {
|
).then((permissionStatus) =>{
|
||||||
|
console.log('🟨 [PERMISSION] permissionStatus', permissionStatus); // granted, denied, prompt
|
||||||
console.log('🟨 [PERMISSION] onchange1', permissionStatus.state); // granted, denied, prompt
|
// It will block the code from execution and display "Permission denied" if we don't have microphone permissions
|
||||||
|
|
||||||
// If he has entered before, the saved access is already saved
|
|
||||||
if (permissionStatus === 'grated') {
|
|
||||||
doIHaveAudio = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it is the first time client enter and give permission
|
|
||||||
permissionStatus.onchange = function() {
|
|
||||||
console.log('🟨 [PERMISSION] onchange2', this.state);
|
|
||||||
if (this.state === 'grated') {
|
|
||||||
// doIHaveAudio = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -20645,7 +20631,7 @@ const createSendTransport = () => {
|
|||||||
console.log('[produce] parameters', parameters)
|
console.log('[produce] parameters', parameters)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// tell the server to create a Producer
|
// Tell the server to create a Producer
|
||||||
// with the following parameters and produce
|
// with the following parameters and produce
|
||||||
// and expect back a server side producer id
|
// and expect back a server side producer id
|
||||||
// see server's socket.on('transport-produce', ...)
|
// see server's socket.on('transport-produce', ...)
|
||||||
@ -20671,14 +20657,16 @@ const connectSendTransport = async () => {
|
|||||||
|
|
||||||
console.log('[connectSendTransport] producerTransport');
|
console.log('[connectSendTransport] producerTransport');
|
||||||
|
|
||||||
// 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
|
||||||
|
|
||||||
console.log('videoParams', videoParams);
|
// Produce video
|
||||||
producerVideo = await producerTransport.produce(videoParams)
|
producerVideo = await producerTransport.produce(videoParams)
|
||||||
|
console.log('videoParams', videoParams);
|
||||||
console.log('producerVideo', producerVideo);
|
console.log('producerVideo', producerVideo);
|
||||||
|
|
||||||
producerVideo.on('trackended', () => {
|
producerVideo.on('trackended', () => {
|
||||||
console.log('track ended')
|
console.log('track ended')
|
||||||
// close video track
|
// close video track
|
||||||
@ -20689,21 +20677,20 @@ const connectSendTransport = async () => {
|
|||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
|
|
||||||
// Video is mandatory, but audio may not be included
|
// Produce audio
|
||||||
// if (doIHaveAudio) {
|
producerAudio = await producerTransport.produce(audioParams)
|
||||||
console.log('audioParams', audioParams);
|
console.log('audioParams', audioParams);
|
||||||
producerAudio = await producerTransport.produce(audioParams)
|
console.log('producerAudio', producerAudio);
|
||||||
console.log('producerAudio', producerAudio);
|
|
||||||
producerAudio.on('trackended', () => {
|
producerAudio.on('trackended', () => {
|
||||||
console.log('track ended')
|
console.log('track ended')
|
||||||
// close video track
|
// close audio track
|
||||||
})
|
})
|
||||||
|
|
||||||
producerAudio.on('transportclose', () => {
|
producerAudio.on('transportclose', () => {
|
||||||
console.log('transport ended')
|
console.log('transport ended')
|
||||||
// close video track
|
// close audio track
|
||||||
})
|
})
|
||||||
// }
|
|
||||||
|
|
||||||
const answer = {
|
const answer = {
|
||||||
origin_asset_id: ASSET_ID,
|
origin_asset_id: ASSET_ID,
|
||||||
@ -20713,7 +20700,7 @@ const connectSendTransport = async () => {
|
|||||||
origin_asset_type_name: ASSET_TYPE,
|
origin_asset_type_name: ASSET_TYPE,
|
||||||
origin_asset_name: ASSET_NAME,
|
origin_asset_name: ASSET_NAME,
|
||||||
video_call_id: callId,
|
video_call_id: callId,
|
||||||
answer: 'accepted', // answer: 'rejected'
|
answer: 'accepted', // answer: accepted/rejected
|
||||||
};
|
};
|
||||||
console.log('SEND answer', answer);
|
console.log('SEND answer', answer);
|
||||||
|
|
||||||
@ -20729,7 +20716,7 @@ const connectSendTransport = async () => {
|
|||||||
|
|
||||||
const createRecvTransport = async () => {
|
const createRecvTransport = async () => {
|
||||||
console.log('createRecvTransport');
|
console.log('createRecvTransport');
|
||||||
// see server's socket.on('consume', sender?, ...)
|
// See server's socket.on('consume', sender?, ...)
|
||||||
// this is a call from Consumer, so sender = false
|
// this is a call from Consumer, so sender = false
|
||||||
await socket.emit('createWebRtcTransport', { sender: false, callId }, ({ params }) => {
|
await socket.emit('createWebRtcTransport', { sender: false, callId }, ({ params }) => {
|
||||||
// The server sends back params needed
|
// The server sends back params needed
|
||||||
@ -20741,13 +20728,13 @@ const createRecvTransport = async () => {
|
|||||||
|
|
||||||
console.log('[createRecvTransport] params', params)
|
console.log('[createRecvTransport] params', params)
|
||||||
|
|
||||||
// creates a new WebRTC Transport to receive media
|
// Creates a new WebRTC Transport to receive media
|
||||||
// based on server's consumer transport params
|
// based on server's consumer transport params
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-createRecvTransport
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-createRecvTransport
|
||||||
consumerTransport = device.createRecvTransport(params)
|
consumerTransport = device.createRecvTransport(params)
|
||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/communication-between-client-and-server/#producing-media
|
// https://mediasoup.org/documentation/v3/communication-between-client-and-server/#producing-media
|
||||||
// this event is raised when a first call to transport.produce() is made
|
// This event is raised when a first call to transport.produce() is made
|
||||||
// see connectRecvTransport() below
|
// see connectRecvTransport() below
|
||||||
consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => {
|
consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => {
|
||||||
try {
|
try {
|
||||||
@ -20781,7 +20768,7 @@ const resetCallSettings = () => {
|
|||||||
|
|
||||||
const connectRecvTransport = async () => {
|
const connectRecvTransport = async () => {
|
||||||
console.log('connectRecvTransport');
|
console.log('connectRecvTransport');
|
||||||
// for consumer, we need to tell the server first
|
// For consumer, we need to tell the server first
|
||||||
// to create a consumer based on the rtpCapabilities and consume
|
// to create a consumer based on the rtpCapabilities and consume
|
||||||
// if the router can consume, it will send back a set of params as below
|
// if the router can consume, it will send back a set of params as below
|
||||||
await socket.emit('consume', {
|
await socket.emit('consume', {
|
||||||
@ -20793,7 +20780,7 @@ const connectRecvTransport = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// then consume with the local consumer transport
|
// Then consume with the local consumer transport
|
||||||
// which creates a consumer
|
// which creates a consumer
|
||||||
consumer = await consumerTransport.consume({
|
consumer = await consumerTransport.consume({
|
||||||
id: params.id,
|
id: params.id,
|
||||||
|
@ -169,23 +169,9 @@ const getLocalStream = () => {
|
|||||||
|
|
||||||
navigator.permissions.query(
|
navigator.permissions.query(
|
||||||
{ name: 'microphone' }
|
{ name: 'microphone' }
|
||||||
).then(function(permissionStatus) {
|
).then((permissionStatus) =>{
|
||||||
|
console.log('🟨 [PERMISSION] permissionStatus', permissionStatus); // granted, denied, prompt
|
||||||
console.log('🟨 [PERMISSION] onchange1', permissionStatus.state); // granted, denied, prompt
|
// It will block the code from execution and display "Permission denied" if we don't have microphone permissions
|
||||||
|
|
||||||
// If he has entered before, the saved access is already saved
|
|
||||||
if (permissionStatus === 'grated') {
|
|
||||||
doIHaveAudio = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it is the first time client enter and give permission
|
|
||||||
permissionStatus.onchange = function() {
|
|
||||||
console.log('🟨 [PERMISSION] onchange2', this.state);
|
|
||||||
if (this.state === 'grated') {
|
|
||||||
// doIHaveAudio = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -287,7 +273,7 @@ const createSendTransport = () => {
|
|||||||
console.log('[produce] parameters', parameters)
|
console.log('[produce] parameters', parameters)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// tell the server to create a Producer
|
// Tell the server to create a Producer
|
||||||
// with the following parameters and produce
|
// with the following parameters and produce
|
||||||
// and expect back a server side producer id
|
// and expect back a server side producer id
|
||||||
// see server's socket.on('transport-produce', ...)
|
// see server's socket.on('transport-produce', ...)
|
||||||
@ -313,14 +299,16 @@ const connectSendTransport = async () => {
|
|||||||
|
|
||||||
console.log('[connectSendTransport] producerTransport');
|
console.log('[connectSendTransport] producerTransport');
|
||||||
|
|
||||||
// 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
|
||||||
|
|
||||||
console.log('videoParams', videoParams);
|
// Produce video
|
||||||
producerVideo = await producerTransport.produce(videoParams)
|
producerVideo = await producerTransport.produce(videoParams)
|
||||||
|
console.log('videoParams', videoParams);
|
||||||
console.log('producerVideo', producerVideo);
|
console.log('producerVideo', producerVideo);
|
||||||
|
|
||||||
producerVideo.on('trackended', () => {
|
producerVideo.on('trackended', () => {
|
||||||
console.log('track ended')
|
console.log('track ended')
|
||||||
// close video track
|
// close video track
|
||||||
@ -331,21 +319,20 @@ const connectSendTransport = async () => {
|
|||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
|
|
||||||
// Video is mandatory, but audio may not be included
|
// Produce audio
|
||||||
// if (doIHaveAudio) {
|
producerAudio = await producerTransport.produce(audioParams)
|
||||||
console.log('audioParams', audioParams);
|
console.log('audioParams', audioParams);
|
||||||
producerAudio = await producerTransport.produce(audioParams)
|
console.log('producerAudio', producerAudio);
|
||||||
console.log('producerAudio', producerAudio);
|
|
||||||
producerAudio.on('trackended', () => {
|
producerAudio.on('trackended', () => {
|
||||||
console.log('track ended')
|
console.log('track ended')
|
||||||
// close video track
|
// close audio track
|
||||||
})
|
})
|
||||||
|
|
||||||
producerAudio.on('transportclose', () => {
|
producerAudio.on('transportclose', () => {
|
||||||
console.log('transport ended')
|
console.log('transport ended')
|
||||||
// close video track
|
// close audio track
|
||||||
})
|
})
|
||||||
// }
|
|
||||||
|
|
||||||
const answer = {
|
const answer = {
|
||||||
origin_asset_id: ASSET_ID,
|
origin_asset_id: ASSET_ID,
|
||||||
@ -355,7 +342,7 @@ const connectSendTransport = async () => {
|
|||||||
origin_asset_type_name: ASSET_TYPE,
|
origin_asset_type_name: ASSET_TYPE,
|
||||||
origin_asset_name: ASSET_NAME,
|
origin_asset_name: ASSET_NAME,
|
||||||
video_call_id: callId,
|
video_call_id: callId,
|
||||||
answer: 'accepted', // answer: 'rejected'
|
answer: 'accepted', // answer: accepted/rejected
|
||||||
};
|
};
|
||||||
console.log('SEND answer', answer);
|
console.log('SEND answer', answer);
|
||||||
|
|
||||||
@ -371,7 +358,7 @@ const connectSendTransport = async () => {
|
|||||||
|
|
||||||
const createRecvTransport = async () => {
|
const createRecvTransport = async () => {
|
||||||
console.log('createRecvTransport');
|
console.log('createRecvTransport');
|
||||||
// see server's socket.on('consume', sender?, ...)
|
// See server's socket.on('consume', sender?, ...)
|
||||||
// this is a call from Consumer, so sender = false
|
// this is a call from Consumer, so sender = false
|
||||||
await socket.emit('createWebRtcTransport', { sender: false, callId }, ({ params }) => {
|
await socket.emit('createWebRtcTransport', { sender: false, callId }, ({ params }) => {
|
||||||
// The server sends back params needed
|
// The server sends back params needed
|
||||||
@ -383,13 +370,13 @@ const createRecvTransport = async () => {
|
|||||||
|
|
||||||
console.log('[createRecvTransport] params', params)
|
console.log('[createRecvTransport] params', params)
|
||||||
|
|
||||||
// creates a new WebRTC Transport to receive media
|
// Creates a new WebRTC Transport to receive media
|
||||||
// based on server's consumer transport params
|
// based on server's consumer transport params
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-createRecvTransport
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-createRecvTransport
|
||||||
consumerTransport = device.createRecvTransport(params)
|
consumerTransport = device.createRecvTransport(params)
|
||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/communication-between-client-and-server/#producing-media
|
// https://mediasoup.org/documentation/v3/communication-between-client-and-server/#producing-media
|
||||||
// this event is raised when a first call to transport.produce() is made
|
// This event is raised when a first call to transport.produce() is made
|
||||||
// see connectRecvTransport() below
|
// see connectRecvTransport() below
|
||||||
consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => {
|
consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => {
|
||||||
try {
|
try {
|
||||||
@ -423,7 +410,7 @@ const resetCallSettings = () => {
|
|||||||
|
|
||||||
const connectRecvTransport = async () => {
|
const connectRecvTransport = async () => {
|
||||||
console.log('connectRecvTransport');
|
console.log('connectRecvTransport');
|
||||||
// for consumer, we need to tell the server first
|
// For consumer, we need to tell the server first
|
||||||
// to create a consumer based on the rtpCapabilities and consume
|
// to create a consumer based on the rtpCapabilities and consume
|
||||||
// if the router can consume, it will send back a set of params as below
|
// if the router can consume, it will send back a set of params as below
|
||||||
await socket.emit('consume', {
|
await socket.emit('consume', {
|
||||||
@ -435,7 +422,7 @@ const connectRecvTransport = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// then consume with the local consumer transport
|
// Then consume with the local consumer transport
|
||||||
// which creates a consumer
|
// which creates a consumer
|
||||||
consumer = await consumerTransport.consume({
|
consumer = await consumerTransport.consume({
|
||||||
id: params.id,
|
id: params.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user