@cardsjd/device 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/device.js +50 -19
- package/package.json +2 -4
package/lib/device.js
CHANGED
|
@@ -29,21 +29,39 @@ export default class Device {
|
|
|
29
29
|
window.close();
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
getDeviceID() {
|
|
33
|
+
var deviceId = null;
|
|
34
|
+
if (this.storageAvailable('localStorage')) {
|
|
35
|
+
deviceId = localStorage.getItem('deviceId');
|
|
36
|
+
if (!deviceId) {
|
|
37
|
+
deviceId = Math.floor(Math.random() * Math.floor(1000000000000));
|
|
38
|
+
if (this.storageAvailable('localStorage')) localStorage.deviceId = deviceId;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return deviceId;
|
|
42
|
+
}
|
|
43
|
+
storageAvailable(type) {
|
|
44
|
+
try {
|
|
45
|
+
const storage = globalThis[type], x = '__storage_test__';
|
|
46
|
+
storage.setItem(x, x);
|
|
47
|
+
storage.removeItem(x);
|
|
48
|
+
return true;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
43
53
|
/**
|
|
44
54
|
* @returns {OSType}
|
|
45
55
|
*/
|
|
46
56
|
getOS() {
|
|
57
|
+
this.#staticWarn('getOS');
|
|
58
|
+
return Device.getOS();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @returns {OSType}
|
|
63
|
+
*/
|
|
64
|
+
static getOS() {
|
|
47
65
|
const ua = navigator.userAgent;
|
|
48
66
|
|
|
49
67
|
if (/(MSAppHost\/3.0)/i.test(navigator.appVersion)) {
|
|
@@ -77,16 +95,29 @@ export default class Device {
|
|
|
77
95
|
return navigator.userAgent;
|
|
78
96
|
}
|
|
79
97
|
|
|
98
|
+
/** @typedef {'facebook' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'steam' | 'windowsPWA' | 'web' | 'CrazyGames' | 'GameDistribution' | 'poki'} PlatformType */
|
|
99
|
+
|
|
80
100
|
/**
|
|
81
101
|
* @returns {PlatformType}
|
|
82
102
|
*/
|
|
83
103
|
getPlatform() {
|
|
104
|
+
this.#staticWarn('getPlatform');
|
|
105
|
+
return Device.getPlatform();
|
|
106
|
+
}
|
|
84
107
|
|
|
108
|
+
/**
|
|
109
|
+
* @returns {PlatformType}
|
|
110
|
+
*/
|
|
111
|
+
static getPlatform() {
|
|
85
112
|
//Get override information
|
|
86
113
|
const searchParams = new URLSearchParams(window.location.search);
|
|
87
114
|
|
|
88
115
|
//discord has a platform in its url and messes up detection //detect first
|
|
89
|
-
if (
|
|
116
|
+
if (
|
|
117
|
+
window.location.host.includes('discord') ||
|
|
118
|
+
(window.location.href.includes('localhost') && window.location.href.includes('frame_id')) ||
|
|
119
|
+
globalThis.location?.ancestorOrigins?.[0]?.includes('discord')
|
|
120
|
+
) {
|
|
90
121
|
return 'discord';
|
|
91
122
|
}
|
|
92
123
|
|
|
@@ -100,14 +131,12 @@ export default class Device {
|
|
|
100
131
|
return 'facebook';
|
|
101
132
|
}
|
|
102
133
|
|
|
103
|
-
if (typeof globalThis.CrazyGames !== 'undefined') {
|
|
134
|
+
if (typeof globalThis.CrazyGames !== 'undefined' || globalThis.location?.ancestorOrigins?.[0]?.includes('crazygames')) {
|
|
104
135
|
return 'crazygames';
|
|
105
136
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (globalThis.location?.ancestorOrigins?.[0]?.includes("discord")) {
|
|
110
|
-
return 'discord';
|
|
137
|
+
|
|
138
|
+
if (typeof globalThis.PokiSDK !== 'undefined' || globalThis.location?.ancestorOrigins?.[0]?.includes('poki')) {
|
|
139
|
+
return 'poki';
|
|
111
140
|
}
|
|
112
141
|
|
|
113
142
|
//native Cordova
|
|
@@ -153,6 +182,8 @@ export default class Device {
|
|
|
153
182
|
return 'web';
|
|
154
183
|
}
|
|
155
184
|
|
|
156
|
-
|
|
185
|
+
#staticWarn(methodName) {
|
|
186
|
+
console.warn(`Please call the static method Device.${methodName}() instead`);
|
|
187
|
+
}
|
|
157
188
|
|
|
158
189
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardsjd/device",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"files": [
|
|
@@ -11,10 +11,8 @@
|
|
|
11
11
|
"lint": "eslint lib --report-unused-disable-directives --max-warnings 0",
|
|
12
12
|
"lint:fix": "npm run lint -- --fix"
|
|
13
13
|
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@capacitor/core": "^6.0.0"
|
|
16
|
-
},
|
|
17
14
|
"peerDependencies": {
|
|
15
|
+
"@capacitor/core": ">=7 <9",
|
|
18
16
|
"@sagi.io/globalthis": "^0.0.2"
|
|
19
17
|
}
|
|
20
18
|
}
|