Reputation: 948
I'm trying to create a webcam video-stream trough my node.js server with the help of socket.io and socket.io-stream.
I want to capture the video in /camera, open a stream trough socket.io (with the help of socket.io-stream) with the video, and receive it on the index url.
When I connect to the server trough /camera, and thus initiate the stream, the server crashes with the error "RangeError: Maximum call stack size exceeded".
The error seems to coming from "/node_modules/socket.io/node_modules/has-binary/index.js:48:23".
In the examples, I left out most of the arbitrary code, as the server/connection is working fine for transferring data-snippits.
Here is my current setup:
Server:
io.on('connection', function(socket) {
ioStream(socket).on('videoStream', function(stream, data) {
socket.broadcast.emit('videoStream', stream);
});
});
Camera
window.glob_socket = io();
var video = document.getElementById('camera');
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({
audio: false,
video: {
width: 320,
height: 240
}
}, function(videoStream) {
// Local preview
video.src = window.URL.createObjectURL(videoStream);
video.onloadedmetadata = function(e) {
video.play();
};
// Stream
var stream = ss.createStream();
ss(glob_socket).emit('videoStream', stream, videoStream);
fs.createReadStream(videoStream).pipe(stream);
}, function(err) {
console.log("The following error occurred: " + err.name);
});
} else {
console.log("getUserMedia not supported");
}
Index
var video = document.getElementById('camera');
ss(glob_socket).on('videoStream', function(stream) {
video.src = window.URL.createObjectURL(stream);
video.onloadedmetadata = function(e) {
video.play();
};
});
I'm unable to test the code on the server/index as the server crashes when the camera initiates the stream.
Anyone has an idea what's wrong here?
Upvotes: 2
Views: 643
Reputation: 23297
Unfortunately, you can't do that. socket.io-stream library only deals with static files, but not with live video streams.
To share video stream you should use WebRTC. There are a couple of libraries that may help you get started:
Worth noting that WebRTC won't transfer video through your server (in most cases). It does more - it transfers video stream from one peer to another directly, which is good for your server's bandwidth. But there might be problems when peers are behind symmetric NAT. In this case video stream should be transfered through a TURN server.
More information about WebRTC you can find here.
Upvotes: 2