[mirotalksfu] - refactoring
هذا الالتزام موجود في:
@@ -194,6 +194,7 @@ module.exports = class Peer {
|
|||||||
const { scalabilityMode } = rtpParameters.encodings[0];
|
const { scalabilityMode } = rtpParameters.encodings[0];
|
||||||
const spatialLayer = parseInt(scalabilityMode.substring(1, 2)); // 1/2/3
|
const spatialLayer = parseInt(scalabilityMode.substring(1, 2)); // 1/2/3
|
||||||
const temporalLayer = parseInt(scalabilityMode.substring(3, 4)); // 1/2/3
|
const temporalLayer = parseInt(scalabilityMode.substring(3, 4)); // 1/2/3
|
||||||
|
|
||||||
log.debug(`Producer [${type}-${kind}] ----->`, {
|
log.debug(`Producer [${type}-${kind}] ----->`, {
|
||||||
scalabilityMode,
|
scalabilityMode,
|
||||||
spatialLayer,
|
spatialLayer,
|
||||||
@@ -251,7 +252,7 @@ module.exports = class Peer {
|
|||||||
this.consumers.delete(consumer_id);
|
this.consumers.delete(consumer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async createConsumer(consumer_transport_id, producer_id, rtpCapabilities) {
|
async createConsumer(consumer_transport_id, producerId, rtpCapabilities) {
|
||||||
if (!this.transports.has(consumer_transport_id)) {
|
if (!this.transports.has(consumer_transport_id)) {
|
||||||
throw new Error(`Consumer transport with ID ${consumer_transport_id} not found`);
|
throw new Error(`Consumer transport with ID ${consumer_transport_id} not found`);
|
||||||
}
|
}
|
||||||
@@ -261,7 +262,7 @@ module.exports = class Peer {
|
|||||||
let consumer;
|
let consumer;
|
||||||
try {
|
try {
|
||||||
consumer = await consumerTransport.consume({
|
consumer = await consumerTransport.consume({
|
||||||
producerId: producer_id,
|
producerId,
|
||||||
rtpCapabilities,
|
rtpCapabilities,
|
||||||
enableRtx: true, // Enable NACK for OPUS.
|
enableRtx: true, // Enable NACK for OPUS.
|
||||||
paused: true,
|
paused: true,
|
||||||
@@ -284,8 +285,8 @@ module.exports = class Peer {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await consumer.setPreferredLayers({
|
await consumer.setPreferredLayers({
|
||||||
spatialLayer: spatialLayer,
|
spatialLayer,
|
||||||
temporalLayer: temporalLayer,
|
temporalLayer,
|
||||||
});
|
});
|
||||||
log.debug(`Consumer [${type}-${kind}] ----->`, {
|
log.debug(`Consumer [${type}-${kind}] ----->`, {
|
||||||
scalabilityMode,
|
scalabilityMode,
|
||||||
@@ -310,7 +311,7 @@ module.exports = class Peer {
|
|||||||
return {
|
return {
|
||||||
consumer: consumer,
|
consumer: consumer,
|
||||||
params: {
|
params: {
|
||||||
producerId: producer_id,
|
producerId,
|
||||||
id: id,
|
id: id,
|
||||||
kind: kind,
|
kind: kind,
|
||||||
rtpParameters: rtpParameters,
|
rtpParameters: rtpParameters,
|
||||||
|
|||||||
@@ -707,30 +707,30 @@ module.exports = class Room {
|
|||||||
// CONSUME
|
// CONSUME
|
||||||
// ####################################################
|
// ####################################################
|
||||||
|
|
||||||
async consume(socket_id, consumer_transport_id, producer_id, rtpCapabilities) {
|
async consume(socket_id, consumer_transport_id, producerId, rtpCapabilities, type) {
|
||||||
if (!this.peers.has(socket_id)) {
|
if (!this.peers.has(socket_id)) {
|
||||||
throw new Error(`Peer with socket ID ${socket_id} not found in the room`);
|
throw new Error(`Peer with socket ID ${socket_id} not found in the room`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.router.canConsume({ producerId: producer_id, rtpCapabilities })) {
|
if (!this.router.canConsume({ producerId, rtpCapabilities })) {
|
||||||
throw new Error(`Cannot consume producer with ID ${producer_id}, router validation failed`);
|
throw new Error(`Cannot consume producer with ID ${producerId} type ${type}, router validation failed`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const peer = this.getPeer(socket_id);
|
const peer = this.getPeer(socket_id);
|
||||||
|
|
||||||
let peerConsumer;
|
let peerConsumer;
|
||||||
try {
|
try {
|
||||||
peerConsumer = await peer.createConsumer(consumer_transport_id, producer_id, rtpCapabilities);
|
peerConsumer = await peer.createConsumer(consumer_transport_id, producerId, rtpCapabilities);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error creating consumer for peer with socket ID ${socket_id}`, error);
|
log.error(`Error creating consumer for peer with socket ID ${socket_id}`, error);
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to create consumer with transport ID ${consumer_transport_id} and producer ID ${producer_id} for peer ${socket_id}`,
|
`Failed to create consumer with transport ID ${consumer_transport_id} and producer ID ${producerId} type ${type} for peer ${socket_id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!peerConsumer) {
|
if (!peerConsumer) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Consumer creation failed for transport ID ${consumer_transport_id} and producer ID ${producer_id}`,
|
`Consumer creation failed for transport ID ${consumer_transport_id} and producer ID ${producerId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ dev dependencies: {
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.6.63
|
* @version 1.6.64
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -1674,7 +1674,7 @@ function startServer() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('consume', async ({ consumerTransportId, producerId, rtpCapabilities }, callback) => {
|
socket.on('consume', async ({ consumerTransportId, producerId, rtpCapabilities, type }, callback) => {
|
||||||
if (!roomExists(socket)) {
|
if (!roomExists(socket)) {
|
||||||
return callback({ error: 'Room not found' });
|
return callback({ error: 'Room not found' });
|
||||||
}
|
}
|
||||||
@@ -1684,10 +1684,11 @@ function startServer() {
|
|||||||
const { peer_name } = peer || 'undefined';
|
const { peer_name } = peer || 'undefined';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const params = await room.consume(socket.id, consumerTransportId, producerId, rtpCapabilities);
|
const params = await room.consume(socket.id, consumerTransportId, producerId, rtpCapabilities, type);
|
||||||
|
|
||||||
log.debug('Consuming', {
|
log.debug('Consuming', {
|
||||||
peer_name: peer_name,
|
peer_name: peer_name,
|
||||||
|
producer_type: type,
|
||||||
producer_id: producerId,
|
producer_id: producerId,
|
||||||
consumer_id: params ? params.id : undefined,
|
consumer_id: params ? params.id : undefined,
|
||||||
});
|
});
|
||||||
@@ -1711,21 +1712,21 @@ function startServer() {
|
|||||||
room.closeProducer(socket.id, data.producer_id);
|
room.closeProducer(socket.id, data.producer_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('pauseProducer', async ({ producer_id }, callback) => {
|
socket.on('pauseProducer', async ({ producer_id, type }, callback) => {
|
||||||
if (!roomExists(socket)) return;
|
if (!roomExists(socket)) return;
|
||||||
|
|
||||||
const peer = getPeer(socket);
|
const peer = getPeer(socket);
|
||||||
|
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
return callback({
|
return callback({
|
||||||
error: `Peer with ID: ${socket.id} for producer with id "${producer_id}" not found`,
|
error: `Peer with ID: ${socket.id} for producer with id "${producer_id}" type "${type}" not found`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const producer = peer.getProducer(producer_id);
|
const producer = peer.getProducer(producer_id);
|
||||||
|
|
||||||
if (!producer) {
|
if (!producer) {
|
||||||
return callback({ error: `Producer with id "${producer_id}" not found` });
|
return callback({ error: `Producer with id "${producer_id}" type "${type}" not found` });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -1733,7 +1734,7 @@ function startServer() {
|
|||||||
|
|
||||||
const { peer_name } = peer || 'undefined';
|
const { peer_name } = peer || 'undefined';
|
||||||
|
|
||||||
log.debug('Producer paused', { peer_name: peer_name, producer_id: producer_id });
|
log.debug('Producer paused', { peer_name, producer_id, type });
|
||||||
|
|
||||||
callback('successfully');
|
callback('successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1741,21 +1742,21 @@ function startServer() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('resumeProducer', async ({ producer_id }, callback) => {
|
socket.on('resumeProducer', async ({ producer_id, type }, callback) => {
|
||||||
if (!roomExists(socket)) return;
|
if (!roomExists(socket)) return;
|
||||||
|
|
||||||
const peer = getPeer(socket);
|
const peer = getPeer(socket);
|
||||||
|
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
return callback({
|
return callback({
|
||||||
error: `peer with ID: "${socket.id}" for producer with id "${producer_id}" not found`,
|
error: `peer with ID: "${socket.id}" for producer with id "${producer_id}" type "${type}" not found`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const producer = peer.getProducer(producer_id);
|
const producer = peer.getProducer(producer_id);
|
||||||
|
|
||||||
if (!producer) {
|
if (!producer) {
|
||||||
return callback({ error: `producer with id "${producer_id}" not found` });
|
return callback({ error: `producer with id "${producer_id}" type "${type}" not found` });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -1763,7 +1764,7 @@ function startServer() {
|
|||||||
|
|
||||||
const { peer_name } = peer || 'undefined';
|
const { peer_name } = peer || 'undefined';
|
||||||
|
|
||||||
log.debug('Producer resumed', { peer_name: peer_name, producer_id: producer_id });
|
log.debug('Producer resumed', { peer_name, producer_id, type });
|
||||||
|
|
||||||
callback('successfully');
|
callback('successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1771,21 +1772,21 @@ function startServer() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('resumeConsumer', async ({ consumer_id }, callback) => {
|
socket.on('resumeConsumer', async ({ consumer_id, type }, callback) => {
|
||||||
if (!roomExists(socket)) return;
|
if (!roomExists(socket)) return;
|
||||||
|
|
||||||
const peer = getPeer(socket);
|
const peer = getPeer(socket);
|
||||||
|
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
return callback({
|
return callback({
|
||||||
error: `peer with ID: "${socket.id}" for consumer with id "${consumer_id}" not found`,
|
error: `peer with ID: "${socket.id}" for consumer with id "${consumer_id}" type "${type}" not found`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const consumer = peer.getConsumer(consumer_id);
|
const consumer = peer.getConsumer(consumer_id);
|
||||||
|
|
||||||
if (!consumer) {
|
if (!consumer) {
|
||||||
return callback({ error: `consumer with id "${consumer_id}" not found` });
|
return callback({ error: `consumer with id "${consumer_id}" type "${type}" not found` });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -1793,7 +1794,7 @@ function startServer() {
|
|||||||
|
|
||||||
const { peer_name } = peer || 'undefined';
|
const { peer_name } = peer || 'undefined';
|
||||||
|
|
||||||
log.debug('Consumer resumed', { peer_name: peer_name, consumer_id: consumer_id });
|
log.debug('Consumer resumed', { peer_name, consumer_id, type });
|
||||||
|
|
||||||
callback('successfully');
|
callback('successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mirotalksfu",
|
"name": "mirotalksfu",
|
||||||
"version": "1.6.63",
|
"version": "1.6.64",
|
||||||
"description": "WebRTC SFU browser-based video calls",
|
"description": "WebRTC SFU browser-based video calls",
|
||||||
"main": "Server.js",
|
"main": "Server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ if (location.href.substr(0, 5) !== 'https') location.href = 'https' + location.h
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.6.63
|
* @version 1.6.64
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -4618,7 +4618,7 @@ function showAbout() {
|
|||||||
imageUrl: image.about,
|
imageUrl: image.about,
|
||||||
customClass: { image: 'img-about' },
|
customClass: { image: 'img-about' },
|
||||||
position: 'center',
|
position: 'center',
|
||||||
title: 'WebRTC SFU v1.6.63',
|
title: 'WebRTC SFU v1.6.64',
|
||||||
html: `
|
html: `
|
||||||
<br />
|
<br />
|
||||||
<div id="about">
|
<div id="about">
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.6.63
|
* @version 1.6.64
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -2051,7 +2051,7 @@ class RoomClient {
|
|||||||
this.producers.get(producer_id).pause();
|
this.producers.get(producer_id).pause();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.socket.request('pauseProducer', { producer_id: producer_id });
|
const response = await this.socket.request('pauseProducer', { producer_id, type });
|
||||||
console.log('Producer paused', response);
|
console.log('Producer paused', response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error pausing producer', error);
|
console.error('Error pausing producer', error);
|
||||||
@@ -2082,7 +2082,7 @@ class RoomClient {
|
|||||||
this.producers.get(producer_id).resume();
|
this.producers.get(producer_id).resume();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.socket.request('resumeProducer', { producer_id: producer_id });
|
const response = await this.socket.request('resumeProducer', { producer_id, type });
|
||||||
console.log('Producer resumed', response);
|
console.log('Producer resumed', response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error resuming producer', error);
|
console.error('Error resuming producer', error);
|
||||||
@@ -2286,9 +2286,10 @@ class RoomClient {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
data = await this.socket.request('consume', {
|
data = await this.socket.request('consume', {
|
||||||
rtpCapabilities,
|
|
||||||
consumerTransportId: this.consumerTransport.id,
|
consumerTransportId: this.consumerTransport.id,
|
||||||
|
rtpCapabilities,
|
||||||
producerId,
|
producerId,
|
||||||
|
type,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم