Skip to content

Commit

Permalink
DetectRTC.js is updated in development branch. index.html added to te…
Browse files Browse the repository at this point in the history
…st new features.
  • Loading branch information
muaz-khan committed Sep 22, 2015
1 parent e57aff7 commit ad0b047
Show file tree
Hide file tree
Showing 9 changed files with 515 additions and 27 deletions.
69 changes: 57 additions & 12 deletions DetectRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,27 @@ if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
};
}

if (typeof navigator !== 'undefined') {
if (typeof navigator.webkitGetUserMedia !== 'undefined') {
navigator.getUserMedia = navigator.webkitGetUserMedia;
}

if (typeof navigator.mozGetUserMedia !== 'undefined') {
navigator.getUserMedia = navigator.mozGetUserMedia;
}
} else {
/*global navigator:true */
var navigator = {
getUserMedia: {}
};
}

var isMobileDevice = !!navigator.userAgent.match(/Android|iPhone|iPad|iPod|BlackBerry|IEMobile/i);
var isEdge = navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob);

// this one can also be used:
// https://www.websocket.org/js/stuff.js (DetectBrowser.js)

function getBrowserInfo() {
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
Expand Down Expand Up @@ -339,7 +357,7 @@ var hasWebcam = canEnumerate;

// http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediadevices
// todo: switch to enumerateDevices when landed in canary.
function CheckDeviceSupport(callback) {
function checkDeviceSupport(callback) {
// This method is useful only for Chrome!

if (!navigator.enumerateDevices && window.MediaStreamTrack && window.MediaStreamTrack.getSources) {
Expand Down Expand Up @@ -395,6 +413,9 @@ function CheckDeviceSupport(callback) {

if (!device.label) {
device.label = 'Please invoke getUserMedia once.';
if (!isHTTPs) {
device.label = 'HTTPs is required to get label of this ' + device.kind + ' device.';
}
}

if (device.kind === 'audioinput' || device.kind === 'audio') {
Expand All @@ -416,9 +437,9 @@ function CheckDeviceSupport(callback) {

if (typeof DetectRTC !== 'undefined') {
DetectRTC.MediaDevices = MediaDevices;
DetectRTC.hasMicrophone = MediaDevices;
DetectRTC.hasSpeakers = MediaDevices;
DetectRTC.hasWebcam = MediaDevices;
DetectRTC.hasMicrophone = hasMicrophone;
DetectRTC.hasSpeakers = hasSpeakers;
DetectRTC.hasWebcam = hasWebcam;
}

if (callback) {
Expand All @@ -428,7 +449,7 @@ function CheckDeviceSupport(callback) {
}

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

var DetectRTC = {};

Expand Down Expand Up @@ -480,7 +501,12 @@ DetectRTC.isCreateMediaStreamSourceSupported = webAudio.isCreateMediaStreamSourc

// ---------- Detect if SCTP/RTP channels are supported.

DetectRTC.isRtpDataChannelsSupported = DetectRTC.browser.isChrome && DetectRTC.browser.version > 31;
var isRtpDataChannelsSupported = false;
if (DetectRTC.browser.isChrome && DetectRTC.browser.version > 31) {
isRtpDataChannelsSupported = true;
}
DetectRTC.isRtpDataChannelsSupported = isRtpDataChannelsSupported;

var isSCTPSupportd = false;
if (DetectRTC.browser.isFirefox && DetectRTC.browser.version > 28) {
isSCTPSupportd = true;
Expand All @@ -499,12 +525,20 @@ DetectRTC.isMobileDevice = isMobileDevice; // "isMobileDevice" boolean is define

DetectRTC.isWebSocketsSupported = 'WebSocket' in window && 2 === window.WebSocket.CLOSING;
if (DetectRTC.isWebSocketsSupported) {
var websocket = new WebSocket('wss://test.com:443/');
var websocket = new WebSocket('wss://echo.websocket.org:443/');
websocket.onopen = function() {
DetectRTC.isWebSocketsBlocked = false;

if (DetectRTC.loadCallback) {
DetectRTC.loadCallback();
}
};
websocket.onerror = function() {
DetectRTC.isWebSocketsBlocked = true;

if (DetectRTC.loadCallback) {
DetectRTC.loadCallback();
}
};
}

Expand All @@ -518,7 +552,7 @@ if (navigator.getUserMedia) {
if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 47 && !isHTTPs) {
DetectRTC.isGetUserMediaSupported = 'Requires HTTPs';
}
DetectRTC.isGetUserMediaSupported = false;
DetectRTC.isGetUserMediaSupported = isGetUserMediaSupported;

// -----------
DetectRTC.osName = osName; // "osName" is defined in "detectOSName.js"
Expand All @@ -531,12 +565,16 @@ DetectRTC.isVideoSupportsStreamCapturing = isVideoSupportsStreamCapturing;
DetectRTC.DetectLocalIPAddress = DetectLocalIPAddress;

// -------
DetectRTC.load = CheckDeviceSupport;
DetectRTC.load = function(callback) {
this.loadCallback = callback;

checkDeviceSupport(callback);
};

DetectRTC.MediaDevices = MediaDevices;
DetectRTC.hasMicrophone = MediaDevices;
DetectRTC.hasSpeakers = MediaDevices;
DetectRTC.hasWebcam = MediaDevices;
DetectRTC.hasMicrophone = hasMicrophone;
DetectRTC.hasSpeakers = hasSpeakers;
DetectRTC.hasWebcam = hasWebcam;

// ------
var isSetSinkIdSupported = false;
Expand All @@ -562,3 +600,10 @@ DetectRTC.isRTPSenderReplaceTracksSupported = isRTPSenderReplaceTracksSupported;

//-------
DetectRTC.isORTCSupported = typeof RTCIceGatherer !== 'undefined';

//------
var isRemoteStreamProcessingSupported = false;
if (DetectRTC.browser.isFirefox && DetectRTC.browser.version > 38) {
isRemoteStreamProcessingSupported = true;
}
DetectRTC.isRemoteStreamProcessingSupported = isRemoteStreamProcessingSupported;
2 changes: 1 addition & 1 deletion DetectRTC.min.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
DetectRTC.isSetSinkIdSupported // (implemented)
DetectRTC.isRTPSenderReplaceTracksSupported // (implemented)
DetectRTC.isORTCSupported // (implemented)
DetectRTC.isRemoteStreamProcessingSupported // (implemented)

DetectRTC.isRemoteStreamProcessingSupported
DetectRTC.isMediaDevicesNewSyntaxSupported
DetectRTC.browser.googSupportedFlags.googDAEEchoCancellation
DetecRTC.browser.googSupportedFlags.echoCancellation
DetectRTC.isMediaHintsSupportsNewSyntax
```

# Test

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

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

# Rules to Contribute

```
Expand Down
13 changes: 8 additions & 5 deletions dev/CheckDeviceSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var hasWebcam = canEnumerate;

// http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediadevices
// todo: switch to enumerateDevices when landed in canary.
function CheckDeviceSupport(callback) {
function checkDeviceSupport(callback) {
// This method is useful only for Chrome!

if (!navigator.enumerateDevices && window.MediaStreamTrack && window.MediaStreamTrack.getSources) {
Expand Down Expand Up @@ -72,6 +72,9 @@ function CheckDeviceSupport(callback) {

if (!device.label) {
device.label = 'Please invoke getUserMedia once.';
if(!isHTTPs) {
device.label = 'HTTPs is required to get label of this ' + device.kind + ' device.';
}
}

if (device.kind === 'audioinput' || device.kind === 'audio') {
Expand All @@ -93,9 +96,9 @@ function CheckDeviceSupport(callback) {

if(typeof DetectRTC !== 'undefined') {
DetectRTC.MediaDevices = MediaDevices;
DetectRTC.hasMicrophone = MediaDevices;
DetectRTC.hasSpeakers = MediaDevices;
DetectRTC.hasWebcam = MediaDevices;
DetectRTC.hasMicrophone = hasMicrophone;
DetectRTC.hasSpeakers = hasSpeakers;
DetectRTC.hasWebcam = hasWebcam;
}

if (callback) {
Expand All @@ -105,4 +108,4 @@ function CheckDeviceSupport(callback) {
}

// check for microphone/camera support!
new CheckDeviceSupport();
checkDeviceSupport();
38 changes: 31 additions & 7 deletions dev/DetectRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ DetectRTC.isCreateMediaStreamSourceSupported = webAudio.isCreateMediaStreamSourc

// ---------- Detect if SCTP/RTP channels are supported.

DetectRTC.isRtpDataChannelsSupported = DetectRTC.browser.isChrome && DetectRTC.browser.version > 31;
var isRtpDataChannelsSupported = false;
if(DetectRTC.browser.isChrome && DetectRTC.browser.version > 31) {
isRtpDataChannelsSupported = true;
}
DetectRTC.isRtpDataChannelsSupported = isRtpDataChannelsSupported;

var isSCTPSupportd = false;
if(DetectRTC.browser.isFirefox && DetectRTC.browser.version > 28) {
isSCTPSupportd = true;
Expand All @@ -70,12 +75,20 @@ DetectRTC.isMobileDevice = isMobileDevice; // "isMobileDevice" boolean is define

DetectRTC.isWebSocketsSupported = 'WebSocket' in window && 2 === window.WebSocket.CLOSING;
if(DetectRTC.isWebSocketsSupported) {
var websocket = new WebSocket('wss://test.com:443/');
var websocket = new WebSocket('wss://echo.websocket.org:443/');
websocket.onopen = function() {
DetectRTC.isWebSocketsBlocked = false;

if(DetectRTC.loadCallback) {
DetectRTC.loadCallback();
}
};
websocket.onerror = function() {
DetectRTC.isWebSocketsBlocked = true;

if(DetectRTC.loadCallback) {
DetectRTC.loadCallback();
}
};
}

Expand All @@ -90,7 +103,7 @@ else if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia){
if(DetectRTC.browser.isChrome && DetectRTC.browser.version >= 47 && !isHTTPs) {
DetectRTC.isGetUserMediaSupported = 'Requires HTTPs';
}
DetectRTC.isGetUserMediaSupported = false;
DetectRTC.isGetUserMediaSupported = isGetUserMediaSupported;

// -----------
DetectRTC.osName = osName; // "osName" is defined in "detectOSName.js"
Expand All @@ -103,12 +116,16 @@ DetectRTC.isVideoSupportsStreamCapturing = isVideoSupportsStreamCapturing;
DetectRTC.DetectLocalIPAddress = DetectLocalIPAddress;

// -------
DetectRTC.load = CheckDeviceSupport;
DetectRTC.load = function(callback) {
this.loadCallback = callback;

checkDeviceSupport(callback);
};

DetectRTC.MediaDevices = MediaDevices;
DetectRTC.hasMicrophone = MediaDevices;
DetectRTC.hasSpeakers = MediaDevices;
DetectRTC.hasWebcam = MediaDevices;
DetectRTC.hasMicrophone = hasMicrophone;
DetectRTC.hasSpeakers = hasSpeakers;
DetectRTC.hasWebcam = hasWebcam;

// ------
var isSetSinkIdSupported = false;
Expand All @@ -135,3 +152,10 @@ DetectRTC.isRTPSenderReplaceTracksSupported = isRTPSenderReplaceTracksSupported;

//-------
DetectRTC.isORTCSupported = typeof RTCIceGatherer !== 'undefined';

//------
var isRemoteStreamProcessingSupported = false;
if(DetectRTC.browser.isFirefox && DetectRTC.browser.version > 38) {
isRemoteStreamProcessingSupported = true;
}
DetectRTC.isRemoteStreamProcessingSupported = isRemoteStreamProcessingSupported;
15 changes: 15 additions & 0 deletions dev/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
navigator.mediaDevices.enumerateDevices().then(callback);
};
}

if (typeof navigator !== 'undefined') {
if (typeof navigator.webkitGetUserMedia !== 'undefined') {
navigator.getUserMedia = navigator.webkitGetUserMedia;
}

if (typeof navigator.mozGetUserMedia !== 'undefined') {
navigator.getUserMedia = navigator.mozGetUserMedia;
}
} else {
/*global navigator:true */
var navigator = {
getUserMedia: {}
};
}
3 changes: 3 additions & 0 deletions dev/getBrowserInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var isMobileDevice = !!navigator.userAgent.match(/Android|iPhone|iPad|iPod|BlackBerry|IEMobile/i);
var isEdge = navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob);

// this one can also be used:
// https://www.websocket.org/js/stuff.js (DetectBrowser.js)

function getBrowserInfo() {
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
Expand Down
Loading

0 comments on commit ad0b047

Please sign in to comment.