@sky-mavis/1more-sdk
v0.0.1
Published
SDK for game partners to integrate with the OneMore platform via iframe communication
Readme
@sky-mavis/1more-sdk
SDK for game partners to integrate their games with the OneMore platform. This SDK handles the iframe communication between partner games and the main platform website using Penpal for secure, promise-based RPC.
Installation
npm install @sky-mavis/1more-sdk
# or
yarn add @sky-mavis/1more-sdkQuick Start
import { init, endRound } from '@sky-mavis/1more-sdk';
// Initialize SDK when your game loads
const { parent, destroy } = await init({
// Optional: add extra allowed origins for local development
allowedOrigins: ['http://localhost:3000'],
onRoundStart: (data) => {
// Called when parent starts a new round
console.log('Round started!');
console.log('Token:', data.token);
console.log('Session ID:', data.sessionId);
console.log('Round ID:', data.roundId);
console.log('Target Score:', data.targetScore);
// Store token for API calls
window.arcadeToken = data.token;
sessionStorage.setItem('arcadeToken', data.token);
},
});
// When game round ends, call parent.endRound()
await parent.endRound();
// Or use the standalone function:
await endRound();API
init(config)
Initializes the SDK and establishes a connection with the parent platform.
const { parent, destroy } = await init({
allowedOrigins: ['http://localhost:3000'], // optional
timeout: 10000, // optional, default 10 seconds
onRoundStart: (data) => {
// Handle round start
console.log(data.token, data.sessionId, data.roundId, data.targetScore);
},
});Parameters:
config.allowedOrigins- Additional allowed origins (default origin is always included)config.timeout- Connection timeout in milliseconds (default: 10000)config.onRoundStart- Callback fired when the parent starts a new round
Returns: Promise<IInitResult>
parent- Proxy object to call methods on the parent platformdestroy()- Function to clean up the connection
parent.endRound()
Notifies the parent platform that the game round has ended.
await parent.endRound();endRound() (standalone)
Convenience function that can be called from anywhere after init().
import { endRound } from '@sky-mavis/1more-sdk';
// Anywhere in your game code:
await endRound();Types
Game (Child) Types
interface IInitConfig {
allowedOrigins?: string[];
timeout?: number;
onRoundStart: (data: IRoundStartData) => void;
}
interface IInitResult {
parent: IParentMethods;
destroy: () => void;
}Shared Types
interface IRoundStartData {
token: string;
sessionId: string;
roundId: string;
targetScore: number;
[key: string]: unknown;
}
interface IGameMethods {
startRound: (data: IRoundStartData) => void | Promise<void>;
}
interface IParentMethods {
endRound: () => void | Promise<void>;
}Example: Phaser Integration
import Phaser from 'phaser';
import { init, endRound } from '@sky-mavis/1more-sdk';
declare global {
interface Window {
arcadeToken?: string;
}
}
async function main() {
// Initialize SDK before starting game
await init({
onRoundStart: (data) => {
window.arcadeToken = data.token;
sessionStorage.setItem('arcadeToken', data.token);
console.log('Round started:', data.roundId);
},
});
// Start Phaser game
new Phaser.Game(gameConfig);
}
// Call in your game over scene
export async function notifyGameFinished() {
await endRound();
}
main();Communication Flow
┌─────────────────┐ ┌─────────────────┐
│ OneMore Platform│ │ Partner Game │
│ (Parent) │ │ (Iframe) │
└────────┬────────┘ └────────┬────────┘
│ │
│ 1. Load iframe │
│ ─────────────────────────────────────>
│ │
│ 2. Penpal connection established │
│ <═══════════════════════════════════>
│ │
│ 3. parent calls game.startRound() │
│ (token, sessionId, roundId, │
│ targetScore) │
│ ─────────────────────────────────────>
│ │
│ ... game plays ... │
│ │
│ 4. game calls parent.endRound() │
│ <─────────────────────────────────────
│ │Security
The SDK validates incoming connections:
- Origin - Only accepts connections from configured
allowedOrigins - Source - Only communicates with
window.parent
Default allowed origin: https://main.new-arcade.axieinfinity.services
License
MIT
