Reputation: 119
I need to send a MediaStream from a electron desktop Capture to a Live HTML5 Video tag using express. The problem is that a I can't create a fs.createReadStream from a Media Stream. I do not think I need to use WEB-RTC for this. Code is below
app.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')
});
})
Upvotes: 2
Views: 3190
Reputation: 17305
If you want it to be "live" you need to implement WebRTC on your server.
If a delay is acceptable, the MediaStreamRecorder API shown in https://webrtc.github.io/samples/src/content/getusermedia/record/ might solve the problem. You can send chunks of data in the ondataavailable handler.
Upvotes: 2