@oasiz/sdk 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @oasiz/sdk
2
2
 
3
- Typed SDK for integrating games with the Oasiz platform. Handles score submission, haptic feedback, cross-session state persistence, multiplayer room codes, and app lifecycle events for local development.
3
+ Typed SDK for integrating games with the Oasiz platform. Handles score submission, haptic feedback, cross-session state persistence, multiplayer room codes, navigation hooks, and app lifecycle events for local development.
4
4
 
5
5
  ## Install
6
6
 
@@ -209,6 +209,55 @@ offResume();
209
209
 
210
210
  ---
211
211
 
212
+ ## Navigation
213
+
214
+ Use navigation hooks when your game needs to control back behavior (Android back / web Escape) or participate in host-driven close events.
215
+
216
+ ### `oasiz.onBackButton(callback: () => void): Unsubscribe`
217
+
218
+ Registers a callback for platform back actions. While at least one back listener is subscribed, back actions are routed to your game instead of immediately closing it.
219
+
220
+ Use this for pause menus, in-game overlays, or custom back-stack behavior.
221
+
222
+ ```ts
223
+ const offBack = oasiz.onBackButton(() => {
224
+ if (this.isPauseMenuOpen) {
225
+ this.closePauseMenu();
226
+ return;
227
+ }
228
+ this.openPauseMenu();
229
+ });
230
+
231
+ // Restore default host back behavior when no longer needed
232
+ offBack();
233
+ ```
234
+
235
+ ### `oasiz.leaveGame(): void`
236
+
237
+ Programmatically request the host to close the current game (for example, from a Quit button inside your game UI).
238
+
239
+ ```ts
240
+ quitButton.addEventListener("click", () => {
241
+ oasiz.leaveGame();
242
+ });
243
+ ```
244
+
245
+ ### `oasiz.onLeaveGame(callback: () => void): Unsubscribe`
246
+
247
+ Registers a callback fired when the host initiates closing the game (for example, close button, gesture, or host navigation). Use this for lightweight cleanup.
248
+
249
+ ```ts
250
+ const offLeave = oasiz.onLeaveGame(() => {
251
+ oasiz.flushGameState();
252
+ this.bgMusic.pause();
253
+ });
254
+
255
+ // Clean up listener when destroyed
256
+ offLeave();
257
+ ```
258
+
259
+ ---
260
+
212
261
  ## Multiplayer
213
262
 
214
263
  ### `oasiz.shareRoomCode(code: string | null)`
