1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 | var Device = (function () {
|
6 | function Device(deps) {
|
7 | this.deps = deps;
|
8 | this.native = this.deps.nativeDevice;
|
9 | this.emitter = this.deps.emitter;
|
10 | this.type = this.determineDeviceType();
|
11 | this.registerEventHandlers();
|
12 | }
|
13 | Device.prototype.isAndroid = function () {
|
14 | return this.type === 'android';
|
15 | };
|
16 | Device.prototype.isIOS = function () {
|
17 | return this.type === 'iphone' || this.type === 'ipad';
|
18 | };
|
19 | Device.prototype.isConnectedToNetwork = function (options) {
|
20 | if (options === void 0) { options = {}; }
|
21 | if (typeof navigator.connection === 'undefined' ||
|
22 | typeof navigator.connection.type === 'undefined' ||
|
23 | typeof Connection === 'undefined') {
|
24 | if (!options.strictMode) {
|
25 | return true;
|
26 | }
|
27 | return false;
|
28 | }
|
29 | switch (navigator.connection.type) {
|
30 | case Connection.ETHERNET:
|
31 | case Connection.WIFI:
|
32 | case Connection.CELL_2G:
|
33 | case Connection.CELL_3G:
|
34 | case Connection.CELL_4G:
|
35 | case Connection.CELL:
|
36 | return true;
|
37 | default:
|
38 | return false;
|
39 | }
|
40 | };
|
41 | |
42 |
|
43 |
|
44 | Device.prototype.registerEventHandlers = function () {
|
45 | var _this = this;
|
46 | if (this.type === 'unknown') {
|
47 | this.emitter.emit('device:ready');
|
48 | }
|
49 | else {
|
50 | this.emitter.once('cordova:deviceready', function () {
|
51 | _this.emitter.emit('device:ready');
|
52 | });
|
53 | }
|
54 | };
|
55 | |
56 |
|
57 |
|
58 | Device.prototype.determineDeviceType = function () {
|
59 | var agent = navigator.userAgent;
|
60 | var ipad = agent.match(/iPad/i);
|
61 | if (ipad && (ipad[0].toLowerCase() === 'ipad')) {
|
62 | return 'ipad';
|
63 | }
|
64 | var iphone = agent.match(/iPhone/i);
|
65 | if (iphone && (iphone[0].toLowerCase() === 'iphone')) {
|
66 | return 'iphone';
|
67 | }
|
68 | var android = agent.match(/Android/i);
|
69 | if (android && (android[0].toLowerCase() === 'android')) {
|
70 | return 'android';
|
71 | }
|
72 | return 'unknown';
|
73 | };
|
74 | return Device;
|
75 | }());
|
76 | exports.Device = Device;
|
77 |
|
\ | No newline at end of file |