forked from plivo/browsercheck-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowsercheck.js
229 lines (226 loc) · 6.12 KB
/
browsercheck.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
window.PlivoCheck = class PlivoCheck {
constructor() {
this._version = "2.0";
BrowserDetect.init();
this.browser = BrowserDetect.browser;
this.browserVersion = BrowserDetect.version;
this.browserFullVersion = BrowserDetect.fullVersion;
this.OS = BrowserDetect.OS;
this.fullOS = BrowserDetect.fullOS;
}
// return the version
version() {
return this._version;
}
// verify the browser supports Websocket with a function checkWebSocket
checkWebSocket() {
if ("WebSocket" in window) {
if (typeof(WebSocket) == "function") {
return true;
}
}
return false;
}
// DEPRECATED verify the browser supports Flash with a function checkFlash
checkFlash() {
console.log("checkFlash function is deprecated.");
return false;
}
// DEPRECATED get the Flash version with a function getFlashVer
getFlashVer() {
console.log("getFlashVer function is deprecated.");
return "0.0.0";
}
// verify the browser with a function checkBrowser
checkBrowser() {
return [this.browser, this.browserFullVersion];
}
// verify the OS with a function checkOS
checkOS() {
return this.OS;
}
// DEPRECATED verify the browser supports the microphone with a function checkMic
checkMic() {
console.log("checkMic function is deprecated.");
return true;
}
// verify the browser supports WebRTC with a function checkWebRTC
checkWebRTC() {
var webrtc_support = navigator.mediaDevices.getUserMedia || navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || window.RTCPeerConnection || window.PeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection
if (!webrtc_support) {
return false;
}
return true;
}
// verify the browser supports mediaDevices with a function checkMediaDevices
checkMediaDevices() {
if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices && navigator.mediaDevices.getUserMedia) {
return true;
}
return false;
}
// list the media devices with a function listMediaDevices
// return a Promise
listMediaDevices() {
if (!this.checkMediaDevices()) {
console.log("navigator.mediaDevices is not supported by your browser.");
return Promise.reject("navigator.mediaDevices is not supported by your browser.");
} else {
return navigator.mediaDevices.getUserMedia({audio: true, video: false})
.then((stream) => {
return navigator.mediaDevices.enumerateDevices();
})
.catch((error) => {
console.log("navigator.mediaDevices.getUserMedia failed: " + error);
return Promise.reject("navigator.mediaDevices.getUserMedia failed: " + error);
});
}
}
}
// BrowserDetect
// Author Alex Ho
// Code: https://gist.github.com/mralexho/d28fb26dc6787b86522f
var BrowserDetect = {
init: function() {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent) ||
this.searchVersion(navigator.appVersion) ||
"an unknown version";
this.fullVersion = this.searchFullVersion(navigator.userAgent) ||
this.searchVersion(navigator.appVersion) ||
"an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
this.fullOS = this.searchOSVersion() || undefined;
},
searchString: function(data) {
for (var i=0;i<data.length;i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
},
searchOSVersion: function() {
var colonIndex,endIndex,closeIndex;
var osIndex = navigator.userAgent.indexOf(this.OS);
endIndex = closeIndex = navigator.userAgent.indexOf(')', osIndex);
if (this.OS == 'Windows') {
colonIndex = navigator.userAgent.indexOf(';', osIndex);
if (colonIndex > 0) {
endIndex = colonIndex < closeIndex ? colonIndex:closeIndex;
}
}
return navigator.userAgent.substring(osIndex, endIndex);
},
searchVersion: function(dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
searchFullVersion: function(dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
var temp = dataString.substring(index+this.versionSearchString.length+1);
var spaceIndex = temp.indexOf(' ');
if (spaceIndex <= 0) {
return temp;
}
var fullVersion = temp.substring(0, spaceIndex);
return fullVersion;
},
dataBrowser: [
{
string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
},
{
string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{
prop: window.opera,
identity: "Opera",
versionSearch: "Version"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{ // for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{
// for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "MacOS"
},
{
string: navigator.userAgent,
subString: "iPhone",
identity: "iPhone/iPad"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]
};