Skip to content

poki/npm-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@poki/sdk

Typed wrapper around the Poki SDK. This package does not bundle the Poki SDK itself; it simply forwards calls and provides TypeScript types.

You still need:

<script src="https://game-cdn.poki.com/scripts/v2/poki-sdk.js"></script>

or something similar depending on your game engine.

Documentation: Poki SDK Documentation

Install

npm install @poki/sdk
yarn add @poki/sdk

Usage

Make sure the Poki SDK script is loaded in your page (see above). Then use this package to access the API:

import PokiSDK from '@poki/sdk';

async function boot() {
  await PokiSDK.init();

  PokiSDK.gameLoadingFinished();
}

boot();

If the Poki SDK script is not loaded, this package will throw PokiSDK not loaded on use.

API

Initialization

  • init(options?: InitOptions): Promise<void>
  • setDebug(toggle?: boolean): void
  • setLogging(toggle: boolean): void

Gameplay Lifecycle

  • gameLoadingFinished(): void
  • gameplayStart(): void
  • gameplayStop(): void

Commercial Breaks (see documentation for details)

  • commercialBreak(onStart?: () => void): Promise<void>

Rewarded Breaks (see documentation for details)

  • rewardedBreak(onStartOrArgs?: (() => void) | RewardedBreakParams): Promise<boolean>

RewardedBreakParams supports onStart?: () => void and size?: 'small' | 'medium' | 'large'.

Display Ads

  • displayAd(container: HTMLElement, size: string, onCanDestroy?: () => void, onDisplayRendered?: (isEmpty: boolean) => void): void
  • destroyAd(container?: HTMLElement): void

Sharing (see documentation for details)

  • shareableURL(params?: Record<string, any>): Promise<string>
  • getURLParam(key: string): string
  • getLanguage(): string

UI (see documentation for details)

  • movePill(topPercent: number, topPx: number): void
  • showLeaderboard(id?: number | null | false): void

Analytics, Tracking, and Errors

  • measure(category: MeasureCategory, what: string, action: MeasureAction): void
  • enableEventTracking(cmpIndex?: number): void
  • captureError(err: string | Error): void

Accounts

  • getUser(): Promise<User | null>
  • getToken(): Promise<string | null>
  • login(): Promise<void>

External Links

  • openExternalLink(url: string): void

Playtest Helpers

  • playtestSetCanvas(canvas: HTMLCanvasElement | HTMLCanvasElement[] | null): void
  • playtestCaptureHtmlOnce(): void
  • playtestCaptureHtmlForce(): void
  • playtestCaptureHtmlOn(): void
  • playtestCaptureHtmlOff(): void

Types Used in Signatures

  • InitOptions: debug?: boolean, logging?: boolean, submitScore?: (fn: (leaderboard: string, score: number) => void) => void
  • User: username: string, avatarUrl: string, optedIn: boolean
  • RewardedBreakSize: 'small' | 'medium' | 'large'
  • RewardedBreakParams: onStart?: () => void, size?: RewardedBreakSize
  • MeasureCategory: 'achievement' | 'booster' | 'boss' | 'button' | 'checkpoint' | 'cosmetic' | 'death' | 'drawing' | 'economy' | 'enemy' | 'hint' | 'item' | 'level' | 'mode' | 'pet' | 'player' | 'powerup' | 'puzzle' | 'quest' | 'round' | 'skip-level' | 'stage' | 'tutorial' | 'upgrade' | 'wave' | 'world' | string
  • MeasureAction: 'start' | 'complete' | 'fail' | 'visible' | 'interact' | string

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors