webrtc-client

A light wrapper around the WebRTC API.

webrtc-client

A light wrapper around the WebRTC API. For an example server implementation see webrtc-handler.

var webrtc = require('webrtc-client')
 
getUserMedia({ audio: true, video: true }, function (stream) {
  var video = document.querySelector('video')
 
  var url = 'ws://localhost:8000'
  var client = webrtc({ url: url, stream: stream })
  client.on('stream add', function (remoteid) {
    video.src = window.URL.createObjectURL(remote);
  })
  client.on('stream remove', function (remoteid) {
    video.src = null
  })
  client.connect()
})

Methods

var webrtc = require('webrtc-client')

Returns a webrtc-client instance.

Websocket url of the signalling server.

Local stream to be sent to connected peers.

Log messages to the console.

Create a connection to the signalling server using the url given when the client was created. The client will connect to peers advertised by the server through the peers event.

The supplied obj will be sent to the signalling server with a join message. This could contain application specific information for the server such as the room to join.

Close connection to the signalling server and any connected peers.

Events

Fires when a new stream is received. cb takes two arguments:

  • stream - The remote stream received.
  • id - The id of the associated peer.

Fires when a stream is removed. cb takes two arguments:

  • stream - The remote stream removed.
  • id - The id of the associated peer.