@playcademy/sdk 0.1.14 → 0.1.15
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 +38 -1
- package/dist/index.d.ts +885 -339
- package/dist/index.js +400 -112
- package/dist/types.d.ts +184 -16
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -31,6 +31,17 @@ The SDK serves as the primary interface between your game and the Playcademy pla
|
|
|
31
31
|
- **Server Integration**: Backend services integrating with Playcademy APIs
|
|
32
32
|
- **Testing & Automation**: Automated testing of platform integrations
|
|
33
33
|
|
|
34
|
+
### Connection Monitoring
|
|
35
|
+
|
|
36
|
+
The SDK automatically monitors network connectivity and provides hooks for games to handle disconnects gracefully:
|
|
37
|
+
|
|
38
|
+
- **Automatic Detection**: Multi-signal approach detects offline, slow, and degraded connections
|
|
39
|
+
- **Game Handlers**: Implement custom disconnect behavior (e.g., return to lobby, pause game)
|
|
40
|
+
- **Platform Integration**: Built-in helpers for displaying connection alerts
|
|
41
|
+
- **Zero Config**: Works out of the box, customizable when needed
|
|
42
|
+
|
|
43
|
+
See [DISCONNECT_HANDLING.md](./DISCONNECT_HANDLING.md) for detailed documentation and examples.
|
|
44
|
+
|
|
34
45
|
## Installation
|
|
35
46
|
|
|
36
47
|
Install the SDK using your preferred package manager:
|
|
@@ -61,7 +72,15 @@ import { PlaycademyClient } from '@playcademy/sdk'
|
|
|
61
72
|
async function initializeGame() {
|
|
62
73
|
try {
|
|
63
74
|
// Automatic initialization - detects environment and configures appropriately
|
|
64
|
-
const client = await PlaycademyClient.init(
|
|
75
|
+
const client = await PlaycademyClient.init({
|
|
76
|
+
// Optional: Handle connection issues gracefully
|
|
77
|
+
onDisconnect: ({ state, displayAlert }) => {
|
|
78
|
+
if (state === 'offline') {
|
|
79
|
+
displayAlert?.('Connection lost. Reconnecting...', { type: 'warning' })
|
|
80
|
+
// Return to safe state (e.g., lobby)
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
})
|
|
65
84
|
|
|
66
85
|
// Get current user
|
|
67
86
|
const user = await client.users.me()
|
|
@@ -322,6 +341,11 @@ client.on('authChange', payload => {
|
|
|
322
341
|
console.log('Authentication changed:', payload.token)
|
|
323
342
|
})
|
|
324
343
|
|
|
344
|
+
// Connection state changes
|
|
345
|
+
client.on('connectionChange', ({ state, reason }) => {
|
|
346
|
+
console.log(`Connection: ${state} - ${reason}`)
|
|
347
|
+
})
|
|
348
|
+
|
|
325
349
|
// Inventory changes
|
|
326
350
|
client.on('inventoryChange', payload => {
|
|
327
351
|
console.log(`Item ${payload.itemId}: ${payload.delta} (total: ${payload.newTotal})`)
|
|
@@ -339,6 +363,19 @@ client.on('levelUp', payload => {
|
|
|
339
363
|
})
|
|
340
364
|
```
|
|
341
365
|
|
|
366
|
+
### Disconnect Handling
|
|
367
|
+
|
|
368
|
+
For convenience, use the `onDisconnect` method to handle only offline/degraded states:
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
const cleanup = client.onDisconnect(({ state, reason, displayAlert }) => {
|
|
372
|
+
console.log(`Disconnect detected: ${state}`)
|
|
373
|
+
displayAlert?.(`Connection ${state}: ${reason}`, { type: 'warning' })
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
// Later: cleanup() to unregister
|
|
377
|
+
```
|
|
378
|
+
|
|
342
379
|
### Event-Driven UI Updates
|
|
343
380
|
|
|
344
381
|
```typescript
|