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