@looplay/sdk 0.8.2 → 0.8.3

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/README.md +35 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -63,24 +63,49 @@ backward compatibility, but you should set one regardless).
63
63
  ```ts
64
64
  import { LooplayIframeAuth } from '@looplay/sdk';
65
65
 
66
+ // 1. Initialize the SDK
66
67
  export const looplayAuth = new LooplayIframeAuth({
67
68
  appId: 'YOUR_APP_ID', // from your creator dashboard
68
69
  apiUrl: 'https://api.looplay.gg', // required for standalone builds; optional inside the iframe
69
70
  parentOrigin: import.meta.env.VITE_PARENT_ORIGIN, // restrict the accepted postMessage origin
71
+
72
+ // Optional: Auto-request rewarded ads after match activity
73
+ autoRequestAds: {
74
+ enabled: true,
75
+ afterActionCount: 3, // show ad every 3 actions/matches
76
+ chance: 0.5, // 50% chance to show ad
77
+ cooldownMs: 60000, // min 1 minute between requests
78
+ maxRequestsPerSession: 5,
79
+ }
70
80
  });
71
81
 
82
+ // 2. Start listening for auth and lifecycle events
72
83
  looplayAuth.init();
73
84
  looplayAuth.initLifecycleTracking(); // auto-emits GAME_STARTED once per session
74
85
 
75
- // Anywhere in the game — identical code whether hosted on Looplay or not:
86
+ // 3. Anywhere in the game — identical code whether hosted on Looplay or not:
76
87
  looplayAuth.canTrack();
77
88
  looplayAuth.subscribe((state) => { /* re-render when auth arrives/clears */ });
89
+
78
90
  await looplayAuth.trackView();
79
- looplayAuth.startAttempt(); // call once when the user presses Play
91
+
92
+ // Call once when the user presses Play
93
+ looplayAuth.startAttempt();
94
+
95
+ // Periodically track play time
80
96
  await looplayAuth.trackPlay(playTimeSeconds);
97
+
98
+ // Track when a match/level ends
81
99
  await looplayAuth.trackMatch(matchId, { durationSeconds, isWin: true });
100
+
101
+ // Emit custom actions for quests/analytics
82
102
  await looplayAuth.emitGameEvent('CUSTOM_ACTION', { value: 1 });
83
- await looplayAuth.requestAds();
103
+
104
+ // Manually request rewarded ads (returns true if watched)
105
+ const adWatched = await looplayAuth.requestAds();
106
+ if (adWatched) {
107
+ // Give reward to the player
108
+ }
84
109
  ```
85
110
 
86
111
  Every play attempt is backed by a short-lived, server-signed token — the SDK
@@ -238,6 +263,13 @@ request as `false` and continue normally.
238
263
  If the parent never answers, `requestAds()` times out after 5 seconds by
239
264
  default and resolves `false`.
240
265
 
266
+ ```ts
267
+ const isWatched = await looplayAuth.requestAds();
268
+ if (isWatched) {
269
+ // Grant reward to player
270
+ }
271
+ ```
272
+
241
273
  ```ts
242
274
  window.addEventListener('message', async (event) => {
243
275
  const data = event.data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@looplay/sdk",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "LooplaySDK (auth + points) for game integrations",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",