Explorar el Código

desktopcapturer

cocktailpeanut hace 1 semana
padre
commit
ca7df2c26f
Se han modificado 2 ficheros con 23 adiciones y 6 borrados
  1. 21 4
      full.js
  2. 2 2
      package.json

+ 21 - 4
full.js

@@ -1,4 +1,4 @@
-const {app, screen, shell, BrowserWindow, BrowserView, ipcMain, dialog, clipboard, session } = require('electron')
+const {app, screen, shell, BrowserWindow, BrowserView, ipcMain, dialog, clipboard, session, desktopCapturer } = require('electron')
 const windowStateKeeper = require('electron-window-state');
 const fs = require('fs')
 const path = require("path")
@@ -546,10 +546,11 @@ if (!gotTheLock) {
   })
 
   // Create mainWindow, load the rest of the app, etc...
+  // Enable desktop capture for getDisplayMedia support (must be before app ready)
+  app.commandLine.appendSwitch('enable-experimental-web-platform-features');
+  app.commandLine.appendSwitch('enable-features', 'GetDisplayMediaSet,GetDisplayMediaSetAutoSelectAllScreens');
+  
   app.whenReady().then(async () => {
-    // Enable desktop capture for getDisplayMedia support
-    app.commandLine.appendSwitch('enable-experimental-web-platform-features');
-    app.commandLine.appendSwitch('enable-features', 'ScreenCaptureKit');
 
     // PROMPT
     let promptResponse
@@ -658,6 +659,22 @@ document.querySelector("form").addEventListener("submit", (e) => {
       console.log(`[PERMISSION DEBUG] Permission check for: "${permission}"`)
       return permission === 'media' || permission === 'display-capture' || permission === 'desktopCapture'
     })
+    
+    // Handle getDisplayMedia requests to make web API work
+    session.defaultSession.setDisplayMediaRequestHandler((request, callback) => {
+      console.log('[DISPLAY MEDIA DEBUG] Display media request received')
+      desktopCapturer.getSources({ types: ['screen', 'window'] }).then((sources) => {
+        console.log('[DISPLAY MEDIA DEBUG] Available sources:', sources.length)
+        if (sources.length > 0) {
+          callback({ video: sources[0], audio: 'loopback' })
+        } else {
+          callback({})
+        }
+      }).catch(err => {
+        console.error('[DISPLAY MEDIA DEBUG] Error getting sources:', err)
+        callback({})
+      })
+    })
 
     app.on('web-contents-created', attach)
     app.on('activate', function () {

+ 2 - 2
package.json

@@ -1,7 +1,7 @@
 {
   "name": "Pinokio",
   "private": true,
-  "version": "3.47.0",
+  "version": "3.48.0",
   "homepage": "https://pinokio.co",
   "description": "pinokio",
   "main": "main.js",
@@ -119,7 +119,7 @@
     "electron-store": "^8.1.0",
     "electron-updater": "^6.6.2",
     "electron-window-state": "^5.0.3",
-    "pinokiod": "^3.47.0"
+    "pinokiod": "^3.48.0"
   },
   "devDependencies": {
     "@electron/rebuild": "3.2.10",