feross / simple-peer

📡 Simple WebRTC video, voice, and data channels
MIT License
7.46k stars 977 forks source link

creation of new SimplePeer with stream option on node.js #219

Closed B-R-Bender closed 6 years ago

B-R-Bender commented 6 years ago

Hi!

I've run into an issue with creating simple peer on node server. I'm trying to implemet WerRTC video/audio streaming between clients browser and node server (server as peer). When I'm getting offer from client I'm creating a peer. As I suppose. I can pass stream only in SimplePeer constructor.

.post('/', function (req, res, next) {
    var stream = fs.createReadStream("media/demo.mp4");
    serverPeer = new SimplePeer({wrtc: wrtc, trickle: false, stream: stream});
    // serverPeer = new SimplePeer({wrtc: wrtc, trickle: false});
    serverPeer.signal(req.body);
    serverPeer.on('signal', function (data) {
        res.send(data);
    });
});

So when I'm trying to do this I'v got an error: self._pc.addStream is not a function

in debugger it looks like this: debug screanshot

Could you please help me with this? Any suggestions, workarounds?

Thank you!

t-mullen commented 6 years ago

No Node.js WebRTC implementations support MediaStreams, so you can't use video/audio with Node.js, only data channels.

You could launch a headless browser though. https://github.com/GoogleChrome/puppeteer

Or you could record the audio/video and upload it to the server as a file: https://github.com/muaz-khan/RecordRTC

B-R-Bender commented 6 years ago

Thanks, @RationalCoding Your suggestion is to instatiate headless chrome on server for each connection, and use it as a peer for client browser, am I right?

What if I send media stream data via peer.send()?

t-mullen commented 6 years ago

One headless Chrome instance with multiple peers in it.

You could send video data over the datachannel, but where would you get it? Node doesn't have getUserMedia or any way to construct media streams, so you'd have to manually create webm streams with the right format for MediaSource. Probably a lot more trouble than it's worth.

If you want to only receive video/audio on the Node side and not send, you can use media-record-stream and media-source-stream with the data channels (search npm).