UNPKG

@tencentcloud/donut-push

Version:

Push Service provides a one-stop app push solution, helping you easily enhance user retention and interaction activity.

2 lines (1 loc) 5.25 kB
function e(e,n,t,r){return new(t||(t=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(u,c)}s((r=r.apply(e,n||[])).next())}))}function n(e,n){var t,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return u.next=c(0),u.throw=c(1),u.return=c(2),"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(c){return function(s){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;u&&(u=0,c[0]&&(i=0)),i;)try{if(t=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=n.call(e,i)}catch(e){c=[6,e],r=0}finally{t=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}"function"==typeof SuppressedError&&SuppressedError;var t,r,o,i,u,c,s,a,f,l="8.6.1",p=new(r=[],o=new Map,i=!1,u=!1,c=function(e){var n=e.eventName;if(n){var t=o.get(n);t&&t.forEach((function(n){n(e)}))}},s=function(){return new Promise((function(e,n){t?e(t):u?r.push({resolve:e,reject:n}):(u=!0,wx.miniapp.loadNativePlugin({pluginId:"wx369499c8a9c4c19e",success:function(r){if(u=!1,!f(r)){var o="The plugin version ".concat(r.getVersion()," is too low, please select a plugin version of ").concat(l," or higher.");return n(o),void a(void 0,o)}console.info("Load push plugin success",r),t=r,r.onMiniPluginEvent(c),e(r),a(r,void 0)},fail:function(e){u=!1,console.error("Load push plugin failed",e),n(e),a(void 0,e)}}))}))},a=function(e,n){r.forEach((function(t){e?t.resolve(e):t.reject(n)})),r=[]},f=function(e){var n=e.getVersion().split("."),t=1e6*Number.parseInt(n[0])+1e3*Number.parseInt(n[1])+Number.parseInt(n[2]),r=l.split(".");return!(t<1e6*Number.parseInt(r[0])+1e3*Number.parseInt(r[1])+Number.parseInt(r[2]))},function(){function t(){this.EventName={NOTIFICATION_CLICKED:"notification_clicked",MESSAGE_RECEIVED:"message_received",MESSAGE_REVOKED:"message_revoked"}}return t.prototype.registerPush=function(t,r){var o=this;return new Promise((function(i,u){return e(o,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,s()];case 1:return null==(e=n.sent())||e.registerPush({sdkAppID:t,appKey:r},(function(e){e&&0===e.errCode?i(e):u(e)})),[2]}}))}))}))},t.prototype.unRegisterPush=function(){var t=this;return new Promise((function(r,o){return e(t,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,s()];case 1:return null==(e=n.sent())||e.unRegisterPush({},(function(e){e&&0===e.errCode?r(e):o(e)})),[2]}}))}))}))},t.prototype.setRegistrationID=function(t){var r=this;return new Promise((function(o,i){return e(r,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,s()];case 1:return null==(e=n.sent())||e.setRegistrationID({registrationID:t},(function(e){e&&0===e.errCode?o(e):i(e)})),[2]}}))}))}))},t.prototype.getRegistrationID=function(){var t=this;return new Promise((function(r,o){return e(t,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,s()];case 1:return null==(e=n.sent())||e.getRegistrationID({},(function(e){e&&0===e.errCode?r(e):o(e)})),[2]}}))}))}))},t.prototype.addPushListener=function(e,n){var t=o.get(e);t||(t=new Set,o.set(e,t)),console.info("Add a listener for the ".concat(e," event.")),t.add(n),e===this.EventName.NOTIFICATION_CLICKED&&(i||(i=!0,s().then((function(e){e.init()})).catch((function(e){console.error("Push service init failed",e)}))))},t.prototype.removePushListener=function(e,n){if(console.info("Remove listener for the ".concat(e," event.")),n){var t=o.get(e);t&&t.delete(n)}else o.delete(e)},t.prototype.disablePostNotificationInForeground=function(e){s().then((function(n){n.disablePostNotificationInForeground({disable:e})})).catch((function(e){console.error("disablePostNotificationInForeground failed",e)}))},t.prototype.createNotificationChannel=function(t){var r=this;return new Promise((function(o,i){return e(r,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,s()];case 1:return null==(e=n.sent())||e.createNotificationChannel(t,(function(e){e&&0===e.errCode?o(e):i(e)})),[2]}}))}))}))},t.prototype.setCustomBadgeNumber=function(t){var r=this;return new Promise((function(o,i){return e(r,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,s()];case 1:return null==(e=n.sent())||e.setCustomBadgeNumber({badgeNumber:t},(function(e){e&&0===e.errCode?o(e):i(e)})),[2]}}))}))}))},t}());export{p as default};