@cardsjd/device 0.1.14 → 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.
Files changed (2) hide show
  1. package/lib/device.js +29 -8
  2. package/package.json +2 -4
package/lib/device.js CHANGED
@@ -54,6 +54,14 @@ export default class Device {
54
54
  * @returns {OSType}
55
55
  */
56
56
  getOS() {
57
+ this.#staticWarn('getOS');
58
+ return Device.getOS();
59
+ }
60
+
61
+ /**
62
+ * @returns {OSType}
63
+ */
64
+ static getOS() {
57
65
  const ua = navigator.userAgent;
58
66
 
59
67
  if (/(MSAppHost\/3.0)/i.test(navigator.appVersion)) {
@@ -87,16 +95,29 @@ export default class Device {
87
95
  return navigator.userAgent;
88
96
  }
89
97
 
98
+ /** @typedef {'facebook' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'steam' | 'windowsPWA' | 'web' | 'CrazyGames' | 'GameDistribution' | 'poki'} PlatformType */
99
+
90
100
  /**
91
101
  * @returns {PlatformType}
92
102
  */
93
103
  getPlatform() {
104
+ this.#staticWarn('getPlatform');
105
+ return Device.getPlatform();
106
+ }
94
107
 
108
+ /**
109
+ * @returns {PlatformType}
110
+ */
111
+ static getPlatform() {
95
112
  //Get override information
96
113
  const searchParams = new URLSearchParams(window.location.search);
97
114
 
98
115
  //discord has a platform in its url and messes up detection //detect first
99
- if (window.location.host.includes('discord') || (window.location.href.includes("localhost") && window.location.href.includes("frame_id"))) {
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
+ ) {
100
121
  return 'discord';
101
122
  }
102
123
 
@@ -110,14 +131,12 @@ export default class Device {
110
131
  return 'facebook';
111
132
  }
112
133
 
113
- if (typeof globalThis.CrazyGames !== 'undefined') {
114
- return 'crazygames';
115
- }
116
- if (globalThis.location?.ancestorOrigins?.[0]?.includes("crazygames")) {
134
+ if (typeof globalThis.CrazyGames !== 'undefined' || globalThis.location?.ancestorOrigins?.[0]?.includes('crazygames')) {
117
135
  return 'crazygames';
118
136
  }
119
- if (globalThis.location?.ancestorOrigins?.[0]?.includes("discord")) {
120
- return 'discord';
137
+
138
+ if (typeof globalThis.PokiSDK !== 'undefined' || globalThis.location?.ancestorOrigins?.[0]?.includes('poki')) {
139
+ return 'poki';
121
140
  }
122
141
 
123
142
  //native Cordova
@@ -163,6 +182,8 @@ export default class Device {
163
182
  return 'web';
164
183
  }
165
184
 
166
- /** @typedef {'facebook' | 'windowsPhone' | 'windows' | 'amazon' | 'android' | 'ios' | 'steam' | 'windowsPWA' | 'web' | 'crazygames'} PlatformType */
185
+ #staticWarn(methodName) {
186
+ console.warn(`Please call the static method Device.${methodName}() instead`);
187
+ }
167
188
 
168
189
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cardsjd/device",
3
3
  "private": false,
4
- "version": "0.1.14",
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
  }