openEventsPlatformApp/plugins/cordova-plugin-device/www/device.js
plugins/cordova-plugin-device/www/device.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*/
21
22var argscheck = require('cordova/argscheck'),
23 channel = require('cordova/channel'),
24 utils = require('cordova/utils'),
25 exec = require('cordova/exec'),
26 cordova = require('cordova');
27
28channel.createSticky('onCordovaInfoReady');
29// Tell cordova channel to wait on the CordovaInfoReady event
30channel.waitForInitialization('onCordovaInfoReady');
31
32/**
33 * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
34 * phone, etc.
35 * @constructor
36 */
37function Device() {
38 this.available = false;
39 this.platform = null;
40 this.version = null;
41 this.uuid = null;
42 this.cordova = null;
43 this.model = null;
44 this.manufacturer = null;
45 this.isVirtual = null;
46 this.serial = null;
47
48 var me = this;
49
50 channel.onCordovaReady.subscribe(function() {
51 me.getInfo(function(info) {
52 //ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
53 //TODO: CB-5105 native implementations should not return info.cordova
54 var buildLabel = cordova.version;
55 me.available = true;
56 me.platform = info.platform;
57 me.version = info.version;
58 me.uuid = info.uuid;
59 me.cordova = buildLabel;
60 me.model = info.model;
61 me.isVirtual = info.isVirtual;
62 me.manufacturer = info.manufacturer || 'unknown';
63 me.serial = info.serial || 'unknown';
64 channel.onCordovaInfoReady.fire();
65 },function(e) {
66 me.available = false;
67 utils.alert("[ERROR] Error initializing Cordova: " + e);
68 });
69 });
70}
71
72/**
73 * Get device info
74 *
75 * @param {Function} successCallback The function to call when the heading data is available
76 * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
77 */
78Device.prototype.getInfo = function(successCallback, errorCallback) {
79 argscheck.checkArgs('fF', 'Device.getInfo', arguments);
80 exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
81};
82
83module.exports = new Device();