Widget ID: screen-share. API: documented below. Needs a connection to another participant: see widgets that need a connection.
Purpose
Adds a button to the control panel tray that starts and stops sharing your screen. The button is highlighted while your screen is shared. Sites that do not enable this widget have no screen-sharing button.
API
interface ScreenShareApi {
start(): Promise<void>; // the browser asks which screen; rejects if cancelled
stop(): Promise<void>; // does nothing when not sharing
isSharing(): boolean;
subscribe(listener: (sharing: boolean) => void): () => void; // called right away, then on every change
}Available while the widget is enabled for your site, even when nothing is open. The button in the tray and the API control the same sharing, so subscribe also reports sharing started from the button.
Example: your own share button
const weei = await window.weeiReady;
const screen = weei.widgetsApi.get('screen-share');
const button = document.querySelector('#share');
if (!screen) button.hidden = true; // not enabled for this site
else {
screen.subscribe(sharing => (button.textContent = sharing ? 'Stop sharing' : 'Share screen'));
button.onclick = () => (screen.isSharing() ? screen.stop() : screen.start()).catch(() => {});
}Good to know
- Watching a screen someone else shares needs no widget. Without the widget your page can still share with
media.setScreenSharing(), which also gives you the streams. - Screen sharing needs HTTPS and a desktop browser that supports it; elsewhere the button is disabled and
start()rejects.