@adlad/plugin-viverse 0.2.0 → 0.3.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/dist/adlad-plugin-viverse.js +1 -1
- package/package.json +1 -1
- package/src/mod.js +7 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
function viversePlugin({appId:e,domain:t="account.htcvive.com",cookieDomain:
|
|
1
|
+
function viversePlugin({appId:e,domain:t="account.htcvive.com",cookieDomain:i}){let a=!1;if(!e)throw new Error("No app id was provided");const o={viverse:"viverse",client:"client",clientId:"clientId",domain:"domain",cookieDomain:"cookieDomain",checkAuth:"checkAuth",loginWithWorlds:"loginWithWorlds",storage:"storage",newCloudSaveClient:"newCloudSaveClient",setPlayerData:"setPlayerData",getPlayerData:"getPlayerData"};let n,s;o>0&&console.log(o);let r=null;const l=new Map,c="adlad_viverse_";return{name:"viverse",async initialize(l){if(a)throw new Error("Viverse plugin is being initialized more than once");if(a=!0,await l.loadScriptTag("https://www.viverse.com/static-assets/viverse-sdk/index.umd.cjs"),n=new globalThis[o.viverse][o.client]({[o.clientId]:e,[o.domain]:t,[o.cookieDomain]:i}),window.parent==window)throw new Error("The Viverse SDK is not supported unless the game is embedded on the viverse.com.");const c=await n[o.checkAuth]();r=c?.access_token||null;const d=new globalThis[o.viverse][o.storage];s=await d[o.newCloudSaveClient](e)},customRequests:{async setStorageItem(e,t){const i=JSON.stringify(t);if(r)await s[o.setPlayerData](e,i,r);else try{localStorage.setItem(c+e,i)}catch{l.set(e,i)}},async getStorageItem(e){let t;if(r)t=await s[o.getPlayerData](e,r);else try{t=localStorage.getItem(c+e)}catch{t=l.get(e)}return t&&"string"==typeof t?JSON.parse(t):null},showAuthPrompt(){n[o.loginWithWorlds]()}}}}export{viversePlugin};
|
package/package.json
CHANGED
package/src/mod.js
CHANGED
|
@@ -68,6 +68,13 @@ export function viversePlugin({
|
|
|
68
68
|
[props.cookieDomain]: cookieDomain,
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
+
// If we're not running in an iframe, the client.checkAuth() promise stays pending forever.
|
|
72
|
+
// But since it is pretty common to run games in local development without an iframe, we'll also make this check here and throw an error.
|
|
73
|
+
// That way at least some of the api calls stay working.
|
|
74
|
+
if (window.parent == window) {
|
|
75
|
+
throw new Error("The Viverse SDK is not supported unless the game is embedded on the viverse.com.");
|
|
76
|
+
}
|
|
77
|
+
|
|
71
78
|
const authResult = await client[props.checkAuth]();
|
|
72
79
|
accessToken = authResult?.access_token || null;
|
|
73
80
|
|