我需要使用 express 将 MediaStream 从电子桌面 Capture 发送到 Live HTML5 Video 标签。问题是我无法从媒体流创建 fs.createReadStream。我认为我不需要为此使用 WEB-RTC。代码如下
应用程序.js
var fs = require('fs');
var path = require('path');
var express = require('express');
var app = express();
const {desktopCapturer} = require('electron');
function getDesktop(callback) {
desktopCapturer.getSources({types: ['window', 'screen']},
function(error, sources) {
if (error) return callback(error)
navigator.mediaDevices.getUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sources[0].id,
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,
maxHeight: 720
}
}
}).then(function(stream) {
return callback(null,stream)
video.onloadedmetadata = (e) => video.play()
}).catch(function(e) {
return callback(e);
})
})
}
getDesktop(function(err,stream) {
app.get('/',function(req,res) {
return res.sendFile(path.join(__dirname + '/client/client.html'))
});
app.get('/video',function(req,res) {
///Send LIVE data to HTML5 Video Tag
});
app.listen(80,function() {
console.log('Streaming')
});
})