Lib-jitsi-meet API (low level) example of screensharing

I am trying to create a GUI using the lib-jitsi-meet API (low level). I want to create a button that, when pressed, shares a pre-determined window (my Jitsi application window itself) to others in the conference.

Does anyone know of some example code that shows how to implement a screensharing button using the lib-jitsi-meet API (low level) that I can reference?

I looked through the Developer Guide but it is still not clear to me how to do this.

Check out my repository with a working demo

1 Like

This worked for me. Thanks so much!

async function screenShare() {
    try {
        var newScreenshareTrack = await JitsiMeetJS.createLocalTracks({
            devices: ['desktop']
        });
        await room.removeTrack(localTracks[1]);
        localTracks = [];
        screenTracks = newScreenshareTrack;

        await room.addTrack(screenTracks[0]);
        screenTracks[0].attach($(`#video-track-local`)[0]);
    } catch (error) {
        console.log('error starting screenshare: ' + error);
    }
}

async function stopScreenShare() {
    try {
        var newLocalTracks = await JitsiMeetJS.createLocalTracks({
            devices: ['video'],
        });

        await room.removeTrack(screenTracks[0]);

        screenTracks = [];
        localTracks = newLocalTracks;

        await room.addTrack(localTrack[0]);
        localTracks[0].attach($(`#video-track-local`)[0]);
    } catch (error) {
        console.log('error in stopping screenshare: ' + error);
    }
};
1 Like

Glad to help. I have done some other changes as well. Please check.