-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdetect.js
86 lines (69 loc) · 2.66 KB
/
detect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* jshint node: true */
/* global window: false */
/* global navigator: false */
'use strict';
var browser = require('detect-browser').detect();
/**
### `rtc-core/detect`
A browser detection helper for accessing prefix-free versions of the various
WebRTC types.
### Example Usage
If you wanted to get the native `RTCPeerConnection` prototype in any browser
you could do the following:
```js
var detect = require('rtc-core/detect'); // also available in rtc/detect
var RTCPeerConnection = detect('RTCPeerConnection');
```
This would provide whatever the browser prefixed version of the
RTCPeerConnection is available (`webkitRTCPeerConnection`,
`mozRTCPeerConnection`, etc).
**/
var detect = module.exports = function(target, opts) {
var attach = (opts || {}).attach;
var prefixIdx;
var prefix;
var testName;
var hostObject = this || (typeof window != 'undefined' ? window : undefined);
// initialise to default prefixes
// (reverse order as we use a decrementing for loop)
var prefixes = ((opts || {}).prefixes || ['ms', 'o', 'moz', 'webkit']).concat('');
// if we have no host object, then abort
if (! hostObject) {
return;
}
// iterate through the prefixes and return the class if found in global
for (prefixIdx = prefixes.length; prefixIdx--; ) {
prefix = prefixes[prefixIdx];
// construct the test class name
// if we have a prefix ensure the target has an uppercase first character
// such that a test for getUserMedia would result in a
// search for webkitGetUserMedia
testName = prefix + (prefix ?
target.charAt(0).toUpperCase() + target.slice(1) :
target);
if (typeof hostObject[testName] != 'undefined') {
// update the last used prefix
detect.browser = detect.browser || prefix.toLowerCase();
if (attach) {
hostObject[target] = hostObject[testName];
}
return hostObject[testName];
}
}
};
// detect mozilla (yes, this feels dirty)
detect.moz = typeof navigator != 'undefined' && !!navigator.mozGetUserMedia;
// Newer Ipad versions cannot be detected just using useragent
// And detect-browser does not plan to implement this feature (ref: https://github.com/DamonOehlman/detect-browser/issues/163)
// Ref: https://stackoverflow.com/questions/9038625/detect-if-device-is-ios/58065241#58065241
const isIosMimic =
navigator && navigator.maxTouchPoints &&
navigator.maxTouchPoints > 2 &&
/MacIntel/.test(navigator.platform);
// set the browser and browser version
detect.browser = browser.name;
detect.browserVersion = detect.version = browser.version;
detect.os = browser.os;
if(isIosMimic) {
detect.os = 'iOS';
}