Skip to content

ferborva/webrtc-int

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Web Streams Simplified Interface

Goals:

  • Obtain list of available inputs
  • Obtain list of supported video and audio constraints
  • Get User media
  • Detect custom screenshare extension
  • Request screenshare extension
  • ES6 Syntax
  • Travis CI

API

The following API enpoints are available:

Documentation

Each of the following sections explains the mode of use of each of the functions and objects made available in the module.

To start using the module clone the repo into your node_modules folder:

npm install git+https://github.com/ferborva/webrtc-int.git --save

Then require/import it into your front-end project:

eg. import WebStreams from 'webrtc-int';

For the module to work you will need to leverage a build system which makes use of Babel (ES6 to compatibile syntax) and Browserify/Webpack or one alike.

Good examples of ready to use development systems are the EmberCLI and Meteor Project. Indeed there are many more that can be used.

Note:

The module offers API endpoints which use either Promise based results or Task objects to the user in order to offer a greater flexibility in the use. Notice that the Task versions are objects where as the Promise versions are functions that have to be invoked before they are managed.

List Devices

listDevices:: Task - Enumerate all devices avaible

Type: Task

WebStreams.listDevices
         .fork(error => {
            // Handle error
          }, results => {
            // Handle Array of results
          })
listDevicesP:: Promise - Enumerate all devices avaible

Type: Function

Return: Promise

WebStreams.listDevicesP()
         .then(results => {
            // Handle Array of results
          }, error => {
            // Handle error
          })
listInputDevices:: Task - Enumerate all Input devices avaible

Type: Task

WebStreams.listInputDevices
         .fork(error => {
            // Handle error
          }, results => {
            // Handle Array of results
          })
listInputDevicesP:: Promise - Enumerate all Input devices avaible

Type: Function

Return: Promise

WebStreams.listInputDevicesP()
         .then(results => {
            // Handle Array of results
          }, error => {
            // Handle error
          })

List Device possible Error messages. These apply to the above calls:

  • Get User Media not supported
  • Enumerate devices not supported
  • InternalError on enumerateDevices API

List Media Constraints

listSupportedConstraints:: Enumerate all media constraints supported by the browser

Type: Function

Return: Array

const results = WebStreams.listSupportedConstraints()

Get Screen Share MediaStream

checkExtension:: Task - Check for the Screen Share extension availability

Type: Task (Predicate)

WebStreams.checkExtension
         .fork(error => {
            // Handle error
          }, ok => {
            // Handle ok
          })
checkExtensionP:: Promise - Check for the Screen Share extension availability

Type: Function

Return: Promise (Predicate)

WebStreams.checkExtensionP()
         .then(ok => {
            // Handle ok
          }, error => {
            // Handle error
          })
getScreen:: Task - Enumerate all devices avaible

Type: Task

WebStreams.getScreen
         .fork(error => {
            // Handle error
          }, result => {
            // Handle MediaStream result
          })
getScreenP:: Promise - Enumerate all devices avaible

Type: Function

Return: Promise

WebStreams.getScreenP()
         .then(result => {
            // Handle MediaStream result
          }, error => {
            // Handle error
          })

Get Screen Share possible Error messages. These apply to the above calls:

  • Screen Share extension is not installed or disabled
  • Screen Share extension not responding
  • Screen Share permission denied by user
  • Get User Media not supported
  • Only secure origins are allowed
  • InternalError on getUserMedia API

Get User MediaStream

getMedia:: Promise

Type: Function

Param: constraints ; Type: Object ; Values: MediaStreamConstraints dictionary

Return: Promise

WebStreams.getMedia(constraints)
         .then(result => {
            // Handle MediaStream result
          }, error => {
            // Handle error
          })

Examples of constraints:

const ex1 = {
  video: true
}

const ex2 = {
  audio: true
}

const ex3 = {
  video: true,
  audio: true
}

const ex4 = {
  video: {
    width: 160,
    height: 120
  },
  audio: {
    echoCancellation: true
  }
}

Test Mode Available for low resolution options. To use the test mode constraints call getMedia with:

const constraints = {testMode: true}

WebStreams.getMedia(constraints)
         .then(result => {
            // Handle MediaStream result
          }, error => {
            // Handle error
          })

Get User Media possible Error messages:

  • Get User Media not supported
  • At least one of audio and video must be requested
  • Only secure origins are allowed
  • InternalError on getUserMedia API
setTestConstraints:: Change the Test Mode constraints objetct used

Type: Function

Param: constraints ; Type: Object ; Values: MediaStreamConstraints dictionary

Return: Object

WebStreams.setTestConstraints(constraints)

By default the testing constraints used are:

{
  video: {
    height: 120,
    width: 160,
    frameRate: {
      ideal: 5,
      max: 10
    },
    facingMode: 'user'
  },
  audio: {
    echoCancellation: true,
    volume: 1
  }
}

Manage Media Tracks

stopAllTracks:: Stop all active tracks

Type: Function

Return: Either Type

WebStreams.stopAllTracks()

This function will go through all the cached MediaStreams, look for the active tracks on them and stop the tracks. Helper function used to clear the browser's "recording" state.

Tests

Unit tests are run using Mocha. You can install it with the following command:

npm install -g mocha

and run the tests with:

mocha or npm test

Ramda subset used

  • compose
  • composeK
  • filter
  • map
  • flatten
  • isNil
  • prop
  • chain
  • test
  • curry

Build command:

./scripts/build -- src/chain.js src/filter.js src/map.js src/flatten.js src/curry.js src/isNil.js src/prop.js src/is.js src/test.js src/compose.js src/composeK.js > dist/ramda.custom.js

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published