@playcademy/sdk 0.0.1-beta.19 → 0.0.1-beta.20

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/dist/messaging.d.ts +19 -18
  2. package/package.json +1 -1
@@ -198,13 +198,12 @@ declare class PlaycademyMessaging {
198
198
  * This is the main public API for sending messages in the Playcademy system.
199
199
  *
200
200
  * **How It Works**:
201
- * 1. If options.target is provided, always use postMessage to that target
202
- * 2. Otherwise, analyzes the message type and current runtime context
203
- * 3. Determines if we're in an iframe and if this message should use postMessage
204
- * 4. Routes to the appropriate transport method (postMessage or CustomEvent)
201
+ * 1. Analyzes the message type and current runtime context
202
+ * 2. Determines if we're in an iframe and if this message should use postMessage
203
+ * 3. Routes to the appropriate transport method (postMessage or CustomEvent)
205
204
  *
206
205
  * **Transport Selection Logic**:
207
- * - **postMessage**: Used when target is specified OR when game is in iframe sending to parent
206
+ * - **postMessage**: Used when game is in iframe and sending to parent, OR when target window is specified
208
207
  * - **CustomEvent**: Used for local/same-context communication
209
208
  *
210
209
  * **Type Safety**:
@@ -214,21 +213,24 @@ declare class PlaycademyMessaging {
214
213
  * @template K - The message event type (ensures type safety)
215
214
  * @param type - The message event type to send
216
215
  * @param payload - The data to send with the message (type-checked)
217
- * @param options - Optional configuration for target window and origin
216
+ * @param options - Optional configuration for message sending
218
217
  *
219
218
  * @example
220
219
  * ```typescript
221
- * // Send game ready signal (auto-detected transport)
220
+ * // Send game ready signal (no payload)
222
221
  * messaging.send(MessageEvents.READY, undefined)
223
222
  *
224
- * // Send to specific iframe (parent → game)
223
+ * // Send telemetry data (typed payload)
224
+ * messaging.send(MessageEvents.TELEMETRY, { fps: 60, mem: 128 })
225
+ *
226
+ * // Send to specific iframe window (parent to iframe communication)
225
227
  * messaging.send(MessageEvents.INIT, { baseUrl, token, gameId }, {
226
228
  * target: iframe.contentWindow,
227
- * origin: 'https://game.example.com'
229
+ * origin: '*'
228
230
  * })
229
231
  *
230
- * // Send telemetry data (auto-detected transport)
231
- * messaging.send(MessageEvents.TELEMETRY, { fps: 60, mem: 128 })
232
+ * // TypeScript will error if payload type is wrong
233
+ * messaging.send(MessageEvents.INIT, "wrong type") // Error
232
234
  * ```
233
235
  */
234
236
  send<K extends MessageEvents>(type: K, payload: MessageEventMap[K], options?: {
@@ -331,17 +333,16 @@ declare class PlaycademyMessaging {
331
333
  * **Message Direction Analysis**:
332
334
  * Different message types flow in different directions:
333
335
  * - **Game → Parent**: READY, EXIT, TELEMETRY (use postMessage when in iframe)
334
- * - **Parent → Game**: INIT, TOKEN_REFRESH, PAUSE, etc. (use CustomEvent in local dev)
336
+ * - **Parent → Game**: INIT, TOKEN_REFRESH, PAUSE, etc. (use CustomEvent in local dev, or postMessage with target)
335
337
  *
336
338
  * **Cross-Context Communication**:
337
- * This messaging system now handles ALL communication patterns:
338
- * - Game Parent: Automatic detection and postMessage
339
- * - Parent Game: Use options.target to specify the iframe window
340
- * - Local development: Automatic CustomEvent fallback
339
+ * The messaging system supports cross-context targeting through the optional `target` parameter.
340
+ * When a target window is specified, postMessage is used regardless of the current context.
341
+ * This enables parent-to-iframe communication through the unified messaging API.
341
342
  *
342
343
  * **Transport Selection Logic**:
343
- * - **postMessage**: Used when game is in iframe AND sending to parent
344
- * - **CustomEvent**: Used for all other cases (local development, parent-to-game)
344
+ * - **postMessage**: Used when game is in iframe AND sending to parent, OR when target window is specified
345
+ * - **CustomEvent**: Used for all other cases (local development, same-context communication)
345
346
  *
346
347
  * **Security Considerations**:
347
348
  * The origin is currently set to '*' for development convenience, but should be
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@playcademy/sdk",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.19",
4
+ "version": "0.0.1-beta.20",
5
5
  "exports": {
6
6
  ".": {
7
7
  "import": "./dist/index.js",