[mirotalksfu] - UI enhancemetns - minor bug fix
هذا الالتزام موجود في:
@@ -27,6 +27,7 @@
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
box-shadow: 0px 12px 22px rgba(0, 0, 0, 0.4);
|
box-shadow: 0px 12px 22px rgba(0, 0, 0, 0.4);
|
||||||
animation: show 0.4s ease;
|
animation: show 0.4s ease;
|
||||||
}
|
}
|
||||||
@@ -61,6 +62,33 @@
|
|||||||
background: rgba(0, 0, 0, 0.4);
|
background: rgba(0, 0, 0, 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#videoMediaContainer button {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
color: white;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin: 5px;
|
||||||
|
width: auto;
|
||||||
|
height: 25px;
|
||||||
|
border-radius: 5px;
|
||||||
|
background: rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#videoMediaContainer img {
|
||||||
|
position: absolute;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
width: 250px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#videoMediaContainer video {
|
||||||
|
position: absolute;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
video {
|
video {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@@ -398,8 +398,6 @@ function joinRoom(peer_name, room_id) {
|
|||||||
peer_info,
|
peer_info,
|
||||||
isAudioAllowed,
|
isAudioAllowed,
|
||||||
isVideoAllowed,
|
isVideoAllowed,
|
||||||
isAudioOn,
|
|
||||||
isVideoOn,
|
|
||||||
roomIsReady,
|
roomIsReady,
|
||||||
);
|
);
|
||||||
handleRoomClientEvents();
|
handleRoomClientEvents();
|
||||||
@@ -589,10 +587,12 @@ function handleButtons() {
|
|||||||
};
|
};
|
||||||
startAudioButton.onclick = () => {
|
startAudioButton.onclick = () => {
|
||||||
rc.produce(RoomClient.mediaType.audio, microphoneSelect.value);
|
rc.produce(RoomClient.mediaType.audio, microphoneSelect.value);
|
||||||
|
rc.updatePeerInfo(peer_name, rc.peer_id, 'audio', true);
|
||||||
// rc.resumeProducer(RoomClient.mediaType.audio);
|
// rc.resumeProducer(RoomClient.mediaType.audio);
|
||||||
};
|
};
|
||||||
stopAudioButton.onclick = () => {
|
stopAudioButton.onclick = () => {
|
||||||
rc.closeProducer(RoomClient.mediaType.audio);
|
rc.closeProducer(RoomClient.mediaType.audio);
|
||||||
|
rc.updatePeerInfo(peer_name, rc.peer_id, 'audio', false);
|
||||||
// rc.pauseProducer(RoomClient.mediaType.audio);
|
// rc.pauseProducer(RoomClient.mediaType.audio);
|
||||||
};
|
};
|
||||||
startVideoButton.onclick = () => {
|
startVideoButton.onclick = () => {
|
||||||
@@ -1178,7 +1178,7 @@ function wbCanvasSaveImg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wbCanvasToJson() {
|
function wbCanvasToJson() {
|
||||||
if (rc.thereIsConsumers()) {
|
if (rc.thereIsParticipants()) {
|
||||||
let wbCanvasJson = JSON.stringify(wbCanvas.toJSON());
|
let wbCanvasJson = JSON.stringify(wbCanvas.toJSON());
|
||||||
rc.socket.emit('wbCanvasToJson', wbCanvasJson);
|
rc.socket.emit('wbCanvasToJson', wbCanvasJson);
|
||||||
}
|
}
|
||||||
@@ -1200,7 +1200,7 @@ function getWhiteboardAction(action) {
|
|||||||
|
|
||||||
function whiteboardAction(data, emit = true) {
|
function whiteboardAction(data, emit = true) {
|
||||||
if (emit) {
|
if (emit) {
|
||||||
if (rc.thereIsConsumers()) {
|
if (rc.thereIsParticipants()) {
|
||||||
rc.socket.emit('whiteboardAction', data);
|
rc.socket.emit('whiteboardAction', data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1300,10 +1300,10 @@ async function getParticipantsTable(peers) {
|
|||||||
table += `
|
table += `
|
||||||
<tr id='${peer_id}'>
|
<tr id='${peer_id}'>
|
||||||
<td>${peer_name}</td>
|
<td>${peer_name}</td>
|
||||||
<td><button id='${peer_id}__audio' onclick="rc.peerAction('me',this.id,'mute')">${peer_audio}</button></td>
|
<td><button id='${peer_id}___pAudio' onclick="rc.peerAction('me',this.id,'mute')">${peer_audio}</button></td>
|
||||||
<td><button id='${peer_id}__video' onclick="rc.peerAction('me',this.id,'hide')">${peer_video}</button></td>
|
<td><button id='${peer_id}___pVideo' onclick="rc.peerAction('me',this.id,'hide')">${peer_video}</button></td>
|
||||||
<td><button>${peer_hand}</button></td>
|
<td><button>${peer_hand}</button></td>
|
||||||
<td><button id='${peer_id}__eject' onclick="rc.peerAction('me',this.id,'eject')">${peer_eject}</button></td>
|
<td><button id='${peer_id}___pEject' onclick="rc.peerAction('me',this.id,'eject')">${peer_eject}</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ const cfg = {
|
|||||||
|
|
||||||
const html = {
|
const html = {
|
||||||
newline: '<br />',
|
newline: '<br />',
|
||||||
|
audioOn: 'fas fa-microphone',
|
||||||
|
audioOff: 'fas fa-microphone-slash',
|
||||||
|
videoOn: 'fas fa-video',
|
||||||
|
videoOff: 'fas fa-video-slash',
|
||||||
};
|
};
|
||||||
|
|
||||||
const image = {
|
const image = {
|
||||||
@@ -62,8 +66,6 @@ class RoomClient {
|
|||||||
peer_info,
|
peer_info,
|
||||||
isAudioAllowed,
|
isAudioAllowed,
|
||||||
isVideoAllowed,
|
isVideoAllowed,
|
||||||
isAudioOn,
|
|
||||||
isVideoOn,
|
|
||||||
successCallback,
|
successCallback,
|
||||||
) {
|
) {
|
||||||
this.remoteAudioEl = remoteAudioEl;
|
this.remoteAudioEl = remoteAudioEl;
|
||||||
@@ -79,8 +81,6 @@ class RoomClient {
|
|||||||
|
|
||||||
this.isAudioAllowed = isAudioAllowed;
|
this.isAudioAllowed = isAudioAllowed;
|
||||||
this.isVideoAllowed = isVideoAllowed;
|
this.isVideoAllowed = isVideoAllowed;
|
||||||
this.isAudioOn = isAudioOn;
|
|
||||||
this.isVideoOn = isVideoOn;
|
|
||||||
this.producerTransport = null;
|
this.producerTransport = null;
|
||||||
this.consumerTransport = null;
|
this.consumerTransport = null;
|
||||||
this.device = null;
|
this.device = null;
|
||||||
@@ -117,7 +117,7 @@ class RoomClient {
|
|||||||
this.chunkSize = 1024 * 16; // 16kb/s
|
this.chunkSize = 1024 * 16; // 16kb/s
|
||||||
|
|
||||||
this.myVideoEl = null;
|
this.myVideoEl = null;
|
||||||
this.connectedRoom = null;
|
this.room_info = null;
|
||||||
this.debug = false;
|
this.debug = false;
|
||||||
|
|
||||||
this.consumers = new Map();
|
this.consumers = new Map();
|
||||||
@@ -187,8 +187,9 @@ class RoomClient {
|
|||||||
this.roomIsLocked();
|
this.roomIsLocked();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.connectedRoom = room;
|
this.room_info = room;
|
||||||
console.log('07 ----> Joined to room', this.connectedRoom);
|
console.log('07 ----> Joined to room', this.room_info);
|
||||||
|
await this.handleRoomInfo(this.room_info);
|
||||||
const data = await this.socket.request('getRouterRtpCapabilities');
|
const data = await this.socket.request('getRouterRtpCapabilities');
|
||||||
this.device = await this.loadDevice(data);
|
this.device = await this.loadDevice(data);
|
||||||
console.log('08 ----> Get Router Rtp Capabilities codecs: ', this.device.rtpCapabilities.codecs);
|
console.log('08 ----> Get Router Rtp Capabilities codecs: ', this.device.rtpCapabilities.codecs);
|
||||||
@@ -202,6 +203,19 @@ class RoomClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleRoomInfo(room_info) {
|
||||||
|
let peers = new Map(JSON.parse(room_info.peers));
|
||||||
|
participantsCount = peers.size;
|
||||||
|
for (let peer of Array.from(peers.keys()).filter((id) => id !== this.peer_id)) {
|
||||||
|
let peer_info = peers.get(peer).peer_info;
|
||||||
|
console.log('|| ----> Remote Peer info', peer_info);
|
||||||
|
if (!peer_info.peer_video) {
|
||||||
|
await this.setVideoOff(peer_info, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.refreshParticipantsCount();
|
||||||
|
}
|
||||||
|
|
||||||
async loadDevice(routerRtpCapabilities) {
|
async loadDevice(routerRtpCapabilities) {
|
||||||
let device;
|
let device;
|
||||||
try {
|
try {
|
||||||
@@ -360,6 +374,31 @@ class RoomClient {
|
|||||||
}.bind(this),
|
}.bind(this),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.socket.on(
|
||||||
|
'setVideoOff',
|
||||||
|
function (data) {
|
||||||
|
console.log('Video off:', data);
|
||||||
|
this.setVideoOff(data, true);
|
||||||
|
}.bind(this),
|
||||||
|
);
|
||||||
|
|
||||||
|
this.socket.on(
|
||||||
|
'removeMe',
|
||||||
|
function (data) {
|
||||||
|
console.log('Remove me:', data);
|
||||||
|
this.removeVideoOff(data.peer_id);
|
||||||
|
participantsCount = data.peer_counts;
|
||||||
|
}.bind(this),
|
||||||
|
);
|
||||||
|
|
||||||
|
this.socket.on(
|
||||||
|
'refreshParticipantsCount',
|
||||||
|
function (data) {
|
||||||
|
console.log('Participants Count:', data);
|
||||||
|
participantsCount = data.peer_counts;
|
||||||
|
}.bind(this),
|
||||||
|
);
|
||||||
|
|
||||||
this.socket.on(
|
this.socket.on(
|
||||||
'newProducers',
|
'newProducers',
|
||||||
async function (data) {
|
async function (data) {
|
||||||
@@ -455,14 +494,19 @@ class RoomClient {
|
|||||||
// ####################################################
|
// ####################################################
|
||||||
|
|
||||||
startLocalMedia() {
|
startLocalMedia() {
|
||||||
if (this.isAudioAllowed && this.isAudioOn) {
|
if (this.isAudioAllowed && this.peer_info.peer_audio) {
|
||||||
console.log('09 ----> Start audio media');
|
console.log('09 ----> Start audio media');
|
||||||
this.produce(mediaType.audio, microphoneSelect.value);
|
this.produce(mediaType.audio, microphoneSelect.value);
|
||||||
}
|
}
|
||||||
if (this.isVideoAllowed && this.isVideoOn) {
|
if (this.isVideoAllowed && this.peer_info.peer_video) {
|
||||||
console.log('10 ----> Start video media');
|
console.log('10 ----> Start video media');
|
||||||
this.produce(mediaType.video, videoSelect.value);
|
this.produce(mediaType.video, videoSelect.value);
|
||||||
}
|
}
|
||||||
|
if (!this.peer_info.peer_video) {
|
||||||
|
console.log('10 ----> Video is off');
|
||||||
|
this.setVideoOff(this.peer_info, false);
|
||||||
|
this.sendVideoOff();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ####################################################
|
// ####################################################
|
||||||
@@ -567,12 +611,15 @@ class RoomClient {
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case mediaType.audio:
|
case mediaType.audio:
|
||||||
|
this.setIsAudio(this.peer_id, true);
|
||||||
this.event(_EVENTS.startAudio);
|
this.event(_EVENTS.startAudio);
|
||||||
break;
|
break;
|
||||||
case mediaType.video:
|
case mediaType.video:
|
||||||
|
this.setIsVideo(true);
|
||||||
this.event(_EVENTS.startVideo);
|
this.event(_EVENTS.startVideo);
|
||||||
break;
|
break;
|
||||||
case mediaType.screen:
|
case mediaType.screen:
|
||||||
|
this.setIsScreen(true);
|
||||||
this.event(_EVENTS.startScreen);
|
this.event(_EVENTS.startScreen);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -664,7 +711,8 @@ class RoomClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleProducer(id, type, stream) {
|
async handleProducer(id, type, stream) {
|
||||||
let elem, d, p, i;
|
let elem, d, p, i, b;
|
||||||
|
this.removeVideoOff(this.peer_id);
|
||||||
d = document.createElement('div');
|
d = document.createElement('div');
|
||||||
d.className = 'Camera';
|
d.className = 'Camera';
|
||||||
d.id = id + '__d';
|
d.id = id + '__d';
|
||||||
@@ -678,11 +726,15 @@ class RoomClient {
|
|||||||
p.id = this.peer_id + '__name';
|
p.id = this.peer_id + '__name';
|
||||||
p.innerHTML = '👤 ' + this.peer_name + ' (me)';
|
p.innerHTML = '👤 ' + this.peer_name + ' (me)';
|
||||||
i = document.createElement('i');
|
i = document.createElement('i');
|
||||||
i.id = this.peer_id + '__peerHand';
|
i.id = this.peer_id + '__hand';
|
||||||
i.className = 'fas fa-hand-paper pulsate';
|
i.className = 'fas fa-hand-paper pulsate';
|
||||||
|
b = document.createElement('button');
|
||||||
|
b.id = this.peer_id + '__audio';
|
||||||
|
b.className = this.peer_info.peer_audio ? html.audioOn : html.audioOff;
|
||||||
d.appendChild(elem);
|
d.appendChild(elem);
|
||||||
d.appendChild(p);
|
|
||||||
d.appendChild(i);
|
d.appendChild(i);
|
||||||
|
d.appendChild(p);
|
||||||
|
d.appendChild(b);
|
||||||
this.videoMediaContainer.appendChild(d);
|
this.videoMediaContainer.appendChild(d);
|
||||||
this.attachMediaStream(elem, stream, type, 'Producer');
|
this.attachMediaStream(elem, stream, type, 'Producer');
|
||||||
this.myVideoEl = elem;
|
this.myVideoEl = elem;
|
||||||
@@ -778,12 +830,15 @@ class RoomClient {
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case mediaType.audio:
|
case mediaType.audio:
|
||||||
|
this.setIsAudio(this.peer_id, false);
|
||||||
this.event(_EVENTS.stopAudio);
|
this.event(_EVENTS.stopAudio);
|
||||||
break;
|
break;
|
||||||
case mediaType.video:
|
case mediaType.video:
|
||||||
|
this.setIsVideo(false);
|
||||||
this.event(_EVENTS.stopVideo);
|
this.event(_EVENTS.stopVideo);
|
||||||
break;
|
break;
|
||||||
case mediaType.screen:
|
case mediaType.screen:
|
||||||
|
this.setIsScreen(false);
|
||||||
this.event(_EVENTS.stopScreen);
|
this.event(_EVENTS.stopScreen);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -852,9 +907,10 @@ class RoomClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleConsumer(id, type, stream, peer_name, peer_info) {
|
handleConsumer(id, type, stream, peer_name, peer_info) {
|
||||||
let elem, d, p, i;
|
let elem, d, p, i, b;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case mediaType.video:
|
case mediaType.video:
|
||||||
|
this.removeVideoOff(peer_info.peer_id);
|
||||||
d = document.createElement('div');
|
d = document.createElement('div');
|
||||||
d.className = 'Camera';
|
d.className = 'Camera';
|
||||||
d.id = id + '__d';
|
d.id = id + '__d';
|
||||||
@@ -868,11 +924,15 @@ class RoomClient {
|
|||||||
p.id = peer_info.peer_id + '__name';
|
p.id = peer_info.peer_id + '__name';
|
||||||
p.innerHTML = '👤 ' + peer_name;
|
p.innerHTML = '👤 ' + peer_name;
|
||||||
i = document.createElement('i');
|
i = document.createElement('i');
|
||||||
i.id = peer_info.peer_id + '__peerHand';
|
i.id = peer_info.peer_id + '__hand';
|
||||||
i.className = 'fas fa-hand-paper pulsate';
|
i.className = 'fas fa-hand-paper pulsate';
|
||||||
|
b = document.createElement('button');
|
||||||
|
b.id = peer_info.peer_id + '__audio';
|
||||||
|
b.className = peer_info.peer_audio ? html.audioOn : html.audioOff;
|
||||||
d.appendChild(elem);
|
d.appendChild(elem);
|
||||||
d.appendChild(p);
|
d.appendChild(p);
|
||||||
d.appendChild(i);
|
d.appendChild(i);
|
||||||
|
d.appendChild(b);
|
||||||
this.videoMediaContainer.appendChild(d);
|
this.videoMediaContainer.appendChild(d);
|
||||||
this.attachMediaStream(elem, stream, type, 'Consumer');
|
this.attachMediaStream(elem, stream, type, 'Consumer');
|
||||||
this.handleFS(elem.id);
|
this.handleFS(elem.id);
|
||||||
@@ -894,6 +954,8 @@ class RoomClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeConsumer(consumer_id) {
|
removeConsumer(consumer_id) {
|
||||||
|
console.log('Remove consumer_id:', consumer_id);
|
||||||
|
|
||||||
let elem = this.getId(consumer_id);
|
let elem = this.getId(consumer_id);
|
||||||
let d = this.getId(consumer_id + '__d');
|
let d = this.getId(consumer_id + '__d');
|
||||||
|
|
||||||
@@ -910,6 +972,45 @@ class RoomClient {
|
|||||||
this.sound('left');
|
this.sound('left');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ####################################################
|
||||||
|
// HANDLE VIDEO OFF
|
||||||
|
// ####################################################
|
||||||
|
|
||||||
|
async setVideoOff(peer_info, remotePeer = false) {
|
||||||
|
let d, i, b, p;
|
||||||
|
let peer_id = peer_info.peer_id;
|
||||||
|
let peer_name = peer_info.peer_name;
|
||||||
|
let peer_audio = peer_info.peer_audio;
|
||||||
|
d = document.createElement('div');
|
||||||
|
d.className = 'Camera';
|
||||||
|
d.id = peer_id + '__videoOff';
|
||||||
|
i = document.createElement('img');
|
||||||
|
i.className = 'center pulsate';
|
||||||
|
i.id = peer_id + '__img';
|
||||||
|
p = document.createElement('p');
|
||||||
|
p.id = peer_id + '__name';
|
||||||
|
p.innerHTML = '👤 ' + peer_name + (remotePeer ? '' : ' (me) ');
|
||||||
|
b = document.createElement('button');
|
||||||
|
b.id = peer_id + '__audio';
|
||||||
|
b.className = peer_audio ? html.audioOn : html.audioOff;
|
||||||
|
d.appendChild(i);
|
||||||
|
d.appendChild(p);
|
||||||
|
d.appendChild(b);
|
||||||
|
this.videoMediaContainer.appendChild(d);
|
||||||
|
this.setVideoAvatarImgName(i.id, peer_name);
|
||||||
|
this.getId(i.id).style.display = 'block';
|
||||||
|
resizeVideoMedia();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeVideoOff(peer_id) {
|
||||||
|
let pvOff = this.getId(peer_id + '__videoOff');
|
||||||
|
if (pvOff) {
|
||||||
|
pvOff.parentNode.removeChild(pvOff);
|
||||||
|
resizeVideoMedia();
|
||||||
|
this.sound('left');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ####################################################
|
// ####################################################
|
||||||
// EXIT ROOM
|
// EXIT ROOM
|
||||||
// ####################################################
|
// ####################################################
|
||||||
@@ -1005,6 +1106,37 @@ class RoomClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setVideoAvatarImgName(elemId, peer_name) {
|
||||||
|
let elem = this.getId(elemId);
|
||||||
|
let avatarImgSize = 250;
|
||||||
|
elem.setAttribute(
|
||||||
|
'src',
|
||||||
|
cfg.msgAvatar + '?name=' + peer_name + '&size=' + avatarImgSize + '&background=random&rounded=true',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsAudio(peer_id, status) {
|
||||||
|
this.peer_info.peer_audio = status;
|
||||||
|
let b = this.getPeerAudioBtn(peer_id);
|
||||||
|
if (b) b.className = this.peer_info.peer_audio ? html.audioOn : html.audioOff;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsVideo(status) {
|
||||||
|
this.peer_info.peer_video = status;
|
||||||
|
if (!this.peer_info.peer_video) {
|
||||||
|
this.setVideoOff(this.peer_info, false);
|
||||||
|
this.sendVideoOff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsScreen(status) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendVideoOff() {
|
||||||
|
this.socket.emit('setVideoOff', this.peer_info);
|
||||||
|
}
|
||||||
|
|
||||||
// ####################################################
|
// ####################################################
|
||||||
// GET
|
// GET
|
||||||
// ####################################################
|
// ####################################################
|
||||||
@@ -1038,6 +1170,18 @@ class RoomClient {
|
|||||||
return room_info;
|
return room_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshParticipantsCount() {
|
||||||
|
this.socket.emit('refreshParticipantsCount');
|
||||||
|
}
|
||||||
|
|
||||||
|
getPeerAudioBtn(peer_id) {
|
||||||
|
return this.getId(peer_id + '__audio');
|
||||||
|
}
|
||||||
|
|
||||||
|
getPeerHandBtn(peer_id) {
|
||||||
|
return this.getId(peer_id + '__hand');
|
||||||
|
}
|
||||||
|
|
||||||
// ####################################################
|
// ####################################################
|
||||||
// UTILITY
|
// UTILITY
|
||||||
// ####################################################
|
// ####################################################
|
||||||
@@ -1074,8 +1218,8 @@ class RoomClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
thereIsConsumers() {
|
thereIsParticipants() {
|
||||||
if (this.consumers.size > 0) {
|
if (this.consumers.size > 0 || participantsCount > 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -1202,7 +1346,7 @@ class RoomClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage() {
|
sendMessage() {
|
||||||
if (!this.thereIsConsumers()) {
|
if (!this.thereIsParticipants()) {
|
||||||
chatMessage.value = '';
|
chatMessage.value = '';
|
||||||
this.userLog('info', 'No participants in the room', 'top-end');
|
this.userLog('info', 'No participants in the room', 'top-end');
|
||||||
return;
|
return;
|
||||||
@@ -1495,7 +1639,7 @@ class RoomClient {
|
|||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
this.fileToSend = result.value;
|
this.fileToSend = result.value;
|
||||||
if (this.fileToSend && this.fileToSend.size > 0) {
|
if (this.fileToSend && this.fileToSend.size > 0) {
|
||||||
if (!this.thereIsConsumers()) {
|
if (!this.thereIsParticipants()) {
|
||||||
userLog('info', 'No participants detected', 'top-end');
|
userLog('info', 'No participants detected', 'top-end');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1761,27 +1905,28 @@ class RoomClient {
|
|||||||
|
|
||||||
peerAction(from_peer_name, id, action, emit = true, broadcast = false) {
|
peerAction(from_peer_name, id, action, emit = true, broadcast = false) {
|
||||||
let peer_id = id;
|
let peer_id = id;
|
||||||
|
|
||||||
if (emit) {
|
if (emit) {
|
||||||
if (!broadcast) {
|
if (!broadcast) {
|
||||||
if (participantsCount === 1) return;
|
if (participantsCount === 1) return;
|
||||||
|
|
||||||
const words = peer_id.split('__');
|
const words = peer_id.split('___');
|
||||||
peer_id = words[0];
|
peer_id = words[0];
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'eject':
|
case 'eject':
|
||||||
let peer = this.getId(peer_id);
|
let peer = this.getId(peer_id);
|
||||||
if (peer) peer.parentNode.removeChild(peer);
|
if (peer) {
|
||||||
participantsCount--;
|
peer.parentNode.removeChild(peer);
|
||||||
refreshParticipantsCount(participantsCount);
|
participantsCount--;
|
||||||
|
refreshParticipantsCount(participantsCount);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'mute':
|
case 'mute':
|
||||||
let peerAudioButton = this.getId(peer_id + '__audio');
|
let peerAudioButton = this.getId(peer_id + '___pAudio');
|
||||||
if (peerAudioButton) peerAudioButton.innerHTML = _PEER.audioOff;
|
if (peerAudioButton) peerAudioButton.innerHTML = _PEER.audioOff;
|
||||||
break;
|
break;
|
||||||
case 'hide':
|
case 'hide':
|
||||||
let peerVideoButton = this.getId(peer_id + '__video');
|
let peerVideoButton = this.getId(peer_id + '___pVideo');
|
||||||
if (peerVideoButton) peerVideoButton.innerHTML = _PEER.videoOff;
|
if (peerVideoButton) peerVideoButton.innerHTML = _PEER.videoOff;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1845,6 +1990,7 @@ class RoomClient {
|
|||||||
case 'mute':
|
case 'mute':
|
||||||
if (peer_id === this.peer_id || broadcast) {
|
if (peer_id === this.peer_id || broadcast) {
|
||||||
this.closeProducer(mediaType.audio);
|
this.closeProducer(mediaType.audio);
|
||||||
|
this.updatePeerInfo(this.peer_name, this.peer_id, 'audio', false);
|
||||||
this.userLog(
|
this.userLog(
|
||||||
'warning',
|
'warning',
|
||||||
from_peer_name + ' ' + _PEER.audioOff + ' has closed yours audio',
|
from_peer_name + ' ' + _PEER.audioOff + ' has closed yours audio',
|
||||||
@@ -1877,14 +2023,14 @@ class RoomClient {
|
|||||||
if (emit) {
|
if (emit) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'audio':
|
case 'audio':
|
||||||
this.peer_info.peer_audio = status;
|
this.setIsAudio(peer_id, status);
|
||||||
break;
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
this.peer_info.peer_video = status;
|
this.setIsVideo(status);
|
||||||
break;
|
break;
|
||||||
case 'hand':
|
case 'hand':
|
||||||
this.peer_info.peer_hand = status;
|
this.peer_info.peer_hand = status;
|
||||||
let peer_hand = this.getId(peer_id + '__peerHand');
|
let peer_hand = this.getPeerHandBtn(peer_id);
|
||||||
if (status) {
|
if (status) {
|
||||||
if (peer_hand) peer_hand.style.display = 'flex';
|
if (peer_hand) peer_hand.style.display = 'flex';
|
||||||
this.event(_EVENTS.raiseHand);
|
this.event(_EVENTS.raiseHand);
|
||||||
@@ -1905,11 +2051,13 @@ class RoomClient {
|
|||||||
} else {
|
} else {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'audio':
|
case 'audio':
|
||||||
|
this.setIsAudio(peer_id, status);
|
||||||
break;
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
|
this.setIsVideo(status);
|
||||||
break;
|
break;
|
||||||
case 'hand':
|
case 'hand':
|
||||||
let peer_hand = this.getId(peer_id + '__peerHand');
|
let peer_hand = this.getPeerHandBtn(peer_id);
|
||||||
if (status) {
|
if (status) {
|
||||||
if (peer_hand) peer_hand.style.display = 'flex';
|
if (peer_hand) peer_hand.style.display = 'flex';
|
||||||
this.userLog(
|
this.userLog(
|
||||||
@@ -1931,7 +2079,7 @@ class RoomClient {
|
|||||||
let peer_id = peer_info.peer_id;
|
let peer_id = peer_info.peer_id;
|
||||||
let peer_hand_status = peer_info.peer_hand;
|
let peer_hand_status = peer_info.peer_hand;
|
||||||
if (peer_hand_status) {
|
if (peer_hand_status) {
|
||||||
let peer_hand = this.getId(peer_id + '__peerHand');
|
let peer_hand = this.getPeerHandBtn(peer_id);
|
||||||
if (peer_hand) peer_hand.style.display = 'flex';
|
if (peer_hand) peer_hand.style.display = 'flex';
|
||||||
}
|
}
|
||||||
//...
|
//...
|
||||||
|
|||||||
@@ -216,6 +216,12 @@ module.exports = class Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendToAll(action, data) {
|
||||||
|
for (let peer_id of Array.from(this.peers.keys())) {
|
||||||
|
this.send(peer_id, action, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
send(socket_id, action, data) {
|
send(socket_id, action, data) {
|
||||||
this.io.to(socket_id).emit(action, data);
|
this.io.to(socket_id).emit(action, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,6 +276,11 @@ io.on('connection', (socket) => {
|
|||||||
roomList.get(socket.room_id).broadCast(socket.id, 'whiteboardAction', data);
|
roomList.get(socket.room_id).broadCast(socket.id, 'whiteboardAction', data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('setVideoOff', (data) => {
|
||||||
|
log.debug('Video off', getPeerName());
|
||||||
|
roomList.get(socket.room_id).broadCast(socket.id, 'setVideoOff', data);
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('join', (data, cb) => {
|
socket.on('join', (data, cb) => {
|
||||||
if (!roomList.has(socket.room_id)) {
|
if (!roomList.has(socket.room_id)) {
|
||||||
return cb({
|
return cb({
|
||||||
@@ -331,9 +336,9 @@ io.on('connection', (socket) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('connectTransport', async ({ transport_id, dtlsParameters }, callback) => {
|
socket.on('connectTransport', async ({ transport_id, dtlsParameters }, callback) => {
|
||||||
|
if (!roomList.has(socket.room_id)) return;
|
||||||
log.debug('Connect transport', getPeerName());
|
log.debug('Connect transport', getPeerName());
|
||||||
|
|
||||||
if (!roomList.has(socket.room_id)) return;
|
|
||||||
await roomList.get(socket.room_id).connectPeerTransport(socket.id, transport_id, dtlsParameters);
|
await roomList.get(socket.room_id).connectPeerTransport(socket.id, transport_id, dtlsParameters);
|
||||||
|
|
||||||
callback('success');
|
callback('success');
|
||||||
@@ -401,8 +406,17 @@ io.on('connection', (socket) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('getRoomInfo', (_, cb) => {
|
socket.on('getRoomInfo', (_, cb) => {
|
||||||
cb(roomList.get(socket.room_id).toJson());
|
|
||||||
log.debug('Send Room Info');
|
log.debug('Send Room Info');
|
||||||
|
cb(roomList.get(socket.room_id).toJson());
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('refreshParticipantsCount', () => {
|
||||||
|
let data = {
|
||||||
|
room_id: socket.room_id,
|
||||||
|
peer_counts: roomList.get(socket.room_id).getPeers().size,
|
||||||
|
};
|
||||||
|
log.debug('Refresh Participants count', data);
|
||||||
|
roomList.get(socket.room_id).sendToAll('refreshParticipantsCount', data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('message', (data) => {
|
socket.on('message', (data) => {
|
||||||
@@ -423,6 +437,8 @@ io.on('connection', (socket) => {
|
|||||||
if (roomList.get(socket.room_id).getPeers().size === 0 && roomList.get(socket.room_id).isLocked()) {
|
if (roomList.get(socket.room_id).getPeers().size === 0 && roomList.get(socket.room_id).isLocked()) {
|
||||||
roomList.get(socket.room_id).setLocked(false);
|
roomList.get(socket.room_id).setLocked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
roomList.get(socket.room_id).broadCast(socket.id, 'removeMe', removeMeData());
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('exitRoom', async (_, callback) => {
|
socket.on('exitRoom', async (_, callback) => {
|
||||||
@@ -440,6 +456,8 @@ io.on('connection', (socket) => {
|
|||||||
roomList.delete(socket.room_id);
|
roomList.delete(socket.room_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
roomList.get(socket.room_id).broadCast(socket.id, 'removeMe', removeMeData());
|
||||||
|
|
||||||
socket.room_id = null;
|
socket.room_id = null;
|
||||||
|
|
||||||
callback('Successfully exited room');
|
callback('Successfully exited room');
|
||||||
@@ -459,6 +477,14 @@ io.on('connection', (socket) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeMeData() {
|
||||||
|
return {
|
||||||
|
room_id: socket.room_id,
|
||||||
|
peer_id: socket.id,
|
||||||
|
peer_counts: roomList.get(socket.room_id).getPeers().size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function bytesToSize(bytes) {
|
function bytesToSize(bytes) {
|
||||||
let sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
let sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||||
if (bytes == 0) return '0 Byte';
|
if (bytes == 0) return '0 Byte';
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم