gloot-xr-sdk
Version:
G-Loots SDK for web platform games
39 lines (35 loc) • 836 B
JavaScript
const Gloot = {
origin: null,
match: null,
openClient: function() {
dispatch({ type: 'CLIENT_OPEN' });
},
reportScore: function(scoreValue = 0, scoreString = '') {
dispatch({ type: 'SCORE_REPORT', payload: { scoreValue, scoreString } });
},
onInit: function(origin) {
this.origin = origin;
},
onPlayMatch: function(match) {
this.match = match;
},
};
const dispatch = ({ type, payload }) => {
try {
window.parent.postMessage({ type, payload }, Gloot.origin);
} catch (e) {}
};
window.addEventListener('message', e => {
console.log('G-Loot SDK got message: ', e);
const { type, payload } = e.data;
switch (type) {
case 'INIT': {
Gloot.onInit(payload);
}
case 'PLAY_MATCH': {
Gloot.onPlayMatch(payload);
}
}
});
window.Gloot = Gloot;
export default Gloot;