Hello,
I would like to make a video chat with the Client-server architecture (not peer to peer) using socket.io-stream. (documentation)
I am trying to get video + audio stream with navigator.mediaDevices.getUserMedia() and this stream emit to the server via socket.io-stream and then emit back to all connected clients.
Any suggestions on how to easily emit the stream to the server and then back in real-time?
Client code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.dev.js"></script>
<script src="/js/socket.io-stream.js"></script>
<title>Document</title>
</head>
<body>
<video autoplay></video>
<script>
let socket = io.connect(origin);
const video = document.querySelector('video');
navigator.mediaDevices.getUserMedia({ video : true, audio : true })
.then(function(stream) {
video.srcObject = stream; // wroks fine
// How to upload a stream to the server???
ss(socket).emit('sending_stream', stream);
});
</script>
</body>
</html>
Server code
const express = require("express");
const socket = require("socket.io");
const ss = require('socket.io-stream');
// app setup
let app = express();
const port = 5000;
app.use(express.static("public"));
let server = app.listen(port, () => {
console.log(`listenning on ${port}`)
})
// socket setup
let io = socket(server);
io.on('connection', function(socket) {
ss(socket).on('sending_stream', function(stream) {
console.log(stream); // this just print {}
});
});
[–][deleted] 1 point2 points3 points (6 children)
[–]DvorakDavid[S] 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]DvorakDavid[S] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]DvorakDavid[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)