Skip to content

non #4625

@Monster6969696969

Description

@Monster6969696969

__d("WAComms",["Promise","WAArrayUtils","WAErrors","WALogger","WANotifyConnectionChangeFactory","WAPromiseRetryLoop","WAResolvable","WAResultOrError","WAShiftTimer","WASmaxInPingsClientResponseServerResponse","WASmaxOutPingsClientRequest","WASmaxParseUtils","WATimeUtils","WAWap","err","regeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";var h;function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["Comms has no open socket"]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] closeSocket called"]);j=function(){return a};return a}function k(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] Socket "," closed"]);k=function(){return a};return a}function l(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] socketLoopIteration failed ",""]);l=function(){return a};return a}function m(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] socketLoopIteration socket closed while in noise handshake"]);m=function(){return a};return a}function n(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] socketLoopIteration socket disconnected while in noise handshake"]);n=function(){return a};return a}function o(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] socketLoopIteration socket closed while in noise handshake using treasureHunt strategy"]);o=function(){return a};return a}function p(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] Socket "," closed"]);p=function(){return a};return a}function q(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] Socket "," opened"]);q=function(){return a};return a}function r(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] Socket "," opening"]);r=function(){return a};return a}function s(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] maybeResetSocketLoop"]);s=function(){return a};return a}function t(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] closeSocketAndPreventRetry called"]);t=function(){return a};return a}function u(){var a=babelHelpers.taggedTemplateLiteralLoose(["handleAck: unrecognized ",""]);u=function(){return a};return a}function v(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] job response is CLOSE_SOCKET"]);v=function(){return a};return a}function w(){var a=babelHelpers.taggedTemplateLiteralLoose(["--- Receiving ---\n",""],["--- Receiving ---\n",""]);w=function(){return a};return a}function x(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failure parsing stanza!"]);x=function(){return a};return a}function y(){var a=babelHelpers.taggedTemplateLiteralLoose(["Comms.startHandlingRequests"]);y=function(){return a};return a}function z(){var a=babelHelpers.taggedTemplateLiteralLoose(["castStanza error ",""]);z=function(){return a};return a}function A(){var a=babelHelpers.taggedTemplateLiteralLoose(["castStanza async error ",""]);A=function(){return a};return a}function B(){var a=babelHelpers.taggedTemplateLiteralLoose(["--- Sending ---\n",""],["--- Sending ---\n",""]);B=function(){return a};return a}function C(){var a=babelHelpers.taggedTemplateLiteralLoose(["Error in onBeforeCastStanza, we consumed and continue with normal stanza sending to the server:\n",""],["Error in onBeforeCastStanza, we consumed and continue with normal stanza sending to the server:\n",""]);C=function(){return a};return a}function D(){var a=babelHelpers.taggedTemplateLiteralLoose(["Dropping stanza since onBeforeCastStanza matched. We return mock response directly."]);D=function(){return a};return a}function E(){var a=babelHelpers.taggedTemplateLiteralLoose(["--- Receive (via SMAX+E2E) ---\n",""],["--- Receive (via SMAX+E2E) ---\n",""]);E=function(){return a};return a}function F(){var a=babelHelpers.taggedTemplateLiteralLoose(["Dropping stanza since onBeforeCastStanza matched:\n",". We return mock response directly."],["Dropping stanza since onBeforeCastStanza matched:\n",". We return mock response directly."]);F=function(){return a};return a}function G(){var a=babelHelpers.taggedTemplateLiteralLoose(["Comms has no open socket, will resend stanza when socket opens"]);G=function(){return a};return a}function H(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] No stanzaId in ping request stanza"]);H=function(){return a};return a}function I(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] sendPing ping still pending"]);I=function(){return a};return a}function J(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] sendPing when socket dead"]);J=function(){return a};return a}function K(){var a=babelHelpers.taggedTemplateLiteralLoose(["[comms] Socket "," expired"]);K=function(){return a};return a}function L(){var a=babelHelpers.taggedTemplateLiteralLoose(["handleIq no handler for iq"]);L=function(){return a};return a}function M(){var a=babelHelpers.taggedTemplateLiteralLoose(["handleIq no handler for iq with id ",""]);M=function(){return a};return a}var N=null,O=null,P=1,Q=0,R=function(){function a(a,c,e){var f=this;this.nextSocketId=1;this.pendingIqs=new Map();this.ackHandlers=[];this.pendingSmaxStanzas=new Map();this.$2=new(d("WAResolvable").Resolvable)();this.socketAbortController=null;this.activePing=null;this.$3=new Set();this.socketId=Q;this.socket=null;this.softCloseSocket=null;this.handleStanza=function(a,b,c){var e=d("WASmaxParseUtils").attrString(a,"id");if(e.success&&a.tag!=="receipt"){e=e.value;var g=f.pendingSmaxStanzas.get(e);if(g){f.pendingSmaxStanzas"delete";g.resolve(a);f.maybeScheduleHealthCheck();return"NO_ACK"}}e=$(a);if(e!=null){g=f.pendingIqs.get(e);g?(f.pendingIqs"delete",g.resolve(a),f.maybeScheduleHealthCheck()):(d("WALogger").WARN(M(),e),d("WALogger").ERROR(L()))}else if(a.tag==="ack")f.handleAck(a);else return a.tag==="failure"&&f.config.shouldBlockReceivingUntilSuccess?f.$1(a,b,c):f.$2.promise.then(function(){return f.$1(a,b,c)});return"NO_ACK"};this.healthCheckTimer=new(d("WAShiftTimer").ShiftTimer)(function(){if(!f.socketId)return;void f.sendPing()});this.deadSocketTimer=new(d("WAShiftTimer").ShiftTimer)(function(a){if(a!==f.socketId)return;d("WALogger").LOG(K(),a);f.softCloseSocket&&f.softCloseSocket()});this.sendPing=function(){var a,c,e,f,g,i,j,k;return b("regeneratorRuntime").async(function(l){while(1)switch(l.prev=l.next){case 0:a=Z("sendPing");if(a.socketId){l.next=4;break}d("WALogger").LOG(J());return l.abrupt("return",(h||(h=b("Promise"))).resolve());case 4:if(!(a.activePing&&a.activePing.socketId===a.socketId)){l.next=7;break}d("WALogger").LOG(I());return l.abrupt("return",(h||(h=b("Promise"))).resolve());case 7:a.activePing&&a.activePing.handler.resolve();c=d("WASmaxOutPingsClientRequest").makeClientRequest();e=c.attrs.id;if(!(typeof e!=="string")){l.next=13;break}d("WALogger").ERROR(H());return l.abrupt("return",(h||(h=b("Promise"))).resolve());case 13:f=new(d("WAResolvable").Resolvable)();a.activePing={socketId:a.socketId,stanzaId:e,handler:f};void a.callStanza(c);l.next=18;return b("regeneratorRuntime").awrap(f.promise);case 18:g=l.sent,g&&(i=d("WASmaxInPingsClientResponseServerResponse").parseClientResponseServerResponse(g,c),i.success&&(j=d("WATimeUtils").castToUnixTime(i.value.t),k=Math.round(Date.now()/1e3-j),a.config.handlers.onClockSkewUpdate==null?void 0:a.config.handlers.onClockSkewUpdate(k)));case 20:case"end":return l.stop()}},null,this)};this.$1=a;this.onConnectionChange=d("WANotifyConnectionChangeFactory").notifyConnectionChangeFactory((a=c.handlers.onConnectionChange)!=null?a:function(){},(a=c.handlers.onOptimisticConnectionChange)!=null?a:function(){});this.gzipInflate=e;this.config=c;this.socketLoop=new(d("WAPromiseRetryLoop").PromiseRetryLoop)({name:"MainSocketLoop",code:W,timer:(a=c.socketReconnectBackoffAlgo)!=null?a:{jitter:.1,max:c.maxSocketLoopWaitTime,algo:{type:"fibonacci",first:1e4,second:1e4},relativeDelay:!0},resetDelay:3e4})}var e=a.prototype;e.filterPending=function(a){var b=[];function c(c){a(c)&&b.push(c)}this.pendingIqs.forEach(c);this.ackHandlers.forEach(c);this.pendingSmaxStanzas.forEach(c);return b};e.sendPendingStanza=function(a){a.cleanup==null?void 0:a.cleanup(),a.cleanup=void 0,void this.callStanza(a.stanza)};e.maybeSendPendingStanza=function(a){if(a.attempt>=this.config.maxRetries)this.config.handlers.onDropStanza==null?void 0:this.config.handlers.onDropStanza(a),a.cleanup==null?void 0:a.cleanup(),a.cleanup=void 0,this.removeHandler(a,"max-retries");else if(this.socket){a.attempt+=1;this.sendPendingStanza(a);return}else d("WALogger").LOG(G())};e.callStanzaAsync=function(a,c){var d;return b("regeneratorRuntime").async(function(e){while(1)switch(e.prev=e.next){case 0:e.next=2;return b("regeneratorRuntime").awrap(this.callStanza(a,c));case 2:d=e.sent;return e.abrupt("return",d);case 4:case"end":return e.stop()}},null,this)};e.callStanza=function(a,b){a=this.castStanza(a,b);this.deadSocketTimer.onOrBefore(this.config.deadSocketTime,this.socketId);this.healthCheckTimer.cancel();return a};e.castStanzaAsync=function(a){var c;return b("regeneratorRuntime").async(function(d){while(1)switch(d.prev=d.next){case 0:d.next=2;return b("regeneratorRuntime").awrap(this.castStanza(a));case 2:c=d.sent;return d.abrupt("return",c);case 4:case"end":return d.stop()}},null,this)};e.castStanza=function(a,c){var e=this;try{var f=this.config.handlers.onBeforeCastStanzaForE2E==null?void 0:this.config.handlers.onBeforeCastStanzaForE2E(a,c);if(f!=null){d("WALogger").DEV_XMPP(F(),a);d("WALogger").DEV_XMPP(E(),f);d("WALogger").ERROR(D());if(Array.isArray(f))return(h||(h=b("Promise"))).all(f.map(function(a){return(h||(h=b("Promise"))).resolve(e.handleStanza(a,e.socketId,Q))}));else{this.handleStanza(f,this.socketId,Q);return(h||(h=b("Promise"))).resolve()}}}catch(a){d("WALogger").DEV_XMPP(C(),a)}f=this.socketOrThrow("castStanza");try{d("WALogger").DEV_XMPP(B(),a);return f.sendFrame(d("WAWap").encodeStanza(a)).then(function(){e.config.handlers.onCastStanza==null?void 0:e.config.handlers.onCastStanza(a,c)})["catch"](function(a){d("WALogger").ERROR(A(),a).devConsole(a);if(a instanceof d("WAErrors").BufferTooLargeError)return(h||(h=b("Promise"))).reject(a)})}catch(a){d("WALogger").ERROR(z(),a).devConsole(a)}return(h||(h=b("Promise"))).resolve()};e.socketOrThrow=function(a){var b=this.socket;if(b)return b;throw c("err")("Comms."+a+" called while no socket")};e.startHandlingRequests=function(){d("WALogger").LOG(y());this.$2.resolve();return this.$2.promise.then(function(){})};e.parseAndHandleStanza=function(a,b){var c=this;a===this.socketId&&(this.deadSocketTimer.cancel(),O&&(O.resolve(),O=null));var e=d("WAWap").decodeStanza(b,this.gzipInflate)["catch"](function(a){d("WALogger").ERROR(x()).devConsole(b);throw a}).then(function(e){d("WALogger").DEV_XMPP(w(),e);c.config.handlers.onHandleStanza==null?void 0:c.config.handlers.onHandleStanza(e,a,b.byteLength);var f=c.activePing;if(f&&f.socketId===a&&f.stanzaId===$(e)){c.activePing=null;f.handler.resolve(e);c.maybeScheduleHealthCheck();return"NO_ACK"}return c.handleStanza(e,a,b.byteLength)}).then(function(b){if(a!==c.socketId)return;if(b==="CLOSE_SOCKET"){d("WALogger").LOG(v());var e=c.socket;e&&e.close()}else b==="NO_ACK"||void c.castStanza(b);return"NO_ACK"});this.$3.add(e);e["finally"](function(){return void c.$3"delete"})};e.handleAck=function(a){var b=this.ackHandlers,c=-1,e=null;while(!e&&++c<b.length)e=b[c].parseAndTest(a);if(e){var f=b[c];d("WAArrayUtils").removeIndexWithoutPreservingOrder(b,c);this.config.handlers.onHandleAck==null?void 0:this.config.handlers.onHandleAck(a);f.resolve(e);this.maybeScheduleHealthCheck()}else d("WALogger").WARN(u(),a)};e.removeHandler=function(a,c){c===void 0&&(c="disconnect");if(a.type==="iq"||a.type==="smax"){var e=a.stanza.attrs.id;if(!e||typeof e!=="string")return;if(a.type==="iq"&&!this.pendingIqs"delete"||a.type==="smax"&&!this.pendingSmaxStanzas"delete")return}else{a.type;e=this.ackHandlers.indexOf(a);if(e===-1)return;d("WAArrayUtils").removeIndexWithoutPreservingOrder(this.ackHandlers,e)}c==="disconnect"?a.resolve((h||(h=b("Promise"))).reject(new(d("WAErrors").Disconnected)())):c==="abort"?a.resolve((h||(h=b("Promise"))).reject(new(d("WAErrors").Aborted)())):a.resolve((h||(h=b("Promise"))).reject(new(d("WAErrors").MaxRetries)()))};e.maybeScheduleHealthCheck=function(){if(this.healthCheckTimer.isScheduled())return;if(this.activePing||this.ackHandlers.length||this.pendingIqs.size||this.pendingSmaxStanzas.size)return;var a=this.config.healthCheckInterval;a=Math.ceil(a1e3(1+Math.random()));this.healthCheckTimer.onOrBefore(a)};return a}();function a(){return N}function e(a,b,c,d){d===void 0&&(d=!0);if(N)return;N=new R(a,b,c);d&&setTimeout(T,0)}function f(){var a=Z("stopComms");a.socketLoop.endWithValue();a.socket&&X();N=null}function S(){var a=Z("closeSocketAndPreventRetry");a.socketLoop.endWithValue();a.socket&&(d("WALogger").LOG(t()),X())}function T(){Z("openSocketLoop").socketLoop.start()}function U(){d("WALogger").LOG(s()),V()||Z("maybeResetSocketLoop").socketLoop.reset()}function aa(){Z("forceResetSocketLoop").socketLoop.reset()}function ba(){var a,b=Z("socketAbortController");(a=b.socketAbortController)==null?void 0:a.abort();b.softCloseSocket==null?void 0:b.softCloseSocket()}function V(){var a;return!!((a=N)==null?void 0:a.socket)}function W(){var a=Z("socketLoopIteration"),b=a.nextSocketId++;d("WALogger").LOG(r(),b);var c=function(){a.onConnectionChange("in_handshake")};a.config.handlers.onSocketLoopIteration==null?void 0:a.config.handlers.onSocketLoopIteration(a.socketAbortController);typeof AbortController==="function"&&(a.socketAbortController=new AbortController());return a.config.openChatSocket(c,(c=a.socketAbortController)==null?void 0:c.signal).then(d("WAResultOrError").onResult(function(c){a.config.handlers.onSocketOpen==null?void 0:a.config.handlers.onSocketOpen();var e=new(d("WAResolvable").Resolvable)();d("WALogger").LOG(q(),b);a.socketId=b;a.socket=c;a.softCloseSocket=function(){a.softCloseSocket=null,a.socket&&a.config.shouldCloseStaleSocket&&(X(),a.socket=null),e.resolve()};a.socketLoop.resetTimeoutAfter(1e4);a.deadSocketTimer.cancel();a.maybeScheduleHealthCheck();c.setOnFrame(function(c){return a.parseAndHandleStanza(b,c)});c.setOnClose(function(){d("WALogger").LOG(p(),b);a.activePing&&b===a.activePing.socketId&&(a.activePing.handler.resolve(),a.activePing=null);a.filterPending(function(a){return a.attachedToSocketId===b}).forEach(function(b){return void a.removeHandler(b)});if(b!==a.socketId)return;a.socketId=Q;a.socket=null;a.onConnectionChange("disconnected");a.config.handlers.onDisconnect==null?void 0:a.config.handlers.onDisconnect();e.resolve()});a.onConnectionChange("connected");a.config.handlers.onConnect==null?void 0:a.config.handlers.onConnect();a.filterPending(function(a){return!a.attachedToSocketId}).sort(function(a,b){return a.orderedId-b.orderedId}).forEach(function(b){switch(b.type){case"smax":case"iq":a.maybeSendPendingStanza(b);break;case"ack":void a.callStanza(b.stanza);break;default:b.type;break}});return e.promise})).then(d("WAResultOrError").catchError(function(a){switch(a){case"max-hunters":d("WALogger").WARN(o());break;case"disconnected":d("WALogger").WARN(n());break;default:a;return}}))["catch"](function(a){a instanceof d("WAErrors").Disconnected?d("WALogger").LOG(m()):d("WALogger").ERROR(l(),a).devConsole(a)})}function X(){var a=Z("closeSocket");a.socket&&(d("WALogger").LOG(k(),a.socketId),d("WALogger").LOG(j()),a.socket.close())}function ca(){Z("onStreamErrorReceived").socketLoop.cancelReset()}function da(){void Z("waitForConnection").sendPing();O||(O=new(d("WAResolvable").Resolvable)());return O.promise}function ea(a,b){var c=Z("castStanza");c.socket?void c.castStanza(a,b):d("WALogger").LOG(i())}function fa(a){var b=Z("castStanza");return b.socketId===a}function Y(a,e,f,g,i){f===void 0&&(f=0);i===void 0&&(i="iq");return new(h||(h=b("Promise")))(function(j){var k=Z("sendIq"),l=a.attrs.id;if(!l||typeof l!=="string")throw c("err")("[comms] sendIq given iq without id: "+String(a));var m=k.socketId;if(e&&!m){j((h||(h=b("Promise"))).reject(new(d("WAErrors").Offline)()));return}var n=function(a){a===void 0&&(a="disconnect");var d=i==="iq"?k.pendingIqs.get(l):k.pendingSmaxStanzas.get(l);if(!d){j((h||(h=b("Promise"))).reject(c("err")("[comms] _sendIq unexisting stanza to be cancelled: "+l)));return}k.removeHandler(d,a)},o=null;if(f>0){var p=setTimeout(n,f*1e3);o=function(){clearTimeout(p)}}if(g!=null)if(g.aborted){j((h||(h=b("Promise"))).reject(new(d("WAErrors").Disconnected)()));return}else{var q=function(){n("abort")};g.addEventListener("abort",q);o=function(){g.removeEventListener("abort",q)}}m={resolve:j,stanza:a,attachedToSocketId:e?m:Q,orderedId:P++,attempt:0,cleanup:o};if(i==="iq"){o=babelHelpers"extends";k.pendingIqs.set(l,o);k.config.handlers.onSendIq==null?void 0:k.config.handlers.onSendIq(a);k.maybeSendPendingStanza(o)}else{i;o=babelHelpers"extends";k.pendingSmaxStanzas.set(l,o);k.maybeSendPendingStanza(o)}})}function ga(a,b){var c,d;c=(c=b==null?void 0:b.withoutRetry)!=null?c:!1;d=(d=b==null?void 0:b.timeoutSeconds)!=null?d:0;b=(b=b==null?void 0:b.signal)!=null?b:null;return Y(a,c,d,b,"smax")}function ha(){var a=Z("sendPing");return a.sendPing()}function ia(){return Z("startHandlingRequests").startHandlingRequests()}function ja(){N&&N.deadSocketTimer.cancel()}function Z(a){if(N)return N;throw c("err")("[comms] "+a+" called before startComms")}function $(a){if(a.tag==="iq"){var b=a.attrs.type;if(b==="result"||b==="error")return d("WAWap").decodeAsString(a.attrs.id)||null}return null}function ka(){return P++}function la(){N=null,O=new(d("WAResolvable").Resolvable)(),P=1}g.DEFAULT_SOCKET_ID=Q;g.getComms=a;g.startComms=e;g.stopComms=f;g.closeSocketAndPreventRetry=S;g.openSocketLoop=T;g.maybeResetSocketLoop=U;g.forceResetSocketLoop=aa;g.forceAbortSocketConnection=ba;g.isSocketConnected=V;g.socketLoopIteration=W;g.closeSocket=X;g.onStreamErrorReceived=ca;g.waitForConnection=da;g.castSmaxStanza=ea;g.isActiveSocket=fa;g._sendIq=Y;g.sendSmaxStanza=ga;g.sendPing=ha;g.startHandlingRequests=ia;g.cancelDeadSocketTimer=ja;g.singletonOrThrowIfUninitialized=Z;g.getAndIncrementNextOrderedId=ka;g.resetStateForTests=la}),98);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions