@goodgamestudios/cxf-events
Version:
Unified events for BigFarm, Empire and others
1 lines • 15.4 kB
JavaScript
!function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=12)}([function(e,n,t){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:!0}),n.debug=n.timeLeftToStopDate=n.randomString=n.randomNumber=n.encodePayload=n.decodePayload=void 0;var o=r(t(2));n.decodePayload=function(e){return JSON.parse(atob(e))},n.encodePayload=function(e){return btoa(JSON.stringify(e))},n.randomNumber=function(){return 1e4*Math.random()|0},n.randomString=function(){return Math.random().toString(36).substr(2)},n.timeLeftToStopDate=function(e){var n=new Date;return n.setTime(n.getTime()+1e3*e),n.getTime()},n.debug=o.default("CXF-EVENTS")},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.CxfEvents=void 0,function(e){e.Token="cxf.token",e.Login="cxf.login",e.Signup="cxf.signup",e.GameEventUpdate="cxf.gameEvent.update",e.GameEventAdd="cxf.gameEvent.add",e.GameEventRemove="cxf.gameEvent.remove",e.XpChanged="cxf.xp.changed",e.LevelChanged="cxf.level.changed",e.LegendLevelChanged="cxf.legendLevel.changed",e.Push="cxf.push",e.OpenIGS="cxf.igs.open",e.JoinTempServer="cxf.join.temp.server",e.Subscription="cxf.subscription",e.RewardedAdStart="cxf.rewardedad.start",e.RewardedAdDone="cxf.rewardedad.done"}(n.CxfEvents||(n.CxfEvents={}))},function(e,n,t){(function(r){n.formatArgs=function(n){if(n[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+n[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const t="color: "+this.color;n.splice(1,0,t,"color: inherit");let r=0,o=0;n[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))}),n.splice(o,0,t)},n.save=function(e){try{e?n.storage.setItem("debug",e):n.storage.removeItem("debug")}catch(e){}},n.load=function(){let e;try{e=n.storage.getItem("debug")}catch(e){}!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG);return e},n.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},n.storage=function(){try{return localStorage}catch(e){}}(),n.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),n.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],n.log=console.debug||console.log||(()=>{}),e.exports=t(4)(n);const{formatters:o}=e.exports;o.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this,t(3))},function(e,n){var t,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(t===setTimeout)return setTimeout(e,0);if((t===i||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:i}catch(e){t=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var u,c=[],f=!1,d=-1;function l(){f&&u&&(f=!1,u.length?c=u.concat(c):d=-1,c.length&&m())}function m(){if(!f){var e=a(l);f=!0;for(var n=c.length;n;){for(u=c,c=[];++d<n;)u&&u[d].run();d=-1,n=c.length}u=null,f=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(n){try{return r.call(null,e)}catch(n){return r.call(this,e)}}}(e)}}function p(e,n){this.fun=e,this.array=n}function C(){}o.nextTick=function(e){var n=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)n[t-1]=arguments[t];c.push(new p(e,n)),1!==c.length||f||a(m)},p.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=C,o.addListener=C,o.once=C,o.off=C,o.removeListener=C,o.removeAllListeners=C,o.emit=C,o.prependListener=C,o.prependOnceListener=C,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,n,t){e.exports=function(e){function n(e){let t,o,i,s=null;function a(...e){if(!a.enabled)return;const r=a,o=Number(new Date),i=o-(t||o);r.diff=i,r.prev=t,r.curr=o,t=o,e[0]=n.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(t,o)=>{if("%%"===t)return"%";s++;const i=n.formatters[o];if("function"==typeof i){const n=e[s];t=i.call(r,n),e.splice(s,1),s--}return t}),n.formatArgs.call(r,e);(r.log||n.log).apply(r,e)}return a.namespace=e,a.useColors=n.useColors(),a.color=n.selectColor(e),a.extend=r,a.destroy=n.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(o!==n.namespaces&&(o=n.namespaces,i=n.enabled(e)),i),set:e=>{s=e}}),"function"==typeof n.init&&n.init(a),a}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},n.disable=function(){const e=[...n.names.map(o),...n.skips.map(o).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.namespaces=e,n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(t=0;t<o;t++)r[t]&&("-"===(e=r[t].replace(/\*/g,".*?"))[0]?n.skips.push(new RegExp("^"+e.slice(1)+"$")):n.names.push(new RegExp("^"+e+"$")))},n.enabled=function(e){if("*"===e[e.length-1])return!0;let t,r;for(t=0,r=n.skips.length;t<r;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;t<r;t++)if(n.names[t].test(e))return!0;return!1},n.humanize=t(5),n.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(t=>{n[t]=e[t]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return n.colors[Math.abs(t)%n.colors.length]},n.enable(n.load()),n}},function(e,n){var t=1e3,r=6e4,o=60*r,i=24*o;function s(e,n,t,r){var o=n>=1.5*t;return Math.round(e/t)+" "+r+(o?"s":"")}e.exports=function(e,n){n=n||{};var a=typeof e;if("string"===a&&e.length>0)return function(e){if((e=String(e)).length>100)return;var n=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!n)return;var s=parseFloat(n[1]);switch((n[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*s;case"weeks":case"week":case"w":return 6048e5*s;case"days":case"day":case"d":return s*i;case"hours":case"hour":case"hrs":case"hr":case"h":return s*o;case"minutes":case"minute":case"mins":case"min":case"m":return s*r;case"seconds":case"second":case"secs":case"sec":case"s":return s*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return s;default:return}}(e);if("number"===a&&isFinite(e))return n.long?function(e){var n=Math.abs(e);if(n>=i)return s(e,n,i,"day");if(n>=o)return s(e,n,o,"hour");if(n>=r)return s(e,n,r,"minute");if(n>=t)return s(e,n,t,"second");return e+" ms"}(e):function(e){var n=Math.abs(e);if(n>=i)return Math.round(e/i)+"d";if(n>=o)return Math.round(e/o)+"h";if(n>=r)return Math.round(e/r)+"m";if(n>=t)return Math.round(e/t)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.subscribeToIGSEvents=void 0;var r=t(1),o=t(0);n.subscribeToIGSEvents=function(e){var n=o.debug.extend("subscribeToIGSEvents");e.on("game.button.clicked.btn_webshop",(function(t){n(r.CxfEvents.OpenIGS),e.emit(r.CxfEvents.OpenIGS,t)})),e.on("game.button.clicked.btn_subscription",(function(){n(r.CxfEvents.OpenIGS,"subscriptions"),e.emit(r.CxfEvents.OpenIGS,{page:"subscriptions"})}))}},function(e,n,t){"use strict";var r=window&&window.CXF;e.exports=new Promise((function(e,n){if(window||n(),r)return e(r);window.addEventListener("cxf.initialized",(function(n){r=n.cxf,e(r)}),{capture:!0,once:!0,passive:!0})}))},,function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.getBigfarmPayload=void 0,n.getBigfarmPayload=function(e){return e[0]}},,,function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.subscribeToRewardedAdEvents=n.subscribeToPushEvents=n.subscribeToLevelChanges=n.subscribeToXPChanges=n.subscribeToJoinTempServer=n.subscribeToSignup=n.subscribeToLogin=n.subscribeToSubscription=n.subscribeToToken=void 0;var r=t(0),o=t(1),i=t(9),s=t(13),a=t(6);t(7).then((function(e){c(e),f(e),d(e),l(e),p(e),C(e),v(e),s.subscribeToGameEvents(e),a.subscribeToIGSEvents(e),m(e),g(e)}));var u=r.debug.extend("BF");function c(e){e.on("API_TOKEN",(function(n){var t=i.getBigfarmPayload(n).token;e.emit(o.CxfEvents.Token,t)})),e.on("508",(function(){}))}function f(e){e.on("SUBSCRIPTION_INFO",(function(n){var t=n[0].playerSubscription,r=Boolean(t);e.emit(o.CxfEvents.Subscription,r)})),e.on("460",(function(){}))}function d(e){e.on("LOGIN_BASIC_DATA",(function(n){return u("LOGIN_BASIC_DATA received"),function(e,n){var t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],c=e[5],f=e[6],d=new Promise((function(e,t){n.once(o.CxfEvents.Token,(function(n){u(o.CxfEvents.Token+" received"),e(n)})),setTimeout((function(){return t(new Error("No token event happened"))}),3e4)})),l=new Promise((function(e,t){n.once(o.CxfEvents.GameEventUpdate,(function(n){u(o.CxfEvents.GameEventUpdate+" received"),e(n)})),setTimeout((function(){return t(new Error("No game event happened"))}),3e4)}));Promise.all([d,l]).then((function(e){var d=e[0],l=e[1],m={playerId:t.playerIdentity.playerID,instanceId:s,networkId:n.networkId||i,gameId:n.gameId,language:r,token:d,gameEvents:l,zoneId:a,xp:t.xp.xp,level:t.xp.level,websiteId:c,countryCode:f,lastPaymentDate:t.lastPaymentTime,registrationDate:t.registrationDate,playerName:t.playerIdentity.name};Object.assign(n,m),n.emit(o.CxfEvents.Login,m),u(o.CxfEvents.Login+" emitted",m)}))}(n,e)})),e.on("3",(function(){})),e.on("LOGIN",(function(n){e.emit(o.CxfEvents.JoinTempServer,!1),u(o.CxfEvents.JoinTempServer+" emitted",!1)})),e.on("2",(function(){}))}function l(e){e.on("REGISTER",(function(n){u(o.CxfEvents.Signup,n),e.emit(o.CxfEvents.Signup),e.emit(o.CxfEvents.JoinTempServer,!1),u(o.CxfEvents.JoinTempServer+" emitted",!1)})),e.on("1",(function(){}))}function m(e){e.on("TEMP_SERVER_LOGIN_OR_REGISTER",(function(n){e.emit(o.CxfEvents.JoinTempServer,!0),u(o.CxfEvents.JoinTempServer+" emitted",!0)})),e.on("495",(function(){}))}function p(e){var n;e.on("LOGIN_BASIC_DATA",(function(e){n=i.getBigfarmPayload(e).xp.xp})),e.on("SYNC_DATA",(function(t){var r=i.getBigfarmPayload(t).xp.xp;if(n!==r){var s={current:r,prev:n};n=r,u(o.CxfEvents.XpChanged,s),e.emit(o.CxfEvents.XpChanged,s)}})),e.on("32",(function(){}))}function C(e){e.on("LEVEL_UP",(function(n){var t=i.getBigfarmPayload(n).xp.level;u(o.CxfEvents.LevelChanged,t),e.emit(o.CxfEvents.LevelChanged,t)})),e.on("24",(function(){}))}function v(e){e.on("CUSTOM_CXF_PUSH",(function(n){u(o.CxfEvents.Push);var t=i.getBigfarmPayload(n).payload;e.emit(o.CxfEvents.Push,r.decodePayload(t))})),e.on("505",(function(){}))}function g(e){e.on("REWARDED_AD_START",(function(n){u(o.CxfEvents.RewardedAdStart),e.emit(o.CxfEvents.RewardedAdStart,0)})),e.on("632",(function(){})),e.on("REWARDED_AD_DONE",(function(n){u(o.CxfEvents.RewardedAdDone),e.emit(o.CxfEvents.RewardedAdDone,0)})),e.on("633",(function(){}))}n.subscribeToToken=c,n.subscribeToSubscription=f,n.subscribeToLogin=d,n.subscribeToSignup=l,n.subscribeToJoinTempServer=m,n.subscribeToXPChanges=p,n.subscribeToLevelChanges=C,n.subscribeToPushEvents=v,n.subscribeToRewardedAdEvents=g},function(e,n,t){"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};Object.defineProperty(n,"__esModule",{value:!0}),n.subscribeToGameEvents=n.toGameEvent=void 0;var o=t(9),i=t(1),s=t(0);function a(e){return r(r({},e),{type:e.episodeId,stopDate:s.timeLeftToStopDate(e.remainingTime)})}n.toGameEvent=a,n.subscribeToGameEvents=function(e){var n=s.debug.extend("subscribeToGameEvents");e.on("ACTIVE_EPISODE_DATA",(function(t){n("ACTIVE_EPISODE_DATA",t);var r=o.getBigfarmPayload(t).episodeData;e.emit(i.CxfEvents.GameEventUpdate,(r||[]).map(a))})),e.on("94",(function(){})),e.on("START_EPISODE",(function(t){n("START_EPISODE",t);var r=o.getBigfarmPayload(t).episodeData;e.emit(i.CxfEvents.GameEventAdd,a(r))})),e.on("95",(function(){})),e.on("END_EPISODE",(function(t){n("END_EPISODE",t);var r=o.getBigfarmPayload(t).episodeId;e.emit(i.CxfEvents.GameEventRemove,r)})),e.on("96",(function(){}))}}]);