Skip to content

Instantly share code, notes, and snippets.

@saghul
Last active August 24, 2024 04:29
Show Gist options
  • Save saghul/179feba3df9f12ddf316decd0181b03e to your computer and use it in GitHub Desktop.
Save saghul/179feba3df9f12ddf316decd0181b03e to your computer and use it in GitHub Desktop.
Streaming a webcam to a Jitsi Meet room
const puppeteer = require('puppeteer');
// Streams the first webcam in the system to the specified Jitsi Meet room. Audio is currently
// not sent, but it can be easily enabled by disabling the corresponding setting in `meetArgs`.
//
// TODO
// - Detect if we are kicked from the room
// - Support authenticated deployments
//
// NOTE: only tested on GNU/Linux.
async function main(room, baseUrl='https://meet.jit.si') {
const chromeArgs = [
// Disable sandboxing, gives an error on Linux
'--no-sandbox',
'--disable-setuid-sandbox',
// Automatically give permission to use media devices
'--use-fake-ui-for-media-stream',
// Silence all output, just in case
'--alsa-output-device=plug:null'
];
const meetArgs = [
// Disable receiving of video
'config.channelLastN=0',
// Mute our audio
'config.startWithAudioMuted=true',
// Don't use simulcast to save resources on the sender (our) side
'config.disableSimulcast=true',
// No need to process audio levels
'config.disableAudioLevels=true',
// Disable P2P mode due to a bug in Jitsi Meet
'config.p2p.enabled=false'
];
const url = `${baseUrl}/${room}#${meetArgs.join('&')}`;
console.log(`Loading ${url}`);
const browser = await puppeteer.launch({ args: chromeArgs, handleSIGINT: false });
const page = await browser.newPage();
// Manual handling on SIGINT to gracefully hangup and exit
process.on('SIGINT', async () => {
console.log('Exiting...');
await page.evaluate('APP.conference.hangup();');
await page.close();
browser.close();
console.log('Done!');
process.exit();
});
await page.goto(url);
// Set some friendly display name
await page.evaluate('APP.conference._room.setDisplayName("Streamer");');
console.log('Running...');
}
main(process.argv[2] || 'test123');
@saghul
Copy link
Author

saghul commented May 4, 2021

Nice!

@MartijnHols
Copy link

Current version needs the following as part of the meetArgs in order to actually connect:

    // Skip the prejoin page - join the conference immediately
    'config.prejoinPageEnabled=false',

@alexivaner
Copy link

alexivaner commented Sep 27, 2023

    async isOnlyParticipant() {
        try {
            const members = await this.page.evaluate('APP.conference.membersCount;');


            console.log('Number of participants: %o', members);

            // Check if there is only one member (yourself)
            return members.length === 1;
        } catch (error) {
            console.error('Error checking the number of participants:', error);
            throw error;
        }
    }

Hi everyone, do you know why I always get this error in my puppeteer when executing the above code? Thanks

Error checking the number of participants: 91 |         name = detail.name;
92 |         message = detail.message;
93 |     }
94 |     const messageHeight = message.split('\n').length;
95 |     const error = new Error(message);
96 |     error.name = name;
                     ^
TypeError: Cannot read properties of undefined (reading 'getParticipants')
      at /Users/ivanhutomo/Documents/GitHub/quickConference/node_modules/puppeteer-core/lib/esm/puppeteer/common/util.js:96:17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment