Meeting SDK Type and Version
Latest SDK Version
Description
When I am trying to share my screen, I am getting a dialog:
No share source content
However, no error when joined from browser.
Electron Code:
main.js
const { app, BrowserWindow, Menu, dialog, session, desktopCapturer, ipcMain } = require('electron');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
backgroundThrottling: false,
contextIsolation: true,
enableRemoteModule: true,
preload: `${__dirname}/preload.js`,
devTools: false // Disable background throttling
}
});
// Clear cache and load the URL
session.defaultSession.clearCache().then(() => {
console.log('Cache cleared');
mainWindow.loadURL('https://mywebsite.com');
});
// Ensure the page is fully loaded
mainWindow.webContents.on('did-finish-load', () => {
console.log('Page loaded');
});
mainWindow.on('close', (e) => {
// Prevent the window from closing immediately
e.preventDefault();
// Show a confirmation dialog
const choice = dialog.showMessageBoxSync(mainWindow, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: 'Are you sure you want to quit?'
});
// If the user clicks 'Yes', allow the app to close
if (choice === 0) {
app.exit(); // Close the app
}
});
// Add a small delay to handle redirects
mainWindow.webContents.on('did-navigate', () => {
setTimeout(() => {
console.log('Redirecting to next page...');
}, 2000); // Adjust the delay as necessary
});
//Menu.setApplicationMenu(null);
// Disable keyboard shortcuts for Developer Tools (Ctrl+Shift+I or F12)
mainWindow.webContents.on('before-input-event', (event, input) => {
if (input.key === 'F12' || (input.control && input.shift && input.key === 'I')) {
event.preventDefault(); // Disable DevTools shortcuts
}
});
ipcMain.handle('get-sources', async (event) => {
const sources = await desktopCapturer.getSources({ types: ['window', 'screen'] });
return sources;
});
// Open dev tools for debugging (remove this for production)
// mainWindow.webContents.openDevTools();
}
app.whenReady().then(() => {
session.defaultSession.setDisplayMediaRequestHandler((request, callback) => {
desktopCapturer.getSources({ types: ['screen'] })
.then((sources) => {
console.log("MONSTER: " + sources[0].name);
callback({ video: sources[0] });
})
.catch((error) => { // Changed from error() to catch()
console.log("ERROR: " + error);
});
});
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
preload.js
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
getSources: () => ipcRenderer.invoke('get-sources'),
});
Am I missing anything?
Note: console does not show anything.