@adlad/plugin-viverse 0.7.0 → 0.9.0
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/deno.lock +5 -5
- package/dist/adlad-plugin-viverse.d.ts +2 -10
- package/dist/adlad-plugin-viverse.js +1 -1
- package/iframeBridge.js +4 -0
- package/importmap.json +1 -1
- package/package.json +6 -1
- package/src/mod.js +44 -52
package/deno.lock
CHANGED
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"@jridgewell/trace-mapping"
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
|
-
"@jridgewell/sourcemap-codec@1.
|
|
27
|
-
"integrity": "sha512-
|
|
26
|
+
"@jridgewell/sourcemap-codec@1.6.0": {
|
|
27
|
+
"integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="
|
|
28
28
|
},
|
|
29
29
|
"@jridgewell/trace-mapping@0.3.31": {
|
|
30
30
|
"integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@jridgewell/sourcemap-codec"
|
|
34
34
|
]
|
|
35
35
|
},
|
|
36
|
-
"acorn@8.
|
|
37
|
-
"integrity": "sha512-
|
|
36
|
+
"acorn@8.18.0": {
|
|
37
|
+
"integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==",
|
|
38
38
|
"bin": true
|
|
39
39
|
},
|
|
40
40
|
"buffer-from@1.1.2": {
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
},
|
|
108
108
|
"workspace": {
|
|
109
109
|
"dependencies": [
|
|
110
|
-
"npm:@adlad/adlad@1.
|
|
110
|
+
"npm:@adlad/adlad@1.1.0"
|
|
111
111
|
]
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -22,17 +22,9 @@ export function viversePlugin({ appId, }: {
|
|
|
22
22
|
}): {
|
|
23
23
|
readonly name: "viverse";
|
|
24
24
|
readonly initialize: (ctx: any) => Promise<void>;
|
|
25
|
+
readonly setStorageItem: (key: any, value: any) => Promise<void>;
|
|
26
|
+
readonly getStorageItem: (key: any) => Promise<any>;
|
|
25
27
|
readonly customRequests: {
|
|
26
|
-
/**
|
|
27
|
-
* @param {string} key
|
|
28
|
-
* @param {unknown} value
|
|
29
|
-
*/
|
|
30
|
-
readonly setStorageItem: (key: string, value: unknown) => Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* @param {string} key
|
|
33
|
-
* @returns {Promise<unknown>}
|
|
34
|
-
*/
|
|
35
|
-
readonly getStorageItem: (key: string) => Promise<unknown>;
|
|
36
28
|
readonly showAuthPrompt: () => void;
|
|
37
29
|
readonly getIsSignedIn: () => boolean;
|
|
38
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function viversePlugin({appId:e}){let t=!1;if(!e)throw new Error("No app id was provided");const a={viverse:"viverse",client:"client",clientId:"clientId",domain:"domain",cookieDomain:"cookieDomain",checkAuth:"checkAuth",loginWithWorlds:"loginWithWorlds",storage:"storage",newCloudSaveClient:"newCloudSaveClient",setPlayerData:"setPlayerData",getPlayerData:"getPlayerData",avatar:"avatar",baseURL:"baseURL",token:"token"};let i,o;a>0&&console.log(a);let n=null,s=null;const l=new Map,r="adlad_viverse_";return{name:"viverse",async initialize(s){if(t)throw new Error("Viverse plugin is being initialized more than once");if(t=!0,await s.loadScriptTag("https://www.viverse.com/static-assets/viverse-sdk/index.umd.cjs"),i=new globalThis[a.viverse][a.client]({[a.clientId]:e,[a.domain]:"account.htcvive.com",[a.cookieDomain]:window.location.hostname}),window.parent==window)throw new Error("The Viverse SDK is not supported unless the game is embedded on viverse.com.");const l=await i[a.checkAuth]();n=l?.access_token||null;const r=new globalThis[a.viverse][a.storage];o=await r[a.newCloudSaveClient](e)},
|
|
1
|
+
function viversePlugin({appId:e}){let t=!1;if(!e)throw new Error("No app id was provided");const a={viverse:"viverse",client:"client",clientId:"clientId",domain:"domain",cookieDomain:"cookieDomain",checkAuth:"checkAuth",loginWithWorlds:"loginWithWorlds",storage:"storage",newCloudSaveClient:"newCloudSaveClient",setPlayerData:"setPlayerData",getPlayerData:"getPlayerData",avatar:"avatar",baseURL:"baseURL",token:"token"};let i,o;a>0&&console.log(a);let n=null,s=null;const l=new Map,r="adlad_viverse_";return{name:"viverse",async initialize(s){if(t)throw new Error("Viverse plugin is being initialized more than once");if(t=!0,await s.loadScriptTag("https://www.viverse.com/static-assets/viverse-sdk/index.umd.cjs"),i=new globalThis[a.viverse][a.client]({[a.clientId]:e,[a.domain]:"account.htcvive.com",[a.cookieDomain]:window.location.hostname}),window.parent==window)throw new Error("The Viverse SDK is not supported unless the game is embedded on viverse.com.");const l=await i[a.checkAuth]();n=l?.access_token||null;const r=new globalThis[a.viverse][a.storage];o=await r[a.newCloudSaveClient](e)},async setStorageItem(e,t){const i=JSON.stringify(t);if(n)await o[a.setPlayerData](e,{s:i},n);else{await new Promise((e=>setTimeout(e,1e3)));try{localStorage.setItem(r+e,i)}catch{l.set(e,i)}}},async getStorageItem(e){let t;if(n){const i=await o[a.getPlayerData](e,n);t="object"==typeof i&&null!=i?i.s:null}else{await new Promise((e=>setTimeout(e,1e3)));try{t=localStorage.getItem(r+e)}catch{t=l.get(e)}}return t&&"string"==typeof t?JSON.parse(t):null},customRequests:{showAuthPrompt(){i[a.loginWithWorlds]()},getIsSignedIn:()=>Boolean(n),async getProfile(){const e=n?(s||(s=new viverse[a.avatar]({[a.baseURL]:"https://sdk-api.viverse.com/",[a.token]:n})),s):null;return e?await e.getProfile():null}}}}export{viversePlugin as default,viversePlugin};
|
package/iframeBridge.js
ADDED
package/importmap.json
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adlad/plugin-viverse",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "AdLad plugin for the Viverse sdk.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "mod.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./mod.js",
|
|
9
|
+
"./iframeBridge": "./iframeBridge.js"
|
|
10
|
+
},
|
|
6
11
|
"types": "dist/adlad-plugin-viverse.d.ts",
|
|
7
12
|
"repository": {
|
|
8
13
|
"type": "git",
|
package/src/mod.js
CHANGED
|
@@ -111,61 +111,53 @@ export function viversePlugin({
|
|
|
111
111
|
const storageClient = new globalThis[props.viverse][props.storage]();
|
|
112
112
|
cloudSaveClient = await storageClient[props.newCloudSaveClient](appId);
|
|
113
113
|
},
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
localStorage.setItem(localStoragePrefix + key, stringifiedValue);
|
|
136
|
-
} catch {
|
|
137
|
-
// The user is probably using private browsing, we'll fallback to session storage
|
|
138
|
-
sessionStorage.set(key, stringifiedValue);
|
|
139
|
-
}
|
|
114
|
+
async setStorageItem(key, value) {
|
|
115
|
+
// The Viverse SDK doesn't allow passing raw values such as `true` or `42`,
|
|
116
|
+
// but since this is quite common, we'll add support for this by stringifying the provided value.
|
|
117
|
+
// This does mean the SDK will probably stringify it a second time, but oh well.
|
|
118
|
+
const stringifiedValue = JSON.stringify(value);
|
|
119
|
+
if (accessToken) {
|
|
120
|
+
// If you give the viverse sdk a json string as input, the sdk will try to parse it.
|
|
121
|
+
// This is rather unexpected however, because if a develoepr calls `setStorageItem("foo", "42")`,
|
|
122
|
+
// they expect to get exactly `"42"` back when calling `getStorageItem("foo")`.
|
|
123
|
+
// So in order to prevent the sdk from parsing our strings, we'll just provide an object.
|
|
124
|
+
await cloudSaveClient[props.setPlayerData](key, { s: stringifiedValue }, accessToken);
|
|
125
|
+
} else {
|
|
126
|
+
// Calls to the viverse sdk normally do not resolve instantly, which might cause bugs in the application.
|
|
127
|
+
// Let's simulate this behavior so it's easier to reproduce these issues in local development.
|
|
128
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
129
|
+
try {
|
|
130
|
+
localStorage.setItem(localStoragePrefix + key, stringifiedValue);
|
|
131
|
+
} catch {
|
|
132
|
+
// The user is probably using private browsing, we'll fallback to session storage
|
|
133
|
+
sessionStorage.set(key, stringifiedValue);
|
|
140
134
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
/** @type {{s: string}} */ (await cloudSaveClient[props.getPlayerData](key, accessToken));
|
|
151
|
-
if (typeof objectifiedValue == "object" && objectifiedValue != null) {
|
|
152
|
-
stringifiedValue = objectifiedValue.s;
|
|
153
|
-
} else {
|
|
154
|
-
stringifiedValue = null;
|
|
155
|
-
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
async getStorageItem(key) {
|
|
138
|
+
let stringifiedValue;
|
|
139
|
+
if (accessToken) {
|
|
140
|
+
const objectifiedValue =
|
|
141
|
+
/** @type {{s: string}} */ (await cloudSaveClient[props.getPlayerData](key, accessToken));
|
|
142
|
+
if (typeof objectifiedValue == "object" && objectifiedValue != null) {
|
|
143
|
+
stringifiedValue = objectifiedValue.s;
|
|
156
144
|
} else {
|
|
157
|
-
|
|
158
|
-
// Let's simulate this behavior so it's easier to reproduce these issues in local development.
|
|
159
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
160
|
-
try {
|
|
161
|
-
stringifiedValue = localStorage.getItem(localStoragePrefix + key);
|
|
162
|
-
} catch {
|
|
163
|
-
stringifiedValue = sessionStorage.get(key);
|
|
164
|
-
}
|
|
145
|
+
stringifiedValue = null;
|
|
165
146
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
147
|
+
} else {
|
|
148
|
+
// Calls to the viverse sdk normally do not resolve instantly, which might cause bugs in the application.
|
|
149
|
+
// Let's simulate this behavior so it's easier to reproduce these issues in local development.
|
|
150
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
151
|
+
try {
|
|
152
|
+
stringifiedValue = localStorage.getItem(localStoragePrefix + key);
|
|
153
|
+
} catch {
|
|
154
|
+
stringifiedValue = sessionStorage.get(key);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!stringifiedValue || typeof stringifiedValue != "string") return null;
|
|
158
|
+
return JSON.parse(stringifiedValue);
|
|
159
|
+
},
|
|
160
|
+
customRequests: {
|
|
169
161
|
showAuthPrompt() {
|
|
170
162
|
client[props.loginWithWorlds]();
|
|
171
163
|
},
|