Skip to content

Commit

Permalink
Added "tests" using "protractor" via "browserstack+travis"
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed May 24, 2017
1 parent 9620d85 commit b7f609b
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 68 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ before_script:
- npm install [email protected] -g
- npm install [email protected]
- grunt
- npm install [email protected]
after_failure: npm install && grunt
matrix:
fast_finish: true
fast_finish: true
11 changes: 6 additions & 5 deletions DetectRTC.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

// Last Updated On: 2017-05-21 5:10:21 AM UTC
// Last Updated On: 2017-05-24 4:28:17 PM UTC

// ________________
// DetectRTC v1.3.4
Expand Down Expand Up @@ -738,7 +738,7 @@

if (!device.label) {
device.label = 'Please invoke getUserMedia once.';
if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 46 && !/^(https:|chrome-extension:)$/g.test(location.protocol || '')) {
if (typeof DetectRTC !== 'undefined' && DetectRTC.browser.isChrome && DetectRTC.browser.version >= 46 && !/^(https:|chrome-extension:)$/g.test(location.protocol || '')) {
if (typeof document !== 'undefined' && typeof document.domain === 'string' && document.domain.search && document.domain.search(/localhost|127.0./g) === -1) {
device.label = 'HTTPs is required to get label of this ' + device.kind + ' device.';
}
Expand Down Expand Up @@ -804,9 +804,6 @@
});
}

// check for microphone/camera support!
checkDeviceSupport();

var DetectRTC = window.DetectRTC || {};

// ----------
Expand Down Expand Up @@ -984,6 +981,10 @@
checkDeviceSupport(callback);
};

// check for microphone/camera support!
if (typeof checkDeviceSupport === 'function') {
// checkDeviceSupport();
}

