com.robotsquid.squidhub 0.5.12 → 0.5.13
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// GENERATED FILE — do not edit by hand.
|
|
2
2
|
// Source: engine/bridge-entry.js. Regenerate: npm run generate
|
|
3
3
|
// Installs window.SquidHub. Load it BEFORE your engine's bootstrap.
|
|
4
|
-
"use strict";(()=>{var
|
|
4
|
+
"use strict";(()=>{var v="squidhub",M=["https://robotsquid.dev","https://robotsquid.com"],I=["saves.get","saves.put","analytics.track","commerce.purchase"];var i=class extends Error{code;retryAfter;constructor(e,n,r){super(n,r?.cause!==void 0?{cause:r.cause}:void 0),this.name="SquidHubError",this.code=e,r?.retryAfter!==void 0&&(this.retryAfter=r.retryAfter)}},g=class extends i{serverCopy;constructor(e){super("CONFLICT","save version conflict \u2014 another device wrote first"),this.name="SaveConflictError",this.serverCopy=e}};var C=new Set,A=new WeakSet,E=!1,x=!1,V=null,P=null,G=null;function L(t){try{t.gain.value=E?0:1}catch{}}function D(t){t.querySelectorAll("audio, video").forEach(e=>{let n=e;if(E){n.muted||(A.add(n),n.muted=!0);return}A.has(n)&&(A.delete(n),n.muted=!1)})}function _(t=window){if(x)return;x=!0,P=t.document??null;let e=["AudioContext","webkitAudioContext"];for(let n of e){let r=t[n];if(typeof r!="function")continue;let o=function(...u){let s=new r(...u);try{let p=s.destination,f=s.createGain();f.connect(p),L(f),C.add(f),Object.defineProperty(s,"destination",{configurable:!0,get:()=>f});try{let y=s.close.bind(s);s.close=()=>(C.delete(f),y())}catch{}}catch{}return s};o.prototype=r.prototype,t[n]=o}typeof t.MutationObserver=="function"&&t.document&&(V=new t.MutationObserver(n=>{let r=!1;for(let o of n){if(r)break;o.addedNodes.forEach(u=>{if(r)return;let s=u;(s.nodeName==="AUDIO"||s.nodeName==="VIDEO"||s.querySelector?.("audio, video"))&&(r=!0)})}r&&D(t.document)}),V.observe(t.document.documentElement,{childList:!0,subtree:!0}))}function U(t){E=t;for(let n of C)L(n);let e=P??(typeof document<"u"?document:null);e&&D(e);try{G?.(E)}catch{}}function J(t){if(!t)throw new i("UNTRUSTED_EMBEDDER","no referrer \u2014 the game must be embedded by the SquidHub portal");let e;try{e=new URL(t).origin}catch(n){throw new i("UNTRUSTED_EMBEDDER",`malformed referrer: ${t}`,{cause:n})}if(!M.includes(e))throw new i("UNTRUSTED_EMBEDDER",`embedder ${e} is not a SquidHub portal \u2014 refusing to hand shake`);return e}function W(t){let n=new URLSearchParams(t.replace(/^#/,"")).get("s");if(!n)throw new i("PROTOCOL","missing launch nonce \u2014 the game was not opened through the SquidHub portal");return n}var R=class{session;#n;#e=new Map;#o=0;#r;constructor(e,n,r){this.session=e,this.#n=n,this.#r=r,n.onmessage=o=>this.#s(o.data),n.start?.()}get connected(){return this.#n!==null}can(e){return this.session.capabilities.includes(e)}close(){for(let[,e]of this.#e)clearTimeout(e.timer),e.reject(new i("NOT_CONNECTED","SDK closed"));this.#e.clear(),this.#n?.close(),this.#n=null}#s(e){if(typeof e!="object"||e===null)return;let n=e;if(n.t===`${v}.audio`&&typeof n.muted=="boolean"){U(n.muted);return}if(typeof n.id!="string")return;let r=this.#e.get(n.id);if(!r)return;if(this.#e.delete(n.id),clearTimeout(r.timer),n.ok===!0){r.resolve(n.r);return}let o=n.e??{};r.reject(new i(o.code??"PROTOCOL",o.message??"request failed",o.retryAfter!==void 0?{retryAfter:o.retryAfter}:void 0))}#t(e,n){let r=this.#n;if(!r)return Promise.reject(new i("NOT_CONNECTED","SDK is not connected"));let o=`r${++this.#o}`;return new Promise((u,s)=>{let p=setTimeout(()=>{this.#e.delete(o),s(new i("TIMEOUT",`${e} timed out`))},this.#r);this.#e.set(o,{resolve:u,reject:s,timer:p}),r.postMessage({id:o,v:1,t:e,p:n})})}saves={get:()=>this.#t("saves.get",{}),put:async(e,n)=>{if(e.byteLength>8388608)throw new i("INVALID",`save is ${e.byteLength} bytes, over the ${8388608} limit`);try{return await this.#t("saves.put",{data:e,...n?.ifVersion!==void 0?{ifVersion:n.ifVersion}:{}})}catch(r){if(r instanceof i&&r.code==="CONFLICT"){let o=await this.saves.get();if(o)throw new g(o)}throw r}}};analytics={track:(e,n)=>{this.#t("analytics.track",{name:e,props:n}).catch(()=>{})}};commerce={purchase:(e,n)=>this.#t("commerce.purchase",{sku:e,idempotencyKey:n})}};async function q(t={},e=globalThis.window){let n=t.handshakeTimeoutMs??15e3,r=t.requestTimeoutMs??2e4;_(e);let o=J(e.document.referrer),u=W(e.location.hash),s=t.helloRetryMs??150;return new Promise((p,f)=>{let y,b=()=>{clearTimeout(h),y!==void 0&&clearInterval(y),e.removeEventListener("message",w)},h=setTimeout(()=>{b(),f(new i("TIMEOUT","portal did not complete the handshake"))},n);function w(d){if(d.origin!==o)return;let c=d.data;if(!c||c.t!==`${v}.ready`||c.v!==1)return;let l=d.ports[0];l&&(b(),l.start?.(),p(new R(c.session,l,r)))}e.addEventListener("message",w);let a=()=>e.parent.postMessage({t:`${v}.hello`,v:1,nonce:u},o);a(),y=setInterval(a,s)})}var $="SquidHub",H=32768;function F(t){let e="";for(let n=0;n<t.length;n+=H)e+=String.fromCharCode(...t.subarray(n,n+H));return btoa(e)}function K(t){let e=atob(t),n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}function T(t){return t instanceof Uint8Array?F(t):Array.isArray(t)?t.map(T):t&&typeof t=="object"?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,T(n)])):t}function X(t,e){let n=t[e];if(typeof n!="number"||!Number.isInteger(n))throw new i("INVALID",`${e} must be an integer, got ${JSON.stringify(n)}`);return n}function O(t,e){let n=t[e];if(typeof n!="string")throw new i("INVALID",`${e} must be a string, got ${JSON.stringify(n)}`);return n}function Y(t,e){try{return K(O(t,e))}catch(n){throw new i("INVALID",`${e} is not valid base64`,{cause:n})}}function z(t,e){let n=t[e];if(n==null)return;if(typeof n!="object"||Array.isArray(n))throw new i("INVALID",`${e} must be an object`);let r={};for(let[o,u]of Object.entries(n)){if(typeof u!="string"&&typeof u!="number"&&typeof u!="boolean")throw new i("INVALID",`${e}.${o} must be a string, number or boolean`);r[o]=u}return r}var Q={"saves.get":t=>t.saves.get(),"saves.put":(t,e)=>t.saves.put(Y(e,"data"),e.ifVersion===void 0?void 0:{ifVersion:X(e,"ifVersion")}),"analytics.track":(t,e)=>(t.analytics.track(O(e,"name"),z(e,"props")),null),"commerce.purchase":(t,e)=>t.commerce.purchase(O(e,"sku"),O(e,"idempotencyKey"))};function Z(t){return I.includes(t)}function j(t){return t instanceof i?t.code:"PROTOCOL"}function ee(t){let e=t instanceof i?t:void 0;return JSON.stringify({ok:!1,code:j(t),message:t instanceof Error?t.message:String(t),...e?.retryAfter!==void 0?{retryAfter:e.retryAfter}:{},...t instanceof g?{serverCopy:T(t.serverCopy)}:{}})}function k(t={},e=globalThis){let n=null,r="connecting",o="",u=q(t).then(a=>(n=a,r="ready",a),a=>{throw r="failed",o=`${j(a)}: ${a instanceof Error?a.message:String(a)}`,a});u.catch(()=>{});let s=new Map,p=0,f=256,y=6e4;function b(a,d){let c=Date.now();if(s.size>=f){let l=!1;for(let[m,S]of s)c-S.at>y&&(s.delete(m),l=!0);if(!l){let m=s.keys().next();m.done||s.delete(m.value)}}s.set(a,{json:d,at:c})}async function h(a,d){try{if(!Z(a))throw new i("INVALID",`unknown verb ${a}`);let c;try{c=JSON.parse(d||"{}")??{}}catch(S){throw new i("INVALID","payload is not valid JSON",{cause:S})}let l=await u,m=await Q[a](l,c);return JSON.stringify({ok:!0,value:T(m)??null})}catch(c){return ee(c)}}let w={status:()=>r,error:()=>o,session:()=>n?JSON.stringify(n.session):"",invoke(a,d="{}"){let c=`c${++p}`;return h(a,d).then(l=>b(c,l)),c},notify(a,d="{}"){h(a,d)},poll(a){let d=s.get(a);return d===void 0?"":(s.delete(a),d.json)},close(){n?.close()}};return e[$]=w,w}k();})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.robotsquid.squidhub",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.13",
|
|
4
4
|
"displayName": "SquidHub",
|
|
5
5
|
"description": "Cloud saves, analytics and the coin economy for Unity WebGL games published on SquidHub. Installs the C# wrapper, the .jslib half and the page bridge, and rewrites the exported index.html so it survives the platform's CSP.",
|
|
6
6
|
"unity": "2021.3",
|