Skip to content

Commit

Permalink
[mirotalksfu] - #171 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Nov 3, 2024
1 parent 2e2a69e commit e03f269
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
6 changes: 6 additions & 0 deletions app/src/Peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = class Peer {
peer_name,
peer_presenter,
peer_audio,
peer_audio_volume,
peer_video,
peer_video_privacy,
peer_recording,
Expand All @@ -25,6 +26,7 @@ module.exports = class Peer {
this.peer_presenter = peer_presenter;
this.peer_audio = peer_audio;
this.peer_video = peer_video;
this.peer_audio_volume = peer_audio_volume;
this.peer_video_privacy = peer_video_privacy;
this.peer_recording = peer_recording;
this.peer_hand = peer_hand;
Expand Down Expand Up @@ -75,6 +77,10 @@ module.exports = class Peer {
this.peer_info.peer_recording = data.status;
this.peer_recording = data.status;
break;
case 'peerAudio':
this.peer_info.peer_audio_volume = data.volume;
this.peer_audio_volume = data.volume;
break;
default:
break;
}
Expand Down
9 changes: 8 additions & 1 deletion app/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1788,16 +1788,23 @@ function startServer() {

const room = getRoom(socket);

const peer = getPeer(socket);

switch (data.type) {
case 'privacy':
const peer = room.getPeer(socket.id);
peer.updatePeerInfo({ type: data.type, status: data.active });
break;
case 'ejectAll':
const { peer_name, peer_uuid } = data;
const isPresenter = await isPeerPresenter(socket.room_id, socket.id, peer_name, peer_uuid);
if (!isPresenter) return;
break;
case 'peerAudio':
// Keep producer volume to update consumer on join room...
if (data.audioProducerId) {
peer.updatePeerInfo({ type: data.type, volume: data.volume * 100 });
}
break;
default:
break;
//...
Expand Down
1 change: 1 addition & 0 deletions public/js/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ function getPeerInfo() {
peer_token: peer_token,
peer_presenter: isPresenter,
peer_audio: isAudioAllowed,
peer_audio_volume: 100,
peer_video: isVideoAllowed,
peer_screen: isScreenAllowed,
peer_recording: isRecording,
Expand Down
56 changes: 43 additions & 13 deletions public/js/RoomClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,17 +604,20 @@ class RoomClient {
for (let peer of Array.from(peers.keys()).filter((id) => id !== this.peer_id)) {
let peer_info = peers.get(peer).peer_info;
// console.log('07.1 ----> Remote Peer info', peer_info);
const canSetVideoOff = !isBroadcastingEnabled || (isBroadcastingEnabled && peer_info.peer_presenter);

if (!peer_info.peer_video && canSetVideoOff) {
console.log('Detected peer video off ' + peer_info.peer_name);
const { peer_id, peer_name, peer_presenter, peer_video, peer_recording } = peer_info;

const canSetVideoOff = !isBroadcastingEnabled || (isBroadcastingEnabled && peer_presenter);

if (!peer_video && canSetVideoOff) {
console.log('Detected peer video off ' + peer_name);
this.setVideoOff(peer_info, true);
}

if (peer_info.peer_recording) {
if (peer_recording) {
this.handleRecordingAction({
peer_id: peer_info.id,
peer_name: peer_info.peer_name,
peer_id: peer_id,
peer_name: peer_name,
action: enums.recording.started,
});
}
Expand Down Expand Up @@ -2281,9 +2284,24 @@ class RoomClient {
const remotePeerId = peer_info.peer_id;
const remoteIsScreen = type == mediaType.screen;
const remotePeerAudio = peer_info.peer_audio;
const remotePeerAudioVolume = peer_info.peer_audio_volume;
const remotePrivacyOn = peer_info.peer_video_privacy;
const remotePeerPresenter = peer_info.peer_presenter;

// Helper function to handle audio volume setup
const setAudioVolume = (audioElementId, volumeElementId, volumeValue) => {
const volumeInput = this.getId(volumeElementId);
const audioPlayer = this.getId(audioElementId);
const volume = volumeValue / 100;

if (volumeInput && audioPlayer) {
console.log('Setting audio volume:', volumeValue);
volumeInput.value = volumeValue;
volumeInput.disabled = volumeValue < 100;
this.setAudioVolume(audioPlayer, volume);
}
};

switch (type) {
case mediaType.video:
case mediaType.screen:
Expand Down Expand Up @@ -2455,7 +2473,15 @@ class RoomClient {
this.setTippy(ko.id, 'Eject', 'bottom');
}

// Use helper function to set audio volume
setAudioVolume(
this.audioConsumers.get(remotePeerId + '___pVolume'),
remotePeerId + '___pVolume',
remotePeerAudioVolume,
);

this.setPeerAudio(remotePeerId, remotePeerAudio);

handleAspectRatio();
this.sound('joined');
break;
Expand All @@ -2466,14 +2492,15 @@ class RoomClient {
elem.audio = 1.0;
this.remoteAudioEl.appendChild(elem);
await this.attachMediaStream(elem, stream, type, 'Consumer');
let audioConsumerId = remotePeerId + '___pVolume';

// Store audio consumer and set volume
const audioConsumerId = remotePeerId + '___pVolume';
this.audioConsumers.set(audioConsumerId, id);
let inputPv = this.getId(audioConsumerId);

if (inputPv) {
this.handleCV(id + '___' + audioConsumerId);
this.setPeerAudio(remotePeerId, remotePeerAudio);
}
// Use helper function to set audio volume
setAudioVolume(id, audioConsumerId, remotePeerAudioVolume);

this.setPeerAudio(remotePeerId, remotePeerAudio);

if (sinkId && speakerSelect.value) {
this.changeAudioDestination(elem);
Expand Down Expand Up @@ -2937,7 +2964,7 @@ class RoomClient {

setIsAudio(peer_id, status) {
if (!isBroadcastingEnabled || (isBroadcastingEnabled && isPresenter)) {
console.log('Set audio enabled: ' + status);
console.log('Set local audio enabled: ' + status);
this.peer_info.peer_audio = status;
const audioStatus = this.getPeerAudioBtn(peer_id); // producer, consumers
if (audioStatus) audioStatus.className = status ? html.audioOn : html.audioOff;
Expand Down Expand Up @@ -6901,6 +6928,9 @@ class RoomClient {
const volume = inputElement.value / 100;
this.setAudioVolume(audioPlayer, volume);

// Update producer audio volume
if (!isConsumer) this.peer_info.peer_audio_volume = inputElement.value;

// Clear any existing timeout to prevent sending too frequently
if (volumeUpdateTimeout) {
clearTimeout(volumeUpdateTimeout);
Expand Down

0 comments on commit e03f269

Please sign in to comment.