node package manager


DetectRTC.js / Try LIVE Demo

npm downloads Build Status: Linux

A tiny JavaScript library that can be used to detect WebRTC features e.g. system having speakers, microphone or webcam, screen capturing is supported, number of audio/video devices etc.

It is MIT Licenced, which means that you can use it in any commercial/non-commercial product, free of cost.

npm install detectrtc
# or via "bower"
bower install detectrtc

Proposed NEW API

DetectRTC.isSetSinkIdSupported                  // (implemented) 
DetectRTC.isRTPSenderReplaceTracksSupported     // (implemented) 
DetectRTC.isORTCSupported                       // (implemented) 
DetectRTC.isRemoteStreamProcessingSupported     // (implemented) 
DetectRTC.isWebsiteHasWebcamPermissions        // (implemented) 
DetectRTC.isWebsiteHasMicrophonePermissions    // (implemented) 
DetectRTC.audioInputDevices    // (implemented) 
DetectRTC.audioOutputDevices   // (implemented) 
DetectRTC.videoInputDevices    // (implemented) 
// Below API are NOT implemented yet 

Test in LocalHost

node server.js
# and open:
# or

Test on NPM

var DetectRTC = require('detectrtc');
DetectRTC.load(function() {

Or try npm-test.js:

cd node_modules
cd detectrtc
node npm-test.js

How to link?

<script src="./node_modules/detectrtc/DetectRTC.js"></script>
<!-- or bower -->
<script src="./bower_components/detectrtc/DetectRTC.js"></script>
<!-- or CDN link (suggested) -->
<script src=""></script>
<!-- or RawGit (if CDN fails) -->
<script src=""></script>

You can even link specific versions:

<script src=""></script>

How to use it?

// for node.js users 
var DetectRTC = require('detectrtc');
// non-nodejs users can skip above line 
// below code will work for all users 
DetectRTC.load(function() {
    DetectRTC.hasWebcam (has webcam device!)
    DetectRTC.hasMicrophone (has microphone device!)
    DetectRTC.hasSpeakers (has speakers!)
    DetectRTC.isWebsiteHasWebcamPermissions        // getUserMedia allowed for HTTPs domain in Chrome? 
    DetectRTC.isWebsiteHasMicrophonePermissions    // getUserMedia allowed for HTTPs domain in Chrome? 
    DetectRTC.audioInputDevices    // microphones 
    DetectRTC.audioOutputDevices   // speakers 
    DetectRTC.videoInputDevices    // cameras 
    DetectRTC.osVersion === 'Edge' || 'Chrome' || 'Firefox'
    DetectRTC.browser.isPrivateBrowsing // incognito or private modes 

Why load method?

If you're not detecting audio/video input/outupt devices then you can skip this method.

DetectRTC.load simply makes sure that all devices are captured and valid result is set for relevant properties.

How to use specific files?


<script src=""></script>
function selectSecondaryCamera() {
    checkDeviceSupport(function() {
        var secondDevice = videoInputDevices[1];
        if(!secondDevice) return alert('Secondary webcam is NOT available.');
        var videoConstraints = {
            deviceId: secondDevice.deviceId
        if(!!navigator.webkitGetUserMedia) {
            videoConstraints = {
                mandatory: {},
                optional: [{
                    sourceId: secondDevice.deviceId
        navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
        navigator.getUserMedia({ video: videoConstraints }, function(stream) {
        }, function(error) {

For further tricks & usages:

Rules to Contribute

git clone --depth=50 --branch=development git:// muaz-khan/DetectRTC
# install all dependencies
[sudo] npm install
# install grunt for code style verifications
[sudo] npm install grunt-cli
[sudo] npm install grunt
# verify your changes
npm test  # or "grunt"
# Success? Make a pull request!


DetectRTC.js is released under MIT licence . Copyright (c) Muaz Khan.