Comparing version 1.0.1 to 1.0.2
221
DetectRTC.js
@@ -1,2 +0,2 @@ | ||
// Last time updated at Sep 16, 2014, 08:32:23 | ||
// Last time updated at Jan 19, 2015, 08:32:23 | ||
@@ -30,11 +30,21 @@ // Latest file can be found here: https://cdn.webrtc-experiment.com/DetectRTC.js | ||
(function() { | ||
'use strict'; | ||
// detect node-webkit | ||
var isNodeWebkit = window.process && (typeof window.process == 'object') && window.process.versions && window.process.versions['node-webkit']; | ||
var browser = getBrowserInfo(); | ||
// is this a chromium browser (opera or chrome) | ||
var isChrome = browser.name == 'Chrome'; | ||
var isFirefox = browser.name == 'Firefox'; | ||
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; | ||
var isFirefox = typeof InstallTrigger !== 'undefined'; | ||
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; | ||
var isChrome = !!window.chrome && !isOpera; | ||
var isIE = !!document.documentMode; | ||
var isMobileDevice = !!navigator.userAgent.match(/Android|iPhone|iPad|iPod|BlackBerry|IEMobile/i); | ||
// detect node-webkit | ||
var isNodeWebkit = !!(window.process && (typeof window.process === 'object') && window.process.versions && window.process.versions['node-webkit']); | ||
var isHTTPs = location.protocol === 'https:'; | ||
window.DetectRTC = { | ||
@@ -47,8 +57,8 @@ browser: browser, | ||
isWebRTCSupported: !!window.webkitRTCPeerConnection || !!window.mozRTCPeerConnection, | ||
isAudioContextSupported: (!!window.AudioContext || !!window.webkitAudioContext) && !!AudioContext.prototype.createMediaStreamSource, | ||
isAudioContextSupported: (!!window.AudioContext && !!window.AudioContext.prototype.createMediaStreamSource) || (!!window.webkitAudioContext && !!window.webkitAudioContext.prototype.createMediaStreamSource), | ||
isScreenCapturingSupported: (isFirefox && browser.version >= 33) || | ||
(isChrome && browser.version >= 26 && (isNodeWebkit ? true : location.protocol == 'https:')), | ||
(isChrome && browser.version >= 26 && (isNodeWebkit ? true : location.protocol === 'https:')), | ||
isDesktopCapturingSupported: (isFirefox && browser.version >= 33) || (isChrome && browser.version >= 34) || isNodeWebkit || false, | ||
isDesktopCapturingSupported: isHTTPs && ((isFirefox && browser.version >= 33) || (isChrome && browser.version >= 34) || isNodeWebkit || false), | ||
@@ -61,13 +71,7 @@ isSctpDataChannelsSupported: isFirefox || (isChrome && browser.version >= 25), | ||
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; | ||
var isFirefox = typeof InstallTrigger !== 'undefined'; | ||
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; | ||
var isChrome = !!window.chrome && !isOpera; | ||
var isIE = !!document.documentMode; | ||
if (!isHTTPs) { | ||
window.DetectRTC.isScreenCapturingSupported = | ||
window.DetectRTC.isDesktopCapturingSupported = 'Requires HTTPs.'; | ||
} | ||
var isMobileDevice = !!navigator.userAgent.match(/Android|iPhone|iPad|iPod|BlackBerry|IEMobile/i); | ||
// detect node-webkit | ||
var isNodeWebkit = !!(window.process && (typeof window.process == 'object') && window.process.versions && window.process.versions['node-webkit']); | ||
DetectRTC.browser = { | ||
@@ -86,6 +90,19 @@ isFirefox: isFirefox, | ||
var osName = 'Unknown OS'; | ||
if (navigator.appVersion.indexOf('Win') != -1) osName = 'Windows'; | ||
if (navigator.appVersion.indexOf('Mac') != -1) osName = 'MacOS'; | ||
if (navigator.appVersion.indexOf('X11') != -1) osName = 'UNIX'; | ||
if (navigator.appVersion.indexOf('Linux') != -1) osName = 'Linux'; | ||
if (navigator.appVersion.indexOf('Win') !== -1) { | ||
osName = 'Windows'; | ||
} | ||
if (navigator.appVersion.indexOf('Mac') !== -1) { | ||
osName = 'MacOS'; | ||
} | ||
if (navigator.appVersion.indexOf('X11') !== -1) { | ||
osName = 'UNIX'; | ||
} | ||
if (navigator.appVersion.indexOf('Linux') !== -1) { | ||
osName = 'Linux'; | ||
} | ||
DetectRTC.osName = osName; | ||
@@ -95,2 +112,14 @@ | ||
if (!navigator.getMediaDevices) { | ||
console.warn('navigator.getMediaDevices API are not available.'); | ||
} | ||
if (!navigator.enumerateDevices) { | ||
console.warn('navigator.enumerateDevices API are not available.'); | ||
} | ||
if (!window.MediaStreamTrack || !window.MediaStreamTrack.getSources) { | ||
console.warn('MediaStreamTrack.getSources are not available.'); | ||
} | ||
// http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediadevices | ||
@@ -104,13 +133,19 @@ // todo: switch to enumerateDevices when landed in canary. | ||
if (isFirefox) { | ||
callback && callback(); | ||
if (callback) { | ||
callback(); | ||
} | ||
return; | ||
} | ||
if (!navigator.getMediaDevices && window.MediaStreamTrack && MediaStreamTrack.getSources) { | ||
navigator.getMediaDevices = MediaStreamTrack.getSources.bind(MediaStreamTrack); | ||
if (!navigator.getMediaDevices && window.MediaStreamTrack && window.MediaStreamTrack.getSources) { | ||
navigator.getMediaDevices = window.MediaStreamTrack.getSources.bind(window.MediaStreamTrack); | ||
} | ||
if (!navigator.getMediaDevices && navigator.enumerateDevices) { | ||
navigator.getMediaDevices = navigator.enumerateDevices.bind(navigator); | ||
} | ||
// if still no 'getMediaDevices'; it MUST be Firefox! | ||
if (!navigator.getMediaDevices) { | ||
log('navigator.getMediaDevices is undefined.'); | ||
console.warn('navigator.getMediaDevices is undefined.'); | ||
// assuming that it is older chrome or chromium implementation | ||
@@ -123,14 +158,28 @@ if (isChrome) { | ||
callback && callback(); | ||
if (callback) { | ||
callback(); | ||
} | ||
return; | ||
} | ||
DetectRTC.MediaDevices = []; | ||
navigator.getMediaDevices(function(devices) { | ||
devices.forEach(function(device) { | ||
var skip; | ||
DetectRTC.MediaDevices.forEach(function(d) { | ||
if (d.id === device.id) { | ||
skip = true; | ||
} | ||
}); | ||
if (skip) { | ||
return; | ||
} | ||
// if it is MediaStreamTrack.getSources | ||
if (device.kind == 'audio') { | ||
if (device.kind === 'audio') { | ||
device.kind = 'audioinput'; | ||
} | ||
if (device.kind == 'video') { | ||
if (device.kind === 'video') { | ||
device.kind = 'videoinput'; | ||
@@ -147,13 +196,21 @@ } | ||
DetectRTC.MediaDevices.push(device); | ||
if (!device.label) { | ||
if (location.protocol === 'https:') { | ||
device.label = 'Please invoke getUserMedia once.'; | ||
} | ||
if (device.kind == 'audioinput' || device.kind == 'audio') { | ||
if (location.protocol === 'http:') { | ||
device.label = 'Plese use HTTPs instead.'; | ||
} | ||
} | ||
if (device.kind === 'audioinput' || device.kind === 'audio') { | ||
DetectRTC.hasMicrophone = true; | ||
} | ||
if (device.kind == 'audiooutput') { | ||
if (device.kind === 'audiooutput') { | ||
DetectRTC.hasSpeakers = true; | ||
} | ||
if (device.kind == 'videoinput' || device.kind == 'video') { | ||
if (device.kind === 'videoinput' || device.kind === 'video') { | ||
DetectRTC.hasWebcam = true; | ||
@@ -163,5 +220,9 @@ } | ||
// there is no 'videoouput' in the spec. | ||
DetectRTC.MediaDevices.push(device); | ||
}); | ||
if (callback) callback(); | ||
if (callback) { | ||
callback(); | ||
} | ||
}); | ||
@@ -171,3 +232,3 @@ } | ||
// check for microphone/camera support! | ||
CheckDeviceSupport(); | ||
new CheckDeviceSupport(); | ||
DetectRTC.load = CheckDeviceSupport; | ||
@@ -184,10 +245,12 @@ | ||
// In Opera, the true version is after 'Opera' or after 'Version' | ||
if ((verOffset = nAgt.indexOf('Opera')) != -1) { | ||
if ((verOffset = nAgt.indexOf('Opera')) !== -1) { | ||
browserName = 'Opera'; | ||
fullVersion = nAgt.substring(verOffset + 6); | ||
if ((verOffset = nAgt.indexOf('Version')) != -1) | ||
if ((verOffset = nAgt.indexOf('Version')) !== -1) { | ||
fullVersion = nAgt.substring(verOffset + 8); | ||
} | ||
} | ||
// In MSIE, the true version is after 'MSIE' in userAgent | ||
else if ((verOffset = nAgt.indexOf('MSIE')) != -1) { | ||
else if ((verOffset = nAgt.indexOf('MSIE')) !== -1) { | ||
browserName = 'IE'; | ||
@@ -197,3 +260,3 @@ fullVersion = nAgt.substring(verOffset + 5); | ||
// In Chrome, the true version is after 'Chrome' | ||
else if ((verOffset = nAgt.indexOf('Chrome')) != -1) { | ||
else if ((verOffset = nAgt.indexOf('Chrome')) !== -1) { | ||
browserName = 'Chrome'; | ||
@@ -203,10 +266,12 @@ fullVersion = nAgt.substring(verOffset + 7); | ||
// In Safari, the true version is after 'Safari' or after 'Version' | ||
else if ((verOffset = nAgt.indexOf('Safari')) != -1) { | ||
else if ((verOffset = nAgt.indexOf('Safari')) !== -1) { | ||
browserName = 'Safari'; | ||
fullVersion = nAgt.substring(verOffset + 7); | ||
if ((verOffset = nAgt.indexOf('Version')) != -1) | ||
if ((verOffset = nAgt.indexOf('Version')) !== -1) { | ||
fullVersion = nAgt.substring(verOffset + 8); | ||
} | ||
} | ||
// In Firefox, the true version is after 'Firefox' | ||
else if ((verOffset = nAgt.indexOf('Firefox')) != -1) { | ||
else if ((verOffset = nAgt.indexOf('Firefox')) !== -1) { | ||
browserName = 'Firefox'; | ||
@@ -219,3 +284,4 @@ fullVersion = nAgt.substring(verOffset + 8); | ||
fullVersion = nAgt.substring(verOffset + 1); | ||
if (browserName.toLowerCase() == browserName.toUpperCase()) { | ||
if (browserName.toLowerCase() === browserName.toUpperCase()) { | ||
browserName = navigator.appName; | ||
@@ -225,6 +291,12 @@ } | ||
// trim the fullVersion string at semicolon/space if present | ||
if ((ix = fullVersion.indexOf(';')) != -1) fullVersion = fullVersion.substring(0, ix); | ||
if ((ix = fullVersion.indexOf(' ')) != -1) fullVersion = fullVersion.substring(0, ix); | ||
if ((ix = fullVersion.indexOf(';')) !== -1) { | ||
fullVersion = fullVersion.substring(0, ix); | ||
} | ||
if ((ix = fullVersion.indexOf(' ')) !== -1) { | ||
fullVersion = fullVersion.substring(0, ix); | ||
} | ||
majorVersion = parseInt('' + fullVersion, 10); | ||
if (isNaN(majorVersion)) { | ||
@@ -250,10 +322,11 @@ fullVersion = '' + parseFloat(navigator.appVersion); | ||
}); | ||
if (window.mozRTCPeerConnection) { // FF needs a channel/stream to proceed | ||
rtc.createDataChannel('', { | ||
reliable: false | ||
}); | ||
}; | ||
rtc.createDataChannel('', { | ||
reliable: false | ||
}); | ||
rtc.onicecandidate = function(evt) { | ||
if (evt.candidate) grepSDP(evt.candidate.candidate); | ||
if (evt.candidate) { | ||
grepSDP(evt.candidate.candidate); | ||
} | ||
}; | ||
@@ -264,29 +337,41 @@ rtc.createOffer(function(offerDesc) { | ||
}, function(e) { | ||
console.warn("offer failed", e); | ||
console.warn('offer failed', e); | ||
}, { | ||
mandatory: { | ||
OfferToReceiveAudio: false, | ||
OfferToReceiveVideo: false | ||
}, | ||
optional: [] | ||
}); | ||
var addrs = Object.create(null); | ||
addrs["0.0.0.0"] = false; | ||
addrs['0.0.0.0'] = false; | ||
function updateDisplay(newAddr) { | ||
if (newAddr in addrs) return; | ||
else addrs[newAddr] = true; | ||
if (newAddr in addrs) { | ||
return; | ||
} else { | ||
addrs[newAddr] = true; | ||
} | ||
var displayAddrs = Object.keys(addrs).filter(function(k) { | ||
return addrs[k]; | ||
}); | ||
callback(displayAddrs.join(" or perhaps ") || "n/a"); | ||
callback(displayAddrs.join(' or perhaps ') || 'n/a'); | ||
} | ||
function grepSDP(sdp) { | ||
var hosts = []; | ||
sdp.split('\r\n').forEach(function(line) { // c.f. http://tools.ietf.org/html/rfc4566#page-39 | ||
if (~line.indexOf("a=candidate")) { // http://tools.ietf.org/html/rfc4566#section-5.13 | ||
var parts = line.split(' '), // http://tools.ietf.org/html/rfc5245#section-15.1 | ||
addr = parts[4], | ||
type = parts[7]; | ||
if (type === 'host') updateDisplay(addr); | ||
} else if (~line.indexOf("c=")) { // http://tools.ietf.org/html/rfc4566#section-5.7 | ||
var parts = line.split(' '), | ||
addr = parts[2]; | ||
var hosts = [], | ||
parts, addr, type; | ||
sdp.split('\r\n').forEach(function(line) { | ||
if (~line.indexOf('candidate:')) { | ||
parts = line.split(' '); | ||
addr = parts[4]; | ||
type = parts[7]; | ||
if (type === 'host') { | ||
updateDisplay(addr); | ||
} | ||
} else if (~line.indexOf('c=')) { | ||
parts = line.split(' '); | ||
addr = parts[2]; | ||
updateDisplay(addr); | ||
@@ -297,3 +382,3 @@ } | ||
})(); | ||
} | ||
}; | ||
})(); |
{ | ||
"name": "detectrtc", | ||
"preferGlobal": true, | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": { | ||
@@ -39,4 +39,15 @@ "name": "Muaz Khan", | ||
"homepage": "https://www.webrtc-experiment.com/DetectRTC/", | ||
"_id": "detectrtc@1.0.1", | ||
"_from": "detectrtc@" | ||
"_id": "detectrtc@", | ||
"_from": "detectrtc@", | ||
"devDependencies": { | ||
"grunt": "latest", | ||
"grunt-cli": "latest", | ||
"load-grunt-tasks": "latest", | ||
"grunt-contrib-concat": "latest", | ||
"grunt-contrib-csslint": "latest", | ||
"grunt-contrib-jshint": "latest", | ||
"grunt-contrib-uglify": "latest", | ||
"grunt-jsbeautifier": "latest", | ||
"grunt-bump": "latest" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
## [DetectRTC.js](https://github.com/muaz-khan/DetectRTC) / [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) | ||
# [DetectRTC.js](https://github.com/muaz-khan/DetectRTC) / [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) | ||
@@ -9,2 +9,5 @@ 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. | ||
npm install detectrtc | ||
# or | ||
bower install detectrtc | ||
``` | ||
@@ -14,21 +17,16 @@ | ||
```htm | ||
```html | ||
<script src="./node_modules/detectrtc/DetectRTC.js"></script> | ||
``` | ||
## Link the library | ||
```html | ||
<!-- or CDN link --> | ||
<script src="//cdn.webrtc-experiment.com/DetectRTC.js"></script> | ||
``` | ||
<img src="https://cdn.webrtc-experiment.com/images/DetectRTC.png" style="width:100%;" /> | ||
**Check all releases:** | ||
## How to use it? | ||
* https://github.com/muaz-khan/DetectRTC/releases | ||
```html | ||
<script src="//cdn.webrtc-experiment.com/DetectRTC.js"></script> | ||
``` | ||
<img src="https://cdn.webrtc-experiment.com/images/DetectRTC.png" style="width:100%;" /> | ||
## List of available detections | ||
# How to use it? | ||
@@ -69,18 +67,8 @@ ```javascript | ||
## Demo | ||
# Demo | ||
* https://www.webrtc-experiment.com/DetectRTC/ | ||
## Credits | ||
# License | ||
[Muaz Khan](https://github.com/muaz-khan): | ||
1. Personal Webpage: http://www.muazkhan.com | ||
2. Email: muazkh@gmail.com | ||
3. Twitter: https://twitter.com/muazkh and https://twitter.com/WebRTCWeb | ||
4. Google+: https://plus.google.com/+WebRTC-Experiment | ||
5. Facebook: https://www.facebook.com/WebRTC | ||
## License | ||
[DetectRTC.js](https://github.com/muaz-khan/DetectRTC) is released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](https://plus.google.com/+MuazKhan). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
300
17025
9
3
72