I am trying to add a deskop track as a new track and not to replace the current track. According to threads like this, Cannot add second audio track, possible before - #2 by damencho, there is suppose to be the ability to add multiple tracks. Here is my code.
function addDesktop() {
window.JitsiMeetJS.createLocalTracks({
devices: ['desktop'],
resolution: 1080
}).then(async (screenTracks) => {
var screenVideoTrack = screenTracks.filter(track => track.getType() === 'video')[0];
await onRemoteTrack(screenVideoTrack);
if (screenVideoTrack) {
await room.addTrack(screenVideoTrack);
let i = localVideoTrackIndex +1;
screenVideoTrack.attach($(`#localVideo${i}`)[0]);
localVideoTrack = screenVideoTrack;
}
}).catch(error => {
alert("There was an error sharing your video feed.");
console.error(error);
});
}
The problem is I get this error:
webrtc_class.js:3220 Error: Cannot add second video track to the conference
And the error occurs at line:
await room.addTrack(screenVideoTrack);
And ideas to what I am doing wrong?
Going through the code of addTrack, is the currently impossible?
JitsiConference.prototype.addTrack = function(track) {
const mediaType = track.getType();
const localTracks = this.rtc.getLocalTracks(mediaType);
// Ensure there's exactly 1 local track of each media type in the conference.
if (localTracks.length > 0) {
// Don't be excessively harsh and severe if the API client happens to attempt to add the same local track twice.
if (track === localTracks[0]) {
return Promise.resolve(track);
}
// Currently, only adding multiple video streams of different video types is supported.
// TODO - remove this limitation once issues with jitsi-meet trying to add multiple camera streams is fixed.
if (FeatureFlags.isMultiStreamSendSupportEnabled()
&& mediaType === MediaType.VIDEO
&& !localTracks.find(t => t.getVideoType() === track.getVideoType())) {
const sourceName = getSourceNameForJitsiTrack(
this.myUserId(),
mediaType,
this.getLocalTracks(mediaType)?.length);
track.setSourceName(sourceName);
const addTrackPromises = [];
this.p2pJingleSession && addTrackPromises.push(this.p2pJingleSession.addTracks([ track ]));
this.jvbJingleSession && addTrackPromises.push(this.jvbJingleSession.addTracks([ track ]));
return Promise.all(addTrackPromises)
.then(() => {
this._setupNewTrack(track);
this._sendBridgeVideoTypeMessage(track);
this._updateRoomPresence(this.getActiveMediaSession());
if (this.isMutedByFocus || this.isVideoMutedByFocus) {
this._fireMuteChangeEvent(track);
}
});
}
return Promise.reject(new Error(`Cannot add second ${mediaType} track to the conference`));
}
Namely this line:
&& !localTracks.find(t => t.getVideoType() === track.getVideoType()))