0.1.1 • Published 4 years ago

socket-webrtc v0.1.1

Weekly downloads
3
License
GPL-3.0
Repository
github
Last release
4 years ago

Socket-WebRTC

WebRTC + Sockets for a lovely P2P

Warning: under heavy development, this will go kaboom 💥

  • Peer roles
  • Rooms support
  • Server-side network configuration and security
  • P2P stream support

Getting started

The following example connects multiple peers and sends a video stream

const io = require('socket.io')(httpServer); // Here goes your express or http server

const {SocketWebRTCRoom} = require('socket-webrtc');

const socketWebRTCRoom = new SocketWebRTCRoom(io);

socketWebRTCRoom.on('connection', (peerCandidate) => {
    socketWebRTCRoom.registerPeer(peerCandidate);
});


httpServer.listen(3000);

server.js

const stream = await navigator.mediaDevices.getUserMedia({
    audio: false
});

const socketWebRTCClient = new SocketWebRTCClient();

socketWebRTCClient.connect();
socketWebRTCClient.on('peer-connected', (peer) => {
    console.log("Peer connected");
    peer.stream(stream); // Send stream to connected peer
    peer.on('stream', (peerStream) => {
      // attach remote stream to html video
    });
});

client.js

Check examples folder for more working examples

Roles

Rooms

STUN and TURN

Coturn

0.1.1

4 years ago

0.1.0

4 years ago