if (typeof MediaDevices !== 'undefined') {
DetectRTC.MediaDevices = MediaDevices;
Expand Down
4 changes: 2 additions & 2 deletions DetectRTC.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = function(grunt) {
jsbeautifier: {
files: [
'dev/*.js',
'test/*.js',
'DetectRTC.js',
'Gruntfile.js'
],
Expand Down
147 changes: 92 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
# DetectRTC | Is WebRTC Supported In Your Browser?

[![npm](https://img.shields.io/npm/v/detectrtc.svg)](https://npmjs.org/package/detectrtc) [![downloads](https://img.shields.io/npm/dm/detectrtc.svg)](https://npmjs.org/package/detectrtc) [![Build Status: Linux](https://travis-ci.org/muaz-khan/DetectRTC.png?branch=master)](https://travis-ci.org/muaz-khan/DetectRTC) <a href="https://www.browserstack.com"><img src="https://webrtcweb.com/browserstack.svg" height="20px" /></a>

### Live Demo: https://www.webrtc-experiment.com/DetectRTC/

[![npm](https://img.shields.io/npm/v/detectrtc.svg)](https://npmjs.org/package/detectrtc) [![downloads](https://img.shields.io/npm/dm/detectrtc.svg)](https://npmjs.org/package/detectrtc) [![Build Status: Linux](https://travis-ci.org/muaz-khan/DetectRTC.png?branch=master)](https://travis-ci.org/muaz-khan/DetectRTC)
```javascript
if (DetectRTC.isWebRTCSupported === false) {
alert('Please use Chrome or Firefox.');
}

* [Check all DetectRTC releases](https://github.com/muaz-khan/DetectRTC/releases)
if (DetectRTC.hasWebcam === false) {
alert('Please install an external webcam device.');
}

if (DetectRTC.hasMicrophone === false) {
alert('Please install an external microphone device.');
}

if (DetectRTC.hasSpeakers === false && (DetectRTC.broser.name === 'Chrome' || DetectRTC.broser.name === 'Edge')) {
alert('Oops, your system can not play audios.');
}
```

## What is this?

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.

## Free?

It is <a href="https://www.webrtc-experiment.com/licence/">MIT Licenced</a>, which means that you can use it in any commercial/non-commercial product, free of cost.

## Tests?

* https://travis-ci.org/muaz-khan/DetectRTC

## Releases?

* https://github.com/muaz-khan/DetectRTC/releases

## How to install?

```
npm install detectrtc
npm install detectrtc --production
# or via "bower"
bower install detectrtc
Expand All @@ -38,9 +68,9 @@ DetecRTC.browser.googSupportedFlags.echoCancellation
DetectRTC.isMediaHintsSupportsNewSyntax
```

# Test in LocalHost
# LocalHost

```
```sh
node server.js

# or
Expand All @@ -53,7 +83,7 @@ http://127.0.0.1:9001
http://localhost:9001
```

# Test on NPM
# NPM

```javascript
var DetectRTC = require('detectrtc');
Expand All @@ -69,7 +99,7 @@ DetectRTC.load(function() {

Or try `npm-test.js`:

```
```sh
cd node_modules
cd detectrtc

Expand All @@ -78,7 +108,7 @@ cd detectrtc
node npm-test.js
```

# How to link?
# How to link the script?

```html
<script src="./node_modules/detectrtc/DetectRTC.js"></script>
Expand Down Expand Up @@ -111,46 +141,46 @@ var DetectRTC = require('detectrtc');
// 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.isScreenCapturingSupported
DetectRTC.isSctpDataChannelsSupported
DetectRTC.isRtpDataChannelsSupported
DetectRTC.isAudioContextSupported
DetectRTC.isWebRTCSupported
DetectRTC.isDesktopCapturingSupported
DetectRTC.isMobileDevice

DetectRTC.isWebSocketsSupported
DetectRTC.isWebSocketsBlocked
DetectRTC.checkWebSocketsSupport(callback)

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.osName
DetectRTC.osVersion

DetectRTC.browser.name === 'Edge' || 'Chrome' || 'Firefox'
DetectRTC.browser.version
DetectRTC.browser.isChrome
DetectRTC.browser.isFirefox
DetectRTC.browser.isOpera
DetectRTC.browser.isIE
DetectRTC.browser.isSafari
DetectRTC.browser.isEdge

DetectRTC.browser.isPrivateBrowsing // incognito or private modes

DetectRTC.isCanvasSupportsStreamCapturing
DetectRTC.isVideoSupportsStreamCapturing

DetectRTC.DetectLocalIPAddress(callback)
DetectRTC.hasWebcam; // (has webcam device!)
DetectRTC.hasMicrophone; // (has microphone device!)
DetectRTC.hasSpeakers; // (has speakers!)
DetectRTC.isScreenCapturingSupported;
DetectRTC.isSctpDataChannelsSupported;
DetectRTC.isRtpDataChannelsSupported;
DetectRTC.isAudioContextSupported;
DetectRTC.isWebRTCSupported;
DetectRTC.isDesktopCapturingSupported;
DetectRTC.isMobileDevice;

DetectRTC.isWebSocketsSupported;
DetectRTC.isWebSocketsBlocked;
DetectRTC.checkWebSocketsSupport(callback);

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.osName;
DetectRTC.osVersion;

DetectRTC.browser.name === 'Edge' || 'Chrome' || 'Firefox';
DetectRTC.browser.version;
DetectRTC.browser.isChrome;
DetectRTC.browser.isFirefox;
DetectRTC.browser.isOpera;
DetectRTC.browser.isIE;
DetectRTC.browser.isSafari;
DetectRTC.browser.isEdge;

DetectRTC.browser.isPrivateBrowsing; // incognito or private modes

DetectRTC.isCanvasSupportsStreamCapturing;
DetectRTC.isVideoSupportsStreamCapturing;

DetectRTC.DetectLocalIPAddress(callback);
});
```

Expand Down Expand Up @@ -202,15 +232,16 @@ For further tricks & usages:

# Rules to Contribute

```
git clone --depth=50 --branch=development git://github.com/muaz-khan/DetectRTC.git muaz-khan/DetectRTC
# install all dependencies
[sudo] npm install
```sh
mkdir DetectRTC
cd DetectRTC
git clone git://github.com/muaz-khan/DetectRTC.git ./

# install grunt for code style verifications
[sudo] npm install grunt-cli
[sudo] npm install grunt
npm install grunt-cli

# install all dependencies
npm install --save-dev

# verify your changes
# npm test # or "grunt"
Expand All @@ -223,6 +254,12 @@ grunt

* https://github.com/muaz-khan/DetectRTC

# Tests powered by

* Check tests here: https://travis-ci.org/muaz-khan/DetectRTC

<a href="https://www.browserstack.com"><img src="https://webrtcweb.com/browserstack.svg" height="32px" /></a>

# License

[DetectRTC.js](https://github.com/muaz-khan/DetectRTC) is released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](http://www.MuazKhan.com/).
5 changes: 1 addition & 4 deletions dev/CheckDeviceSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function checkDeviceSupport(callback) {

if (!device.label) {
device.label = 'Please invoke getUserMedia once.';
if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 46 && !/^(https:|chrome-extension:)$/g.test(location.protocol || '')) {
if (typeof DetectRTC !== 'undefined' && DetectRTC.browser.isChrome && DetectRTC.browser.version >= 46 && !/^(https:|chrome-extension:)$/g.test(location.protocol || '')) {
if (typeof document !== 'undefined' && typeof document.domain === 'string' && document.domain.search && document.domain.search(/localhost|127.0./g) === -1) {
device.label = 'HTTPs is required to get label of this ' + device.kind + ' device.';
}
Expand Down Expand Up @@ -166,6 +166,3 @@ function checkDeviceSupport(callback) {
}
});
}

// check for microphone/camera support!
checkDeviceSupport();
4 changes: 4 additions & 0 deletions dev/DetectRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ DetectRTC.load = function(callback) {
checkDeviceSupport(callback);
};

// check for microphone/camera support!
if (typeof checkDeviceSupport === 'function') {
// checkDeviceSupport();
}

if (typeof MediaDevices !== 'undefined') {
DetectRTC.MediaDevices = MediaDevices;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"url": "https://github.com/muaz-khan/DetectRTC.git"
},
"scripts": {
"start": "node server.js"
"start": "node server.js",
"test": "./node_modules/.bin/protractor test/browserstack.config.js"
},
"main": "DetectRTC.js",
"keywords": [
Expand Down
32 changes: 32 additions & 0 deletions test/CheckDeviceSupport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe('DetectRTC', function() {
it('dev/CheckDeviceSupport', function() {
console.log('------------------------------');
console.log('\x1b[31m%s\x1b[0m ', 'dev/CheckDeviceSupport.js');

browser.driver.get('https://webrtcweb.com/DetectRTC/CheckDeviceSupport.html').then(function() {
var audioInputDevices = 0;
var audioOutputDevices = 0;
var videoInputDevices = 0;

browser.driver.findElement(by.id('audioInputDevices')).getText().then(function(value) {
audioInputDevices = value;
});

browser.driver.findElement(by.id('audioOutputDevices')).getText().then(function(value) {
audioOutputDevices = value;
});

browser.driver.findElement(by.id('videoInputDevices')).getText().then(function(value) {
videoInputDevices = value;
});

browser.wait(function() {
console.log('audioInputDevices: ' + audioInputDevices);
console.log('audioOutputDevices: ' + audioOutputDevices);
console.log('videoInputDevices: ' + videoInputDevices);

return true;
}, 1000, 'CheckDeviceSupport did not return valid information.');
});
});
});
56 changes: 56 additions & 0 deletions test/DetectRTC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
describe('DetectRTC', function() {
it('DetectRTC compiled using grunt', function() {
console.log('------------------------------');
console.log('\x1b[31m%s\x1b[0m ', 'DetectRTC.js');

browser.driver.get('https://webrtcweb.com/DetectRTC/DetectRTC.html').then(function() {
var booleans = {};
var failed = {};

['hasWebcam', 'hasMicrophone', 'hasSpeakers', 'isApplyConstraintsSupported',
'isAudioContextSupported', 'isCanvasSupportsStreamCapturing',
'isCreateMediaStreamSourceSupported', 'isGetUserMediaSupported',
'isMobileDevice', 'isMultiMonitorScreenCapturingSupported', 'isORTCSupported',
'isPromisesSupported', 'isRTPSenderReplaceTracksSupported', 'isRemoteStreamProcessingSupported',
'isRtpDataChannelsSupported', 'isScreenCapturingSupported', 'isSctpDataChannelsSupported',
'isSetSinkIdSupported', 'isVideoSupportsStreamCapturing', 'isWebRTCSupported',
'isWebSocketsBlocked', 'isWebSocketsSupported', 'isWebsiteHasMicrophonePermissions', 'isWebsiteHasWebcamPermissions'
].forEach(function(prop) {
browser.driver.findElement(by.id(prop)).getText().then(function(value) {
if (!value.toString().length) {
failed[prop] = true;
return;
}

if (typeof value !== 'boolean') {
if (value === 'true') {
value = true;
} else if (value === 'false') {
value = false;
} else {
value = value;
}
}

booleans[prop] = value;
});
});

browser.wait(function() {
Object.keys(booleans).forEach(function(key) {
console.log(key + ': ' + booleans[key]);
});

if (Object.keys(failed).length) {
Object.keys(failed).forEach(function(key) {
console.error(key + ': test failed.');
});

throw new Error(Object.keys(failed).length + ' tests failed.');
}

return true;
}, 1000, 'DetectRTC did not return valid information.');
});
});
});
Loading

0 comments on commit b7f609b

Please sign in to comment.