From 91413fbd965573a00a3b7529a2867962080b13e4 Mon Sep 17 00:00:00 2001 From: Hristo Terezov Date: Wed, 24 Nov 2021 11:13:34 -0600 Subject: [PATCH] feat(load-test): Unmute video. --- resources/load-test/load-test-participant.js | 44 ++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/resources/load-test/load-test-participant.js b/resources/load-test/load-test-participant.js index 22c51a89f..ac740e8dd 100644 --- a/resources/load-test/load-test-participant.js +++ b/resources/load-test/load-test-participant.js @@ -340,6 +340,49 @@ function onUserLeft(id) { } } +/** + * Handles private messages. + * + * @param {string} id - The sender ID. + * @param {string} text - The message. + * @returns {void} + */ +function onPrivateMessage(id, text) { + switch(text) { + case 'video on': + onVideoOnMessage(); + break; + } +} + +/** + * Handles 'video on' private messages. + * + * @returns {void} + */ +function onVideoOnMessage() { + console.debug('Turning my video on!'); + + const localVideoTrack = room.getLocalVideoTrack(); + + if (localVideoTrack && localVideoTrack.isMuted()) { + console.debug('Unmuting existing video track.'); + localVideoTrack.unmute(); + } else if (!localVideoTrack) { + JitsiMeetJS.createLocalTracks({ devices: [ 'video' ] }) + .then(([ videoTrack ]) => videoTrack) + .catch(console.error) + .then(videoTrack => { + return room.replaceTrack(null, videoTrack); + }) + .then(() => { + console.debug('Successfully added a new video track for unmute.'); + }); + } else { + console.log('No-op! We are already video unmuted!'); + } +} + /** * That function is called when connection is established successfully */ @@ -351,6 +394,7 @@ function onConnectionSuccess() { room.on(JitsiMeetJS.events.conference.CONNECTION_ESTABLISHED, onConnectionEstablished); room.on(JitsiMeetJS.events.conference.USER_JOINED, onUserJoined); room.on(JitsiMeetJS.events.conference.USER_LEFT, onUserLeft); + room.on(JitsiMeetJS.events.conference.PRIVATE_MESSAGE_RECEIVED, onPrivateMessage); if (stageView) { room.on(JitsiMeetJS.events.conference.DOMINANT_SPEAKER_CHANGED, onDominantSpeakerChanged); }