commonroutesServer/www/plugins/cordova-plugin-device/src/browser/DeviceProxy.js
www/plugins/cordova-plugin-device/src/browser/DeviceProxy.jsRaw
1/*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21var browser = require('cordova/platform');
22
23function getPlatform() {
24 return "browser";
25}
26
27function getModel() {
28 return getBrowserInfo(true);
29}
30
31function getVersion() {
32 return getBrowserInfo(false);
33}
34
35function getBrowserInfo(getModel) {
36 var userAgent = navigator.userAgent;
37 var returnVal = '';
38 var offset;
39
40 if ((offset = userAgent.indexOf('Chrome')) !== -1) {
41 returnVal = (getModel) ? 'Chrome' : userAgent.substring(offset + 7);
42 } else if ((offset = userAgent.indexOf('Safari')) !== -1) {
43 if (getModel) {
44 returnVal = 'Safari';
45 } else {
46 returnVal = userAgent.substring(offset + 7);
47
48 if ((offset = userAgent.indexOf('Version')) !== -1) {
49 returnVal = userAgent.substring(offset + 8);
50 }
51 }
52 } else if ((offset = userAgent.indexOf('Firefox')) !== -1) {
53 returnVal = (getModel) ? 'Firefox' : userAgent.substring(offset + 8);
54 } else if ((offset = userAgent.indexOf('MSIE')) !== -1) {
55 returnVal = (getModel) ? 'MSIE' : userAgent.substring(offset + 5);
56 } else if ((offset = userAgent.indexOf('Trident')) !== -1) {
57 returnVal = (getModel) ? 'MSIE' : '11';
58 }
59
60 if ((offset = returnVal.indexOf(';')) !== -1 || (offset = returnVal.indexOf(' ')) !== -1) {
61 returnVal = returnVal.substring(0, offset);
62 }
63
64 return returnVal;
65}
66
67
68module.exports = {
69 getDeviceInfo: function (success, error) {
70 setTimeout(function () {
71 success({
72 cordova: browser.cordovaVersion,
73 platform: getPlatform(),
74 model: getModel(),
75 version: getVersion(),
76 uuid: null
77 });
78 }, 0);
79 }
80};
81
82require("cordova/exec/proxy").add("Device", module.exports);