Skip to content

Commit

Permalink
Added DetectRTC-v1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Jan 1, 2016
1 parent d9cdd4e commit 424ac4c
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 41 deletions.
66 changes: 52 additions & 14 deletions DetectRTC.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Sunday, December 13th, 2015, 11:10:15 AM
// Last time updated at Friday, January 1st, 2016, 5:04:28 PM

// Latest file can be found here: https://cdn.webrtc-experiment.com/DetectRTC.js

Expand All @@ -18,14 +18,6 @@

var navigator = window.navigator;

if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
// Firefox 38+ seems having support of enumerateDevices
// Thanks @xdumaine/enumerateDevices
navigator.enumerateDevices = function(callback) {
navigator.mediaDevices.enumerateDevices().then(callback);
};
}

if (typeof navigator !== 'undefined') {
if (typeof navigator.webkitGetUserMedia !== 'undefined') {
navigator.getUserMedia = navigator.webkitGetUserMedia;
Expand Down Expand Up @@ -338,6 +330,18 @@

var MediaDevices = [];

var audioInputDevices = [];
var audioOutputDevices = [];
var videoInputDevices = [];

if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
// Firefox 38+ seems having support of enumerateDevices
// Thanks @xdumaine/enumerateDevices
navigator.enumerateDevices = function(callback) {
navigator.mediaDevices.enumerateDevices().then(callback);
};
}

// ---------- Media Devices detection
var canEnumerate = false;

Expand All @@ -352,6 +356,9 @@
var hasSpeakers = false;
var hasWebcam = false;

var isWebsiteHasMicrophonePermissions = false;
var isWebsiteHasWebcamPermissions = false;

// http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediadevices
// todo: switch to enumerateDevices when landed in canary.
function checkDeviceSupport(callback) {
Expand All @@ -377,6 +384,11 @@
}

MediaDevices = [];

audioInputDevices = [];
audioOutputDevices = [];
videoInputDevices = [];

navigator.enumerateDevices(function(devices) {
devices.forEach(function(_device) {
var device = {};
Expand Down Expand Up @@ -414,21 +426,32 @@

if (!device.label) {
device.label = 'Please invoke getUserMedia once.';
if (!isHTTPs) {
if (location.protocol !== 'https:') {
device.label = 'HTTPs is required to get label of this ' + device.kind + ' device.';
}
} else {
if (device.kind === 'videoinput' && !isWebsiteHasWebcamPermissions) {
isWebsiteHasWebcamPermissions = true;
}

if (device.kind === 'audioinput' && !isWebsiteHasMicrophonePermissions) {
isWebsiteHasMicrophonePermissions = true;
}
}

if (device.kind === 'audioinput') {
hasMicrophone = true;
audioInputDevices.push(device);
}

if (device.kind === 'audiooutput') {
hasSpeakers = true;
audioOutputDevices.push(device);
}

if (device.kind === 'videoinput') {
hasWebcam = true;
videoInputDevices.push(device);
}

// there is no 'videoouput' in the spec.
Expand All @@ -437,10 +460,18 @@
});

if (typeof DetectRTC !== 'undefined') {
// to sync latest outputs
DetectRTC.MediaDevices = MediaDevices;
DetectRTC.hasMicrophone = hasMicrophone;
DetectRTC.hasSpeakers = hasSpeakers;
DetectRTC.hasWebcam = hasWebcam;

DetectRTC.isWebsiteHasWebcamPermissions = isWebsiteHasWebcamPermissions;
DetectRTC.isWebsiteHasMicrophonePermissions = isWebsiteHasMicrophonePermissions;

DetectRTC.audioInputDevices = audioInputDevices;
DetectRTC.audioOutputDevices = audioOutputDevices;
DetectRTC.videoInputDevices = videoInputDevices;
}

if (callback) {
Expand All @@ -452,7 +483,7 @@
// check for microphone/camera support!
checkDeviceSupport();

var DetectRTC = {};
var DetectRTC = window.DetectRTC || {};

// ----------
// DetectRTC.browser.name || DetectRTC.browser.version || DetectRTC.browser.fullVersion
Expand All @@ -461,7 +492,6 @@
// DetectRTC.isChrome || DetectRTC.isFirefox || DetectRTC.isEdge
DetectRTC.browser['is' + DetectRTC.browser.name] = true;

var isHTTPs = location.protocol === 'https:';
var isNodeWebkit = !!(window.process && (typeof window.process === 'object') && window.process.versions && window.process.versions['node-webkit']);

// --------- Detect if system supports WebRTC 1.0 or WebRTC 1.1.
Expand All @@ -488,7 +518,7 @@
isScreenCapturingSupported = true;
}

if (!isHTTPs) {
if (location.protocol !== 'https:') {
isScreenCapturingSupported = false;
}
DetectRTC.isScreenCapturingSupported = isScreenCapturingSupported;
Expand Down Expand Up @@ -551,6 +581,7 @@
DetectRTC.loadCallback();
}
websocket.close();
websocket = null;
};
websocket.onerror = function() {
DetectRTC.isWebSocketsBlocked = true;
Expand All @@ -568,7 +599,7 @@
} else if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
isGetUserMediaSupported = true;
}
if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 46 && !isHTTPs) {
if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 46 && location.protocol !== 'https:') {
DetectRTC.isGetUserMediaSupported = 'Requires HTTPs';
}
DetectRTC.isGetUserMediaSupported = isGetUserMediaSupported;
Expand All @@ -595,6 +626,13 @@
DetectRTC.hasSpeakers = hasSpeakers;
DetectRTC.hasWebcam = hasWebcam;

DetectRTC.isWebsiteHasWebcamPermissions = isWebsiteHasWebcamPermissions;
DetectRTC.isWebsiteHasMicrophonePermissions = isWebsiteHasMicrophonePermissions;

DetectRTC.audioInputDevices = audioInputDevices;
DetectRTC.audioOutputDevices = audioOutputDevices;
DetectRTC.videoInputDevices = videoInputDevices;

// ------
var isSetSinkIdSupported = false;
if ('setSinkId' in document.createElement('video')) {
Expand Down
4 changes: 2 additions & 2 deletions DetectRTC.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function(grunt) {
'dev/detectOSName.js',
'dev/detectCaptureStream.js',
'dev/DetectLocalIPAddress.js',
'dev/CheckDeviceSupport.js',
'dev/checkDeviceSupport.js',
'dev/DetectRTC.js',
'dev/tail.js'
],
Expand Down
71 changes: 64 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ It is <a href="https://www.webrtc-experiment.com/licence/">MIT Licenced</a>, whi
```
npm install detectrtc
# or
# or via "bower"
bower install detectrtc
```

Expand All @@ -23,6 +23,13 @@ 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
DetectRTC.browser.googSupportedFlags.googDAEEchoCancellation
DetecRTC.browser.googSupportedFlags.echoCancellation
Expand All @@ -31,25 +38,28 @@ DetectRTC.isMediaHintsSupportsNewSyntax

# Test in LocalHost

```javascript
```
node server.js
// and open:
# and open:
127.0.0.1:9001
// or
# or
http://localhost:9001
```

To use it:
# How to link?

```html
<script src="./node_modules/detectrtc/DetectRTC.js"></script>

<!-- or CDN link -->
<!-- or bower -->
<script src="./bower_components/detectrtc/DetectRTC.js"></script>

<!-- or CDN link (suggested) -->
<script src="https://cdn.webrtc-experiment.com/DetectRTC.js"></script>

<!-- or RawGit -->
<!-- or RawGit (if CDN fails) -->
<script src="https://cdn.rawgit.com/muaz-khan/DetectRTC/master/DetectRTC.js"></script>
```

Expand All @@ -70,6 +80,13 @@ DetectRTC.load(function() {
// DetectRTC.isDesktopCapturingSupported
// DetectRTC.isMobileDevice
// DetectRTC.isWebSocketsSupported

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

Expand All @@ -95,6 +112,46 @@ If you're not detecting audio/video input/outupt devices then you can skip this

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

# How to use specific files?

Demo: [https://jsfiddle.net/cf90az9q/](https://jsfiddle.net/cf90az9q/)

```html
<script src="https://cdn.webrtc-experiment.com/DetectRTC/checkDeviceSupport.js"></script>
<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) {
alert(JSON.stringify(error));
});
});
}
</script>
```

For further tricks & usages:

* https://www.webrtc-experiment.com/webrtcpedia/#modify-streams

<img src="https://i.imgur.com/YXehckT.jpg?1" />

# Rules to Contribute
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "detectrtc",
"version": "1.0.4",
"version": "1.2.4",
"authors": [
{
"name": "Muaz Khan",
Expand Down
Loading

0 comments on commit 424ac4c

Please sign in to comment.