Skip to content

Instantly share code, notes, and snippets.

@maxmonax
Last active October 10, 2023 13:52
Show Gist options
  • Save maxmonax/77d44b67963ed1cd23a5b5b1d1201482 to your computer and use it in GitHub Desktop.
Save maxmonax/77d44b67963ed1cd23a5b5b1d1201482 to your computer and use it in GitHub Desktop.
Yandex Games API wrapper
import { LogMng } from "@/utils/LogMng";
export class YaGamesApi {
private static instance: YaGamesApi = null;
private _ysdk: any;
private constructor() { }
static getInstance(): YaGamesApi {
if (!YaGamesApi.instance) {
YaGamesApi.instance = new YaGamesApi();
}
return YaGamesApi.instance;
}
async init() {
try {
this._ysdk = await YaGames.init();
LogMng.debug('Yandex SDK initialized');
return await Promise.resolve(true);
} catch (error) {
LogMng.error('Yandex SDK NOT initialized');
console.error(error);
return await Promise.resolve(false);
}
}
gameReady() {
this._ysdk?.features.LoadingAPI?.ready();
}
async canReview(): Promise<{ value: boolean, reason: string }> {
return this._ysdk.feedback.canReview();
}
async requestReview(): Promise<{ feedbackSent: any }> {
return this._ysdk.feedback.requestReview();
}
showFullscreenAdv(onOpen?: Function, onCLose?: Function, onError?: Function, onOffline?: Function) {
this._ysdk.adv.showFullscreenAdv({
callbacks: {
onOpen: onOpen,
onClose: onCLose,
onError: onError,
onOffline: onOffline
}
})
}
showRewarded(onOpen?: Function, onRewarded?: Function, onCLose?: Function, onError?: Function) {
this._ysdk.adv.showRewardedVideo({
callbacks: {
onOpen: onOpen,
onRewarded: onRewarded,
onClose: onCLose,
onError: onError
}
})
}
}
declare var YaGames: {
init: Function;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment