@playcademy/sdk 0.2.1 → 0.2.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
@@ -221,9 +221,19 @@ console.log(`Level ${userLevel.currentLevel}, ${progress.xpToNextLevel} XP to ne
221
221
 
222
222
  ### TimeBack Integration
223
223
 
224
- Track learning activities and automatically calculate XP based on time spent and accuracy:
224
+ Access user role and enrollments, and track learning activities:
225
225
 
226
226
  ```typescript
227
+ // Access TimeBack role and enrollments
228
+ const role = client.timeback.role // 'student' | 'parent' | 'teacher' | 'administrator'
229
+ const enrollments = client.timeback.enrollments // [{ subject, grade, courseId }]
230
+
231
+ // Check if user is enrolled in a specific grade
232
+ const grade3Enrollment = enrollments.find(e => e.grade === 3)
233
+ if (grade3Enrollment) {
234
+ // Show grade 3 content
235
+ }
236
+
227
237
  // Start tracking an activity (only activityId required!)
228
238
  client.timeback.startActivity({
229
239
  activityId: 'math-quiz-level-1',
@@ -242,24 +252,16 @@ await client.timeback.endActivity({
242
252
  // 100%: 1.25x | 80-99%: 1.0x | 65-79%: 0.5x | <65%: 0x
243
253
  ```
244
254
 
245
- ### Real-time Communication
255
+ ### Real-time Authentication
246
256
 
247
- Open a direct, low-latency communication channel for your game, perfect for multiplayer interactions.
257
+ Get authentication tokens for WebSocket connections used by the platform's multiplayer system.
248
258
 
249
259
  ```typescript
250
- // Open a channel scoped to the current game
251
- const channel = await client.realtime.open('lobby-chat')
252
-
253
- // Send messages to other players in the channel
254
- channel.send({ type: 'chat', message: 'Hello, world!' })
255
-
256
- // Listen for incoming messages
257
- channel.onMessage(data => {
258
- console.log('Received message:', data)
259
- })
260
+ // Get a realtime token for WebSocket authentication
261
+ const { token } = await client.realtime.token.get()
260
262
 
261
- // Remember to close the channel when it's no longer needed
262
- // channel.close()
263
+ // Token is used internally by the platform's multiplayer WebSocket client
264
+ // for presence tracking, player positions, and real-time game features
263
265
  ```
264
266
 
265
267
  ## API Reference
@@ -315,11 +317,12 @@ channel.onMessage(data => {
315
317
 
316
318
  #### **Real-time** (`client.realtime`)
317
319
 
318
- - `open(channelName?)`: Opens a game-scoped WebSocket channel.
319
- - `token.get()`: Retrieves a JWT for the real-time service.
320
+ - `token.get()`: Retrieves a JWT for WebSocket authentication (used by the platform's multiplayer system).
320
321
 
321
322
  #### **TimeBack** (`client.timeback`)
322
323
 
324
+ - `role`: The user's TimeBack role (`'student'`, `'parent'`, `'teacher'`, or `'administrator'`)
325
+ - `enrollments`: Array of course enrollments with `subject`, `grade`, and `courseId`
323
326
  - `startActivity(metadata)`: Start tracking an activity (stores start time and metadata)
324
327
  - `metadata.activityId`: Unique activity identifier (required)
325
328
  - `metadata.activityName`: Human-readable activity name