Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js desktopCapturer示例。。。如何使其适用于特定的应用程序_Node.js_Electron - Fatal编程技术网

Node.js desktopCapturer示例。。。如何使其适用于特定的应用程序

Node.js desktopCapturer示例。。。如何使其适用于特定的应用程序,node.js,electron,Node.js,Electron,我将尝试遵循本教程: 教程的第一部分做得很好。。。我可以从我的pc摄像头和麦克风播放av。。。进入我的电子应用程序。但现在我正在尝试通过desktopCapturer对象从运行在windows桌面上的特定应用程序流式传输音频和视频 问题 我没有收到任何错误。但electron应用程序的视频html标签并没有显示myappthatstreamsAV的流 代码 我更改了index.html代码,如下所示:(只是更改了标记中的内容) 到目前为止我所尝试的: 我添加了一些调试语句,如下所示: cons

我将尝试遵循本教程:

教程的第一部分做得很好。。。我可以从我的pc摄像头和麦克风播放av。。。进入我的电子应用程序。但现在我正在尝试通过desktopCapturer对象从运行在windows桌面上的特定应用程序流式传输音频和视频

问题

我没有收到任何错误。但electron应用程序的视频html标签并没有显示myappthatstreamsAV的流

代码

我更改了index.html代码,如下所示:(只是更改了标记中的内容)

到目前为止我所尝试的:

我添加了一些调试语句,如下所示:

const {app, BrowserWindow} = require('electron')
const url = require('url')
const path = require('path')

let win

// Set the path where recordings will be saved
app.setPath("userData", __dirname + "/saved_recordings")

function createWindow() {
   win = new BrowserWindow({width: 800, height: 600,
      webPreferences: {
         nodeIntegration: true
     }
   })
   win.loadURL(url.format({
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file:',
      slashes: true
   }))
}

app.on('ready', createWindow)
  <script type = "text/javascript">
     var desktopCapturer = require('electron').desktopCapturer;
     console.log("1")
     console.log(desktopCapturer)
     desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
        console.log("2")
        if (error) throw error
        for (let i = 0; i < sources.length; ++i) {
           console.log((sources[i].name));
           console.log("3")
     var desktopCapturer = require('electron').desktopCapturer;
     console.log("are you here?")
     console.log(desktopCapturer)

     desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => {
        for (const source of sources) {
           if (source.name === 'mystreamApp') {
              try {
              const stream = await navigator.mediaDevices.getUserMedia({
                 audio: true,
                 video: {
                    mandatory: {
                    chromeMediaSource: 'desktop',
                    chromeMediaSourceId: source.id,
                    minWidth: 1280,
                    maxWidth: 1280,
                    minHeight: 720,
                    maxHeight: 720
                    }
                 }
              })
              handleStream(stream)
              } catch (e) {
              handleError(e)
              }
              return
           }
        }
        })

        function handleStream (stream) {
        const video = document.querySelector('video')
        video.srcObject = stream
        video.onloadedmetadata = (e) => video.play()
        }

        function handleError (e) {
        console.log(e)
        }

它永远不会达到2或3。

将我的代码更改为如下所示:

const {app, BrowserWindow} = require('electron')
const url = require('url')
const path = require('path')

let win

// Set the path where recordings will be saved
app.setPath("userData", __dirname + "/saved_recordings")

function createWindow() {
   win = new BrowserWindow({width: 800, height: 600,
      webPreferences: {
         nodeIntegration: true
     }
   })
   win.loadURL(url.format({
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file:',
      slashes: true
   }))
}

app.on('ready', createWindow)
  <script type = "text/javascript">
     var desktopCapturer = require('electron').desktopCapturer;
     console.log("1")
     console.log(desktopCapturer)
     desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
        console.log("2")
        if (error) throw error
        for (let i = 0; i < sources.length; ++i) {
           console.log((sources[i].name));
           console.log("3")
     var desktopCapturer = require('electron').desktopCapturer;
     console.log("are you here?")
     console.log(desktopCapturer)

     desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => {
        for (const source of sources) {
           if (source.name === 'mystreamApp') {
              try {
              const stream = await navigator.mediaDevices.getUserMedia({
                 audio: true,
                 video: {
                    mandatory: {
                    chromeMediaSource: 'desktop',
                    chromeMediaSourceId: source.id,
                    minWidth: 1280,
                    maxWidth: 1280,
                    minHeight: 720,
                    maxHeight: 720
                    }
                 }
              })
              handleStream(stream)
              } catch (e) {
              handleError(e)
              }
              return
           }
        }
        })

        function handleStream (stream) {
        const video = document.querySelector('video')
        video.srcObject = stream
        video.onloadedmetadata = (e) => video.play()
        }

        function handleError (e) {
        console.log(e)
        }
现在我看到了视频流。
音频仍不工作。但我会就此提出另一个问题。

将我的代码更改为如下:

const {app, BrowserWindow} = require('electron')
const url = require('url')
const path = require('path')

let win

// Set the path where recordings will be saved
app.setPath("userData", __dirname + "/saved_recordings")

function createWindow() {
   win = new BrowserWindow({width: 800, height: 600,
      webPreferences: {
         nodeIntegration: true
     }
   })
   win.loadURL(url.format({
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file:',
      slashes: true
   }))
}

app.on('ready', createWindow)
  <script type = "text/javascript">
     var desktopCapturer = require('electron').desktopCapturer;
     console.log("1")
     console.log(desktopCapturer)
     desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
        console.log("2")
        if (error) throw error
        for (let i = 0; i < sources.length; ++i) {
           console.log((sources[i].name));
           console.log("3")
     var desktopCapturer = require('electron').desktopCapturer;
     console.log("are you here?")
     console.log(desktopCapturer)

     desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => {
        for (const source of sources) {
           if (source.name === 'mystreamApp') {
              try {
              const stream = await navigator.mediaDevices.getUserMedia({
                 audio: true,
                 video: {
                    mandatory: {
                    chromeMediaSource: 'desktop',
                    chromeMediaSourceId: source.id,
                    minWidth: 1280,
                    maxWidth: 1280,
                    minHeight: 720,
                    maxHeight: 720
                    }
                 }
              })
              handleStream(stream)
              } catch (e) {
              handleError(e)
              }
              return
           }
        }
        })

        function handleStream (stream) {
        const video = document.querySelector('video')
        video.srcObject = stream
        video.onloadedmetadata = (e) => video.play()
        }

        function handleError (e) {
        console.log(e)
        }
现在我看到了视频流。
音频仍不工作。但我会就此提出另一个问题。

这是否回答了你的问题@是的。这允许我定义变量。但是现在代码不起作用了。我的电子应用程序中没有出现任何流。没有错误。将更新问题此选项是否回答您的问题@是的。这允许我定义变量。但是现在代码不起作用了。我的电子应用程序中没有出现任何流。没有错误。将更新问题