token.kaios.backendRoot.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cobalt Show documentation
Show all versions of cobalt Show documentation
Standalone fully-featured Whatsapp Web API for Java and Kotlin
"use strict";class Script{constructor(){this.modulePath=""}set charset(e){}set timeout(e){}set src(e){this.modulePath=e}set onerror(e){this.onerrorCb=e}set onload(e){this.onloadCb=e}setAttribute(){}load(){let e=!0;try{importScripts(this.modulePath)}catch(t){e=!1,this.onerrorCb&&this.onerrorCb({type:"error",target:{src:this.modulePath}})}e&&this.onloadCb&&this.onloadCb({type:"load",target:{src:this.modulePath}})}}var fakeHead={appendChild(e){e.load()}},document={getElementsByTagName:e=>"head"===e?[fakeHead]:[],createElement:e=>"script"===e?new Script:{},head:fakeHead};self.document=document,(function(e){function t(t){for(var o,a,i=t[0],d=t[1],l=t[2],c=0,p=[];c{try{e()}catch(e){console.error(`WhatsApp ServiceWorker failed to shutdown [${t}]`)}})}function m(e,t){console.log("WhatsApp ServiceWorker shutting down");var r=Promise.resolve(),v=[()=>{t&&(r=(function(){var e=(0,u.d)();if(!e)return console.warn("WhatsApp ServiceWorker shutdown deferVoipDaemonShutdownIfNeeded forgetDaemonSession returned null"),Promise.resolve();var t=(0,p.n)().then(()=>{console.log("WhatsApp ServiceWorker shutdown deferVoipDaemonShutdownIfNeeded wait for eviction completed")});return(t=(0,b.b)(t,3e4,()=>{console.warn("WhatsApp ServiceWorker shutdown waitForVoipDaemonEviction completed on timeout")})).then(()=>e).then(e=>{e.close()})})()),r.then(()=>{j(f)})},...g,()=>(0,n.o)(),()=>(0,s.closeLogs)(),()=>(0,a.closeWamStore)(),()=>(0,i.a)(),()=>(0,d.X)(),()=>(0,l.d)(),()=>(0,o.jobsTable)().close(),()=>(0,u.b)(),()=>r.then(e,e)];j(v);var h=(0,c.g)();h.length>0&&console.error(`WhatsApp ServiceWorker dangling tables: [${h.join(", ")}]`),(0,c.a)()}},517:function(e,t,r){r.r(t);var o,n=r(13),s=Math.floor(Date.now()/1e3),a=!1,i=!1;function d(e,t,i){if(o)return o;self.Promise=r(449).default,self.onerror=function(e,t,n){a||(r(136).crashlog("onerror",e),__LOG__(4)`filename: ${t} lineno: ${n}`,o.then(e=>{e.bridge.fireAndForget("basic","sendLogs",{manual:!1})}))},self.onunhandledrejection=function(e){if(!a){e.preventDefault();var t=e.reason,n=e.promise;self.ERROR&&t&&"QuotaExceededError"===t.name?(__LOG__(4)`Unhandled dexie promise rejection: ${e}`,r(136).crashlog("dexie rejected",String(t))):(r(136).crashlog("rejected",t),__LOG__(4)`### begin stack trace ${"2.2329.8"}\n${null==t?void 0:t.stack}`,__LOG__(4)`### end stack trace`,__LOG__(4)`promise: ${n}`),(function(e){o.then(t=>{var r=t.bridge;"QuotaExceededError"===(null==e?void 0:e.name)&&r.fireAndForget("event","ranOutOfStorage",{}),a?__LOG__(4)`Tried to send logs for an unhandled rejection, but the worker was shutting down`:r.fireAndForget("basic","sendLogs",{manual:!1})},()=>{__LOG__(4)`Tried to handle unhandled rejection, but the startup promise has been rejected`})})(t)}};var d=r(136);if(d.initializeLogger(e,e=>{o.then(e=>{e.bridge.fireAndForget("basic","sendLogs",{manual:!1})})}),n.i(b),Date.now()>=1705967999e3)throw __LOG__(4)`Worker ${s} expired!`,self.SwEventHandlers={},new Error("build expired!");var l=r(201);self.WAM=l;var u=r(164);return u.startWamStore(),u.submitInitialAttributes(),r(452).startAbPropsStore(),__LOG__(2)`Backend::startUp`,(o=Promise.resolve().then(()=>{var e=r(266);return r(217).loadInfoStore().then(t=>Promise.all([e.initLanguage(t.lang),e.initPolyfill()]).then(()=>t))}).then(e=>{var o=e.appMode,n=e.appBuild;return(t?t(o,n):Promise.resolve()).then(()=>(d.initializeLogsTable(),r(525).startInWorkerBackend(o,i).then(e=>({bridge:e,appMode:o}))))})).then(()=>{__LOG__(2)`Backend Started!`},e=>{__LOG__(4)`Backend errored ${e.stack}\n${o.toString()}`}),o}var l,u=!1,c=new Promise(e=>{l=e}),p=null;function b(){a||(p&&(clearTimeout(p),p=null),a=!0,r(291).shutdown(l,i))}function g(e){a||(null!=p&&clearTimeout(p),p=setTimeout(b,e))}var f=null;function v(e){if(null!=f)return f;n.h(!1),n.g(()=>{g(6e4)}),d("SW",(e,t)=>"2.2329.8"!==t?Promise.all([r.e(4),r.e(8),r.e(164)]).then(r.bind(null,502)).then(t=>t.initializeMigrations("SW",e)).then(e=>{if("migration-needed"===e.type)return e.migration()}):Promise.resolve(),!1),e&&r(291).runOnShutdown(e);var t=o.then(e=>{var t=e.bridge;if("reg"===e.appMode.mode)r(527).onRegPush(t);else{var o,n=r(217).DEVICE_INFO.get(),s=r(217).SERVER_PROPS.get(),a=r(217).AB_PROPS.get(),i=a.abKey,d=a.expoKeyStr;null!=i&&null!=d&&(o=d),WAM.logAttributes([["regular","private"],15,2,n.osVersion,["regular","private"],13,2,n.device,["regular","private"],5,0,parseInt(n.mcc,10),["regular","private"],3,0,parseInt(n.mnc,10),["regular"],2141,2,s.abKey,["regular"],4473,2,i,["regular","private"],5029,2,o]),r(526).attachHeadlessHandlers(t)}return g(6e4),c});return f={bridge:o,pushFinished:t}}self.SwEventHandlers={"bridge-channel"(e){if(!o){var t=e.data,s=e.ports,a=t.deviceInfo,i=t.hasWifi,l=t.shouldStartVoip;n.h(!0),d("BACK",null,l),__LOG__(2)`Backend establishing channel`;var u=s[0];o.then(e=>{var t=e.bridge;r(217).DEVICE_INFO.set(a);var o,n=r(217).SERVER_PROPS.get(),s=r(217).AB_PROPS.get(),d=s.abKey,l=s.expoKeyStr;null!=d&&null!=l&&(o=l),WAM.logAttributes([["regular"],23,1,i,["regular"],105,0,i?1:a.carrier.radioType,["regular","private"],15,2,a.os.version,["regular","private"],13,2,a.device,["regular","private"],5,0,parseInt(a.carrier.mcc,10),["regular","private"],3,0,parseInt(a.carrier.mnc,10),["regular"],2141,2,n.abKey,["regular"],4473,2,d,["regular","private"],5029,2,o]),u.postMessage({type:"bridge-channel-ready"});var c=r(149),p=c.attachBatchedPortal(t,["page","event","regPage","debug"]);c.warnOnMissingHandlers(t),__LOG__(2)`Backend bridge is ready`,p.setPort(u)})}},onPush(e){if(!u)return u=!0,v(e).pushFinished},onCallRejected(){var e=v();return e.bridge.then(e=>{e.bridge.fireAndForget("voip","rejectVoipCall",{})}),e.pushFinished},onCallAccepted(){f?(__LOG__(2)`Backend in incoming call`,i=!0):console.error("WhatsApp accept call notification went to new ServiceWorker")}}},526:function(e,t,r){r.r(t),r.d(t,"attachHeadlessHandlers",(function(){return w}));var o=r(9),n=r.n(o),s=r(132),a=r(349),i=r(52),d=r(21),l=r(59),u=r(54),c=r(74),p="/icons/call-notif-avatar.svg",b=r(230),g=r(213),f=r(8),v=r(156),h=r(92),j=r(149),m=r(291),_=r(351),S=r(123),M=r(13),k=r(232),y=r(25),R=r(208),C=r(40);function w(e){var t=e,r=null;function o(){}var w={finishedBooting:o,chatModified:o,chatCleared:o,contactsModified:o,msgAcked:o,mediaUpdated:o,msgMediaStatusUpdated:o,chatRead:o,fullsizeAvatarLoaded:o,avatarsUpdated:o,clearUserLastSeen:o,receiveChatState:o,receivePresence:o,blockList:o,clockSkewUpdated:o,serverPropsUpdated:o,msgsDeleted:o,msgsDeletedFromManyChats:o,chatDeleted:o,kicked(){(0,M.j)()},profilePicReceived(){throw new h.a("profilePicReceived")},ranOutOfStorage:o,voipSetupDone:o,gdprReportUpdated:o,gdprReportDownloaded:o,gdprReportDownloading:o,twoFactorReminderVerified:o,openChatWithGroup:o,groupInvitesRevoked:o,groupInviteCode:o,groupInviteCodeReset:o,callMuteStateChanged:o,callInterruptedStateChanged:o,callOfferNacked:o,callDurationChanged:o,callEnded:o,voipServiceDisconnected:o,callBusyReceived:o,callLogsUpdated:o,voipCallFailed:o,statusAuthorsLoaded:o,statusAuthorMeUpdated:o,statusAuthorsCleared:o,statusReceiptsUpdated:o,statusAuthorUpdated:o,statusAuthorsUpdated:o,statusMsgsUpdated:o,statusMsgRemoved:o,aboutUpdated:o,identityVerificationChanged:o,voipStatusChanged:o,hsmButtonPressed:o,statusSettingsUpdated:o,statusLastUnreadMsgLoaded:o,uiJobsInitialized:o,uiJobUpdated:o,uiJobScheduled:o,uiJobCleared:o,uiEphemeralTimestamp:o,refreshRecentGifs:o,addFavoriteGifs:o,removeFavoriteGif:o,viewOnceExpired:o,syncAbCacheFromStorage:o,pinAbProp:o,tosGatingStatusChanged:o,companionsLoaded:o,companionRegistrationFailed:o,trustedContactTokenUpdatedForJid:o,pastParticipantsUpdated:o,callStateChanged:t=>{var o=t.state,s=t.peerJid;if(!t.isCaller&&((function(e,t){var r;"incoming"===e?Promise.all([(0,u.f)(t),(r=t,(0,c.getProfilePicTable)().getThumb(r).then(e=>{var t=null==e?void 0:e.image;return null!=t?(function(e){return new Promise((t,r)=>{var o=new FileReader;o.onerror=()=>r("blobToDataUrl error while reading blob as DataURL"),o.onload=()=>{var e=o.result;"string"==typeof e?t(e):r("blobToDataUrl after onload, result is not a string")},o.readAsDataURL(e)})})(t).catch(()=>p):p}))]).then(e=>{var r=n()(e,2),o=r[0],s=r[1];(function(e,t,r){(0,i.q)(e,{body:(0,d.l)(90),requireInteraction:!0,actions:[{action:"accept",title:(0,d.l)(78)},{action:"reject",title:(0,d.l)(105)}],data:{action:i.c,jid:r},tag:i.d,image:t,mozbehavior:{soundFile:"default_dialer_ringtone",vibrationPattern:[750,1500],loopControl:{sound:!0,soundMaxDuration:45e3,vibration:!0,vibrationMaxDuration:45e3}}})})((0,l.d)(o,"long"),s,t)}):"none"===e&&(0,i.o)(i.c,i.d).then(e=>e.forEach(e=>e.close()))})(o,s),null==r)){var a=new _.a("wa-bridge");r=a,(0,m.runOnShutdown)(()=>{__LOG__(2)`Removing handler from wa-bridge BroadcastChannel`,r&&r.silenceChannel()}),(0,m.runAfterVoipEviction)(()=>{console.log("Closing wa-bridge BroadcastChannel"),r&&(r.close(),r=null)}),a.onmessage=t=>{r&&"connect-page-to-sw"===t.data&&(r.startMonitoring({onTimeout:()=>{__LOG__(2)`Channel to the page lost, ending the call`,(0,S.b)(!0),r&&(r.close(),r=null),e.setHandlers("event",w)}}),(0,j.attachBatchedPortal)(e,["event"]).setPort(a))}}},callMissed(e){var t=e.peerJid,r=e.id;(0,u.f)(t).then(e=>(0,b.b)(e,r,"alert"))},msgBgUpdated:o,reactionReceived:o,notifyNewReaction(e){var t=e.msg,r=e.reaction;Promise.all([(0,u.b)(),(0,y.t)(t.chatId)]).then(e=>{var o=n()(e,2),s=o[0],a=o[1];a&&(0,k.c)(r,t,a,(0,C.e)(s),(0,v.f)(),f.k.get(),"alert")})},msgsReceived(e){var r=e.affectedChats,o=e.newMsgs,n=e.changedMsgs;(0,u.b)().then(e=>{self.registration||__LOG__(4)`self.registration is not available within the HeadlessApi`,(0,s.a)({affectedChats:r,newMsgs:o,changedMsgs:n,settings:f.k.get(),contacts:(0,C.e)(e),type:"alert",user:(0,v.f)(),fireAndForget:t.fireAndForget})})},gdprReportReadyReceived(){(0,a.a)("alert")},commsConnected:o,commsDisconnected:o,votesNotSent:o,notifyMessageKept:e=>{var t=e.msg;(0,u.b)().then(e=>{(0,R.b)(t,(0,C.e)(e),(0,v.f)())})}};e.setHandlers("event",w),e.setNamespaceHandler("page",(e,t,r)=>{var o;switch(e){case"getPushEndpoint":o=(0,g.a)();break;case"getNetworkInfo":o={isWifiConnected:!1,isRoaming:!1};break;case"reload":(0,M.j)();break;default:throw new h.a(e)}r&&r(o)}),(0,j.warnOnMissingHandlers)(e)}},527:function(e,t,r){r.r(t),r.d(t,"onRegPush",(function(){return i}));var o=r(364),n=r(189),s=r(21),a=r(52);function i(e){var t=new o.a(e,()=>Promise.resolve());t.getStoreInStates2(["BAN_APPEAL","BLOCKED_BAN_APPEAL"])&&(0,n.b)(t).then(e=>{var t,r;e&&(t=(0,s.l)(56),r={body:(0,s.l)(55),data:{action:a.a},tag:a.b},(0,a.q)(t,r))})}r(41)}});