@@ -261,6 +310,9 @@ import {
261
310
  shareRoomCode,
262
311
  onPause,
263
312
  onResume,
313
+ onBackButton,
314
+ onLeaveGame,
315
+ leaveGame,
264
316
  getGameId,
265
317
  getRoomCode,
266
318
  getPlayerName,
package/dist/index.cjs CHANGED
@@ -26,8 +26,11 @@ __export(index_exports, {
26
26
  getPlayerAvatar: () => getPlayerAvatar,
27
27
  getPlayerName: () => getPlayerName,
28
28
  getRoomCode: () => getRoomCode,
29
+ leaveGame: () => leaveGame,
29
30
  loadGameState: () => loadGameState,
30
- oasis: () => oasis,
31
+ oasiz: () => oasiz,
32
+ onBackButton: () => onBackButton,
33
+ onLeaveGame: () => onLeaveGame,
31
34
  onPause: () => onPause,
32
35
  onResume: () => onResume,
33
36
  saveGameState: () => saveGameState,
@@ -234,8 +237,77 @@ function onResume(callback) {
234
237
  return addLifecycleListener("oasiz:resume", callback);
235
238
  }
236
239
 
240
+ // src/navigation.ts
241
+ var activeBackListeners = 0;
242
+ function isDevelopment6() {
243
+ const nodeEnv = globalThis.process?.env?.NODE_ENV;
244
+ return nodeEnv !== "production";
245
+ }
246
+ function getBridgeWindow5() {
247
+ if (typeof window === "undefined") {
248
+ return void 0;
249
+ }
250
+ return window;
251
+ }
252
+ function warnMissingBridge3(methodName) {
253
+ if (isDevelopment6()) {
254
+ console.warn(
255
+ "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
256
+ );
257
+ }
258
+ }
259
+ function addNavigationListener(eventName, callback) {
260
+ if (typeof window === "undefined") {
261
+ if (isDevelopment6()) {
262
+ console.warn(
263
+ "[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
264
+ );
265
+ }
266
+ return () => {
267
+ };
268
+ }
269
+ const handler = () => callback();
270
+ window.addEventListener(eventName, handler);
271
+ return () => window.removeEventListener(eventName, handler);
272
+ }
273
+ function onBackButton(callback) {
274
+ const off = addNavigationListener("oasiz:back", callback);
275
+ const bridge = getBridgeWindow5();
276
+ activeBackListeners += 1;
277
+ if (activeBackListeners === 1) {
278
+ if (typeof bridge?.__oasizSetBackOverride === "function") {
279
+ bridge.__oasizSetBackOverride(true);
280
+ } else {
281
+ warnMissingBridge3("__oasizSetBackOverride");
282
+ }
283
+ }
284
+ return () => {
285
+ off();
286
+ activeBackListeners = Math.max(0, activeBackListeners - 1);
287
+ if (activeBackListeners === 0) {
288
+ const currentBridge = getBridgeWindow5();
289
+ if (typeof currentBridge?.__oasizSetBackOverride === "function") {
290
+ currentBridge.__oasizSetBackOverride(false);
291
+ } else {
292
+ warnMissingBridge3("__oasizSetBackOverride");
293
+ }
294
+ }
295
+ };
296
+ }
297
+ function onLeaveGame(callback) {
298
+ return addNavigationListener("oasiz:leave", callback);
299
+ }
300
+ function leaveGame() {
301
+ const bridge = getBridgeWindow5();
302
+ if (typeof bridge?.__oasizLeaveGame === "function") {
303
+ bridge.__oasizLeaveGame();
304
+ return;
305
+ }
306
+ warnMissingBridge3("__oasizLeaveGame");
307
+ }
308
+
237
309
  // src/index.ts
238
- var oasis = {
310
+ var oasiz = {
239
311
  submitScore,
240
312
  emitScoreConfig,
241
313
  triggerHaptic,
@@ -245,6 +317,9 @@ var oasis = {
245
317
  shareRoomCode,
246
318
  onPause,
247
319
  onResume,
320
+ onBackButton,
321
+ onLeaveGame,
322
+ leaveGame,
248
323
  get gameId() {
249
324
  return getGameId();
250
325
  },
@@ -266,8 +341,11 @@ var oasis = {
266
341
  getPlayerAvatar,
267
342
  getPlayerName,
268
343
  getRoomCode,
344
+ leaveGame,
269
345
  loadGameState,
270
- oasis,
346
+ oasiz,
347
+ onBackButton,
348
+ onLeaveGame,
271
349
  onPause,
272
350
  onResume,
273
351
  saveGameState,
package/dist/index.d.cts CHANGED
@@ -27,7 +27,11 @@ type Unsubscribe = () => void;
27
27
  declare function onPause(callback: () => void): Unsubscribe;
28
28
  declare function onResume(callback: () => void): Unsubscribe;
29
29
 
30
- declare const oasis: {
30
+ declare function onBackButton(callback: () => void): Unsubscribe;
31
+ declare function onLeaveGame(callback: () => void): Unsubscribe;
32
+ declare function leaveGame(): void;
33
+
34
+ declare const oasiz: {
31
35
  submitScore: typeof submitScore;
32
36
  emitScoreConfig: typeof emitScoreConfig;
33
37
  triggerHaptic: typeof triggerHaptic;
@@ -37,10 +41,13 @@ declare const oasis: {
37
41
  shareRoomCode: typeof shareRoomCode;
38
42
  onPause: typeof onPause;
39
43
  onResume: typeof onResume;
44
+ onBackButton: typeof onBackButton;
45
+ onLeaveGame: typeof onLeaveGame;
46
+ leaveGame: typeof leaveGame;
40
47
  readonly gameId: string | undefined;
41
48
  readonly roomCode: string | undefined;
42
49
  readonly playerName: string | undefined;
43
50
  readonly playerAvatar: string | undefined;
44
51
  };
45
52
 
46
- export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, loadGameState, oasis, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
53
+ export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
package/dist/index.d.ts CHANGED
@@ -27,7 +27,11 @@ type Unsubscribe = () => void;
27
27
  declare function onPause(callback: () => void): Unsubscribe;
28
28
  declare function onResume(callback: () => void): Unsubscribe;
29
29
 
30
- declare const oasis: {
30
+ declare function onBackButton(callback: () => void): Unsubscribe;
31
+ declare function onLeaveGame(callback: () => void): Unsubscribe;
32
+ declare function leaveGame(): void;
33
+
34
+ declare const oasiz: {
31
35
  submitScore: typeof submitScore;
32
36
  emitScoreConfig: typeof emitScoreConfig;
33
37
  triggerHaptic: typeof triggerHaptic;
@@ -37,10 +41,13 @@ declare const oasis: {
37
41
  shareRoomCode: typeof shareRoomCode;
38
42
  onPause: typeof onPause;
39
43
  onResume: typeof onResume;
44
+ onBackButton: typeof onBackButton;
45
+ onLeaveGame: typeof onLeaveGame;
46
+ leaveGame: typeof leaveGame;
40
47
  readonly gameId: string | undefined;
41
48
  readonly roomCode: string | undefined;
42
49
  readonly playerName: string | undefined;
43
50
  readonly playerAvatar: string | undefined;
44
51
  };
45
52
 
46
- export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, loadGameState, oasis, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
53
+ export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
package/dist/index.js CHANGED
@@ -195,8 +195,77 @@ function onResume(callback) {
195
195
  return addLifecycleListener("oasiz:resume", callback);
196
196
  }
197
197
 
198
+ // src/navigation.ts
199
+ var activeBackListeners = 0;
200
+ function isDevelopment6() {
201
+ const nodeEnv = globalThis.process?.env?.NODE_ENV;
202
+ return nodeEnv !== "production";
203
+ }
204
+ function getBridgeWindow5() {
205
+ if (typeof window === "undefined") {
206
+ return void 0;
207
+ }
208
+ return window;
209
+ }
210
+ function warnMissingBridge3(methodName) {
211
+ if (isDevelopment6()) {
212
+ console.warn(
213
+ "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
214
+ );
215
+ }
216
+ }
217
+ function addNavigationListener(eventName, callback) {
218
+ if (typeof window === "undefined") {
219
+ if (isDevelopment6()) {
220
+ console.warn(
221
+ "[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
222
+ );
223
+ }
224
+ return () => {
225
+ };
226
+ }
227
+ const handler = () => callback();
228
+ window.addEventListener(eventName, handler);
229
+ return () => window.removeEventListener(eventName, handler);
230
+ }
231
+ function onBackButton(callback) {
232
+ const off = addNavigationListener("oasiz:back", callback);
233
+ const bridge = getBridgeWindow5();
234
+ activeBackListeners += 1;
235
+ if (activeBackListeners === 1) {
236
+ if (typeof bridge?.__oasizSetBackOverride === "function") {
237
+ bridge.__oasizSetBackOverride(true);
238
+ } else {
239
+ warnMissingBridge3("__oasizSetBackOverride");
240
+ }
241
+ }
242
+ return () => {
243
+ off();
244
+ activeBackListeners = Math.max(0, activeBackListeners - 1);
245
+ if (activeBackListeners === 0) {
246
+ const currentBridge = getBridgeWindow5();
247
+ if (typeof currentBridge?.__oasizSetBackOverride === "function") {
248
+ currentBridge.__oasizSetBackOverride(false);
249
+ } else {
250
+ warnMissingBridge3("__oasizSetBackOverride");
251
+ }
252
+ }
253
+ };
254
+ }
255
+ function onLeaveGame(callback) {
256
+ return addNavigationListener("oasiz:leave", callback);
257
+ }
258
+ function leaveGame() {
259
+ const bridge = getBridgeWindow5();
260
+ if (typeof bridge?.__oasizLeaveGame === "function") {
261
+ bridge.__oasizLeaveGame();
262
+ return;
263
+ }
264
+ warnMissingBridge3("__oasizLeaveGame");
265
+ }
266
+
198
267
  // src/index.ts
199
- var oasis = {
268
+ var oasiz = {
200
269
  submitScore,
201
270
  emitScoreConfig,
202
271
  triggerHaptic,
@@ -206,6 +275,9 @@ var oasis = {
206
275
  shareRoomCode,
207
276
  onPause,
208
277
  onResume,
278
+ onBackButton,
279
+ onLeaveGame,
280
+ leaveGame,
209
281
  get gameId() {
210
282
  return getGameId();
211
283
  },
@@ -226,8 +298,11 @@ export {
226
298
  getPlayerAvatar,
227
299
  getPlayerName,
228
300
  getRoomCode,
301
+ leaveGame,
229
302
  loadGameState,
230
- oasis,
303
+ oasiz,
304
+ onBackButton,
305
+ onLeaveGame,
231
306
  onPause,
232
307
  onResume,
233
308
  saveGameState,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oasiz/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Typed SDK for Oasiz game platform bridge APIs.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",