solclientjs
Version:
Solace Messaging API for Node.js
2 lines • 516 kB
JavaScript
/*! For license information please see solclient.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("solace",[],t):"object"==typeof exports?exports.solace=t():e.solace=t()}(this,()=>(()=>{var e={43:(e,t,n)=>{const s=n(178),r=n(5898),i=n(3450),o=n(4386),a=n(8205),{assert:c}=n(7444),{CapabilityType:u}=n(2484),{Check:l}=n(802),{CorrelatedRequest:h}=n(8165),{Destination:p}=n(9620),{ErrorResponseSubcodeMapper:d,ErrorSubcode:_,OperationError:E}=n(6706),{FsmEvent:g,State:T,StateMachine:S}=n(7414),{Hex:m}=n(9783),{LogFormatter:f}=n(2694),{Message:I,MessageOutcome:R,MessageDeliveryModeType:C}=n(6247),{P2PUtil:A}=n(7603),{SessionEvent:O}=n(8229),{SessionEventCode:N}=n(6334),{SessionEventName:y}=n(6324),{SessionFSMEvent:P}=n(1122),{SessionRequestType:D}=n(168),{SessionStateName:b}=n(6057),{SslDowngrade:M}=n(6415),{StatType:v,StatsByMode:w}=n(5747),{StringUtils:L}=n(968),{SubscriptionUpdateTimeoutMessages:U}=n(4356),{Codec:F}=n(769),{Convert:x}=n(9783),{anythingToBuffer:B}=x,{formatHexString:G}=m,{stripNullTerminate:k}=L,{STAT_TX_BYMODE_BYTES:W,STAT_TX_BYMODE_MSGS:$,STAT_RX_BYMODE_BYTES:q,STAT_RX_BYMODE_MSGS:V,STAT_TX_BYMODE_REDELIVERED:H,STAT_TX_BYMODE_BYTES_REDELIVERED:Y}=w,Q=(n(97),n(595));e.exports.SessionFSM=class extends S{constructor(e,t,n,r){super({name:"SessionFSM"});const i=this,o=this.logger=new f(function(...e){return[`[session-fsm=${i.sessionIdHex||"(N/A)"}]`,`[${i.getCurrentStateName()}]`,...e]}),{LOG_TRACE:u,LOG_DEBUG:l,LOG_INFO:h}=o;this.log=o.wrap(this.log,this),this._sessionProperties=e,this._session=t,this._sessionStatistics=n,this._hosts=r,this._consumers=new s.ConsumerFlows,this._flowInterfaceFactory=e=>({getCorrelationTag:this.getCorrelationTag.bind(this),incStat:this.incStat.bind(this),sendData:t=>this.send(t,e,!1),sendToTransport:t=>this.sendToTransport(t,e,!1),sendControl:t=>this.send(t,e,!0),enqueueRequest:this.enqueueOutstandingCorrelatedReq.bind(this),createDestinationFromDescriptor:t.createDestinationFromDescriptor.bind(t),createTemporaryDestination:t.createTemporaryDestination.bind(t),isCapable:t.isCapable.bind(t),getCapability:t.getCapability.bind(t),getCurrentStateName:this.getCurrentStateName.bind(this),updateQueueSubscription:t.updateQueueSubscription.bind(t),get sessionIdHex(){return i.sessionIdHex},get canAck(){return t.canAck}}),this._userBackpressured=!1,this.clearCurrentError(),this.initial(function(){return this.transitionTo(i.SessionDisconnected,e=>e.getStateMachine().reset())}),this.unhandledEventReaction(function(e){const t=i.getCurrentState();switch(e.getName()){case y.CREATE_SUBSCRIBER:return c(i._consumers,"collection has lifetime of FSM instance"),i._consumers.add(e.guaranteedFlowObject),this;case y.DISPOSE:return t.terminate(()=>i.disposeInternal());case y.FLOW_UP:return e.guaranteedFlowObject,this;default:return e.getName(),i.getCurrentStateName(),this}}),this.SessionConnecting=new T({name:b.CONNECTING,parentContext:i},{handleTransportDestroyed(){if(i.clearConnectTimer(),i._currentHost=i._hosts.getNextHost(),null===i._currentHost)return this.transitionToExitPoint(i.SessionConnecting,"ErrorExit");const{connectWaitTimeInMsecs:e}=i._hosts;return e>0&&!i._connectWaitTimer?(i._connectWaitTimer=setTimeout(()=>{i._connectWaitTimer=null,i.processEvent(new P({name:y.CONNECT_WAIT_TIMEOUT}))},e),this.transitionTo(i.WaitingForInterConnectTimeout)):this.transitionTo(i.WaitingForTransport)}}).entry(()=>{i.setConnectTimer()}).entryPoint("DisconnectTransport",function(){return i._hosts.reset({wasConnected:void 0,disconnected:!0}),i._connectFailEvent=N.DISCONNECTED,i._connectSuccessEvent=N.DISCONNECTED,this.transitionTo(i.DestroyingTransport)}).entryPoint("ReconnectTransport",function(){i._connectFailEvent=N.DOWN_ERROR,i._connectSuccessEvent=N.RECONNECTED_NOTICE;const e=0===i._sessionProperties._reconnectRetries;if(i._hosts.reset({wasConnected:!0,disconnected:e}),!e){const e=i._currentError||{},t=[e.eventText,e.responseCode,e.errorSubcode,void 0,e.eventReason];i.setPostEventAction(()=>{i.setConnectTimer(),i.emitSessionEvent(O.build(N.RECONNECTING_NOTICE,...t))})}return this.transitionTo(i.DestroyingTransport)}).initial(()=>(i.clearCurrentError(),i._connectFailEvent=N.CONNECT_FAILED_ERROR,i._connectSuccessEvent=N.UP_NOTICE,i._hosts.resolveHosts(e=>i._hosts?e?(i.setCurrentError({errorSubcode:_.UNRESOLVED_HOSTS,eventText:e}),i._hosts.reset({disconnected:!0}),this.processEvent(new P({name:y.EXCEPTION}))):(i._hosts.reset({wasConnected:!1}),i._currentHost=i._hosts.getNextHost(),this.processEvent(new P({name:y.DNS_RESOLUTION_COMPLETE}))):null),this.transitionTo(i.WaitingForDNS))).reaction(y.DNS_RESOLUTION_COMPLETE,function(){return this.transitionTo(i.WaitingForTransport)}).reaction(y.DISCONNECT,function(){return this.transitionToEntryPoint(i.SessionConnecting,"DisconnectTransport")}).reaction(y.CONNECT_TIMEOUT,function(){return i.setCurrentError({errorSubcode:_.TIMEOUT,eventText:"Connect timeout"}),this.transitionTo(i.DestroyingTransport)}).reaction(y.SEND_ERROR,function(e){return h(`SEND_ERROR reached SessionConnecting. ${e}`),i.setCurrentError(e),this.transitionTo(i.DestroyingTransport)}).reaction(y.EXCEPTION,function(e){return i.setCurrentError(e),this.transitionTo(i.DestroyingTransport)}).reaction(y.TRANSPORT_DESTROYED,function(e){return i.setCurrentError(e),h("TRANSPORT_DESTROYED event"),this.transitionTo(i.DestroyingTransport)}).exit(()=>{i.clearConnectTimer(),i._connectWaitTimer&&(clearTimeout(i._connectWaitTimer),i._connectWaitTimer=null)}).exitPoint("ConnectedExit",()=>(i.setPostEventAction(()=>{if(i.emitSessionEvent(O.build(i._connectSuccessEvent,`'${i._hosts.currentHostToString()}'`,200,0,null,null)),i._userBackpressured){const e=O.build(N.CAN_ACCEPT_DATA,"",null,0,null,"");i.emitSessionEvent(e),i._userBackpressured=!1}}),i.clearCurrentError(),this.transitionTo(i.SessionTransportUp))).exitPoint("ErrorExit",function(){return i.setPostEventAction(()=>{const e=i._currentError||{},t=[e.eventText,e.responseCode,e.errorSubcode,void 0,e.eventReason];i.emitSessionEvent(O.build(i._connectFailEvent,...t))}),this.transitionTo(i.SessionDisconnected)}),this.WaitingForDNS=new T({name:b.WAITING_FOR_DNS,parentContext:i.SessionConnecting}),this.DestroyingTransport=new T({name:b.DESTROYING_TRANSPORT,parentContext:i.SessionConnecting}).entry(()=>{h("Connecting, disposing transport"),i.clearConnectTimer(),i.destroyTransportSession("Disconnecting session",0)}).reaction(y.TRANSPORT_DESTROYED,function(e){return i.setCurrentError(e),i.SessionConnecting.handleTransportDestroyed.call(this)}),this.WaitingForInterConnectTimeout=new T({name:b.WAITING_FOR_INTERCONNECT_TIMEOUT,parentContext:i.SessionConnecting}).reaction(y.CONNECT_WAIT_TIMEOUT,function(){return this.transitionTo(i.WaitingForTransport)}),this.WaitingForTransport=new T({name:b.WAITING_FOR_TRANSPORT,parentContext:i.SessionConnecting}).initial(()=>{const e="Cannot establish transport session: creation failed";i.setConnectTimer(),i.clearCurrentError();try{i.initTransport()}catch(t){return this.setCurrentError({eventText:t.message===e?e:`${e}: ${t.message}`,errorSubcode:t.subcode||_.INTERNAL_ERROR,eventReason:t}),i.SessionConnecting.handleTransportDestroyed.call(this)}return this.transitionTo(i.WaitingForTransportUp)}),this.WaitingForTransportUp=new T({name:b.WAITING_FOR_TRANSPORT_UP,parentContext:this.WaitingForTransport}).entry(()=>{this._justEntered=!0}).initial(()=>{if(!this._justEntered)return this;this._justEntered=!1;const e="Cannot establish transport session: connection failed";try{const t=i._transport.connect();if(t!==a.TransportReturnCode.OK)throw new E(e,_.CONNECTION_ERROR,a.TransportReturnCode.describe(t));h(`Attempting to connect session '${i.sessionId}' to ${i._hosts.currentHostToString()}`)}catch(t){return this.setCurrentError({eventText:t.message===e?e:`${e}: ${t.message}`,errorSubcode:t.subcode||_.INTERNAL_ERROR,eventReason:t}),i.SessionConnecting.handleTransportDestroyed.call(this)}return this}).reaction(y.SEND_ERROR,function(e){return h(`SEND_ERROR while waiting for transport up, doing nothing. ${e}`),this.internalTransition(null)}).reaction(y.TRANSPORT_UP,function(e){if(i.sessionId=e.sessionId||"",i.sendClientCtrlLogin()===a.TransportReturnCode.OK)return this.transitionTo(i.WaitingForLogin);const t={eventText:"Failed to send Client Control Login",errorSubcode:_.LOGIN_FAILURE,responseCode:400};return i.setCurrentError(t),this.transitionTo(i.DestroyingTransport)}),this.WaitingForLogin=new T({name:b.WAITING_FOR_LOGIN,parentContext:i.SessionConnecting}).entry(()=>{i.setClientCtrlTimer()}).reaction(y.TRANSPORT_PROTOCOL_CLIENTCTRL,function(e){const t=e.smfMsg,n=t.getResponse(),s=n.responseCode,r={responseCode:s};if(i._responseCode=s,200===s)if(i.checkNoLocal(t)){if(i.checkCompressedSsl(t))return i.updateReadonlySessionProps(t),this.transitionTo(i.WaitForTransportChange);Object.assign(r,{eventText:"Compressed TLS is not supported by the Solace Message Router",errorSubcode:_.COMPRESSED_TLS_NOT_SUPPORTED})}else Object.assign(r,{eventText:"No Local is not supported by the Solace Message Router",errorSubcode:_.NO_LOCAL_NOT_SUPPORTED});else{const e=d.getErrorSubcode(s,n.responseString),t=e===_.UNKNOWN_ERROR?_.LOGIN_FAILURE:e;h(`Login failed. Subcode: ${t} respCode: ${s} respString: ${n.responseString}`),Object.assign(r,{eventText:n.responseString,errorSubcode:t})}return i.setCurrentError(r),this.transitionTo(i.DestroyingTransport)}).reaction(y.DOWNGRADE_TIMEOUT,function(){return i._transport.requestDowngrade&&!1!==i._transport.requestDowngrade("ClientCtrl timeout",_.TIMEOUT)?this.transitionTo(i.WaitingForTransportUp):(i.setCurrentError({eventText:"ClientCtrl timeout",errorSubcode:_.TIMEOUT}),this.transitionTo(i.DestroyingTransport))}).exit(()=>{i.clearClientCtrlTimer()}),this.WaitForTransportChange=new T({name:b.WAITING_FOR_TRANSPORT_CHANGE,parentContext:i.SessionConnecting}).initial(function(){const e=i.updateTransportCompression(function(e){this._transport=e,this.processEvent(new P({name:y.TRANSPORT_CHANGE_DONE}))}.bind(i));return null===e?this:(i._transport=e,this.transitionTo(i.ReapplyingSubscriptions))}).reaction(y.TRANSPORT_CHANGE_DONE,function(){return this.transitionTo(i.ReapplyingSubscriptions)}),this.ReapplyingSubscriptions=new T({name:b.REAPPLYING_SUBSCRIPTIONS,parentContext:i.SessionConnecting}).entry(()=>{h("ReapplyingSubscriptions: entry"),i.copySubscriptionCacheKeys()}).initial(function(){return!0===i.reapplySubscriptions()?this.transitionTo(i.WaitForSubConfirm):this.transitionTo(i.WaitForCanAcceptData)}).reaction(y.SUBSCRIBE_TIMEOUT,function(){const e=_.TIMEOUT;return i.setCurrentError({eventText:"Subscription timeout while reapplying",errorSubcode:e}),this.transitionTo(i.DestroyingTransport)}).exit(function(){return i.clearSubscriptionCacheKeys(),this}),this.WaitForSubConfirm=new T({name:b.WAITING_FOR_SUBCONFIRM,parentContext:i.ReapplyingSubscriptions}).reaction(y.TRANSPORT_PROTOCOL_SMP,function(e){const t=e.smfMsg.smfHeader,n=k(e.smfMsg.encodedUtf8Subscription),s=t.pm_respcode,r=t.pm_respstr;if(200!==s){const e=d.getErrorSubcode(s,r);return h(`Waiting for subscription confirmation, got ${s} (${e}) '${r}' on subscription ${n}`),i.setCurrentError({eventText:r,responseCode:s,errorSubcode:e}),this.transitionTo(i.DestroyTransport)}return i._session.canConnectPublisher&&i._defaultPublisher&&i._defaultPublisher.isBindWaiting()?this.transitionTo(i.WaitingForMessagePublisher):this.transitionToExitPoint(i.SessionConnecting,"ConnectedExit")}),this.WaitForCanAcceptData=new T({name:b.WAITING_FOR_CAN_ACCEPT_DATA,parentContext:i.ReapplyingSubscriptions}).reaction(y.TRANSPORT_PROTOCOL_SMP,function(e){const t=e.smfMsg.smfHeader,n=k(e.smfMsg.encodedUtf8Subscription),s=t.pm_respcode,r=t.pm_respstr;if(200!==s){const e=d.getErrorSubcode(s,r);return i.setCurrentError({eventText:r,responseCode:s,errorSubcode:e}),this.transitionTo(i.DestroyingTransport)}return h(`Unexpected 200 OK response to subscription add for ${n}`),this.internalTransition(null)}).reaction(y.TRANSPORT_CAN_ACCEPT_DATA,function(){return!0===i.reapplySubscriptions()?this.transitionTo(i.WaitForSubConfirm):this.internalTransition(null)}),this.WaitingForMessagePublisher=new T({name:b.WAITING_FOR_PUBFLOW,parentContext:i.SessionConnecting}).entry(()=>{i._defaultPublisher.connect(),i.sendPublisherSessionUpEvent(i._defaultPublisher)}).reaction(y.FLOW_UP,function(){return i._defaultPublisher.isBindWaiting()?this.internalTransition(null):this.transitionToExitPoint(i.SessionConnecting,"ConnectedExit")}).reaction(y.FLOW_FAILED,function(e){return i.setCurrentError({eventText:`Guaranteed Message Publisher Failed: ${e.eventText}`,errorSubcode:_.LOGIN_FAILURE}),this.transitionTo(i.DestroyingTransport)}),this.SessionTransportUp=new T({name:b.TRANSPORT_UP,parentContext:i}).entry(function(){return i.clearConnectTimer(),this}).initial(function(){return i._session.canConnectConsumer&&(i._consumers.flows.forEach(e=>i.sendConsumerSessionUpEvent(e)),i._consumers.reconnectingFlows.forEach(e=>i.sendConsumerSessionUpEvent(e))),this.transitionTo(i.FullyConnected)}).reaction(y.DISCONNECT,function(){return this.transitionTo(i.SessionDisconnecting)}).reaction(y.EXCEPTION,function(e){return i.setCurrentError(e),i.cleanupSession(),this.transitionToEntryPoint(i.SessionConnecting,"ReconnectTransport")}).reaction(y.SEND_ERROR,function(e){return i.setCurrentError(e),i.cleanupSession(),this.transitionToEntryPoint(i.SessionConnecting,"ReconnectTransport")}).reaction(y.TRANSPORT_DESTROYED,function(e){return i.setCurrentError(e),h("Received unsolicited TRANSPORT_DESTROYED event while transport is up"),i.cleanupSession(),this.transitionToEntryPoint(i.SessionConnecting,"ReconnectTransport")}).reaction(y.TRANSPORT_PROTOCOL_SMP,function(e){const t=e.smfMsg.smfHeader,n=k(e.smfMsg.encodedUtf8Subscription),s=t.pm_respcode,r=t.pm_respstr;return i.handleSubscriptionUpdateError(s,r,n,void 0,!1),this.internalTransition(null)}).reaction(y.TRANSPORT_CAN_ACCEPT_DATA,function(e){const t=O.build(N.CAN_ACCEPT_DATA,"",null,0,null,e.toString());return i.emitSessionEvent(t),i._userBackpressured=!1,this.internalTransition(null)}).reaction(y.CREATE_SUBSCRIBER,function(e){const t=i._consumers.add(e.guaranteedFlowObject);return i.sendConsumerSessionUpEvent(t),this}).exit(function(){return i.clearKeepAlive(),this}),this.FullyConnected=new T({name:b.FULLY_CONNECTED,parentContext:i.SessionTransportUp}).entry(()=>{i._connectFailEvent=N.DOWN_ERROR,i.scheduleKeepAlive()}),this.SessionDisconnected=new T({name:b.DISCONNECTED,parentContext:i}).reaction(y.DISCONNECT,function(){return i.setPostEventAction(()=>{i.emitSessionEvent(O.build(N.DISCONNECTED))}),this.internalTransition(null)}).reaction(y.CONNECT,function(){return this.transitionTo(i.SessionConnecting)}).reaction(y.EXCEPTION,function(){return this.internalTransition(null)}),this.SessionDisconnecting=new T({name:b.DISCONNECTING,parentContext:i}).initial(()=>(h(`Disconnecting session ${i}`),this.transitionTo(i.DisconnectingFlows))).reaction(y.DISCONNECT,function(){return this.internalTransition(null)}).reaction(y.EXCEPTION,function(e){return i.setCurrentError({errEvent:e}),i.cleanupSession(),this.transitionToEntryPoint(i.SessionConnecting,"DisconnectTransport")}).reaction(y.TRANSPORT_DESTROYED,function(){return h("Received unsolicited TRANSPORT_DESTROYED while disconnecting transport"),i.cleanupSession(),this.transitionToEntryPoint(i.SessionConnecting,"DisconnectTransport")}),this.DisconnectingFlows=new T({name:b.DISCONNECTING_FLOWS,parentContext:i.SessionDisconnecting},{gatherPendingFlows(){const{MessageConsumerEventName:e}=s;c(!this.isGathering),this.isGathering=!0;const t=(e,t,n)=>{if(c(e,"Trying to listen to undefined flow"),this.known.has(e))return;this.known.add(e),this.pending.add(e);const s=()=>{n.forEach(t=>e._removeListener(t,s)),this.pending.delete(e),this.isGathering||this.checkPendingFlows()};n.forEach(n=>t.call(e,n,s));try{e._disconnectSession()}catch(e){s()}};i._consumers&&i._consumers.flows.forEach(n=>{t(n,n._once,[e.DOWN,e.DOWN_ERROR])}),this.isGathering=!1},checkPendingFlows(){this.pending,0===this.pending.size&&(this.gatherPendingFlows(),0===this.pending.size&&this.proceed())},proceed(){this.known=null,this.pending=null,h("All flows disconnected"),i.processEvent(new g({name:y.FLOWS_DISCONNECTED}))}}).entry(function(){this.known=new Set,this.pending=new Set,this.checkPendingFlows()}).reaction(y.FLOWS_DISCONNECTED,function(){return this.transitionTo(i.FlushingTransport)}),this.FlushingTransport=new T({name:b.FLUSHING_TRANSPORT,parentContext:i.SessionDisconnecting},{flushTransport(){i.cleanupSession(),i.flushTransportSession(()=>this.onTransportFlushed()),this.sessionId=null},onTransportFlushed(){i.processEvent(new g({name:y.TRANSPORT_FLUSHED}))}}).entry(function(){h("Flushing transport"),this.flushTransport()}).reaction(y.TRANSPORT_FLUSHED,function(){return h("Handle Transport Flushed"),this.transitionToEntryPoint(i.SessionConnecting,"DisconnectTransport")})}addToSubscriptionCache(e){if(l.nothing(e)||!this._subscriptionCache)return;const{LOG_DEBUG:t}=this.logger,n=e.name;null===this._subscriptionCache[n]||void 0===this._subscriptionCache[n]?(this._subscriptionCache[n]=e,this._subscriptionCacheCount++):this._subscriptionCache[n]=e}cancelOutstandingCorrelatedReq(e){if(l.nothing(e)||!this._correlatedReqs)return null;const t=this._correlatedReqs[e];if(null==t)return null;const{LOG_DEBUG:n,LOG_ERROR:s}=this.logger;t.timer&&(clearTimeout(t.timer),t.timer=null);try{delete this._correlatedReqs[e]||s(`Cannot delete ctrl request ${e}`)}catch(t){s(`Cannot delete ctrl request ${e}`,t)}return t}cleanupSession(){const{LOG_INFO:e}=this.logger;e("Clean up session");const{ConsumerFSMEvent:t,ConsumerFSMEventNames:n}=s;this._correlatedReqs&&Object.keys(this._correlatedReqs).forEach(e=>this.cancelOutstandingCorrelatedReq(e)),this.clearConnectTimer(),this.clearClientCtrlTimer(),this.clearKeepAlive(),this._consumers.flows.forEach(e=>{e.processFSMEvent(new t({name:n.SESSION_DOWN}))}),this._consumers.reconnectingFlows.forEach(e=>{e.processFSMEvent(new t({name:n.SESSION_DOWN}))}),this._defaultPublisher&&this._defaultPublisher.processFSMEvent(new r.PublisherFSMEvent({name:r.PublisherFSMEventNames.SESSION_DOWN})),this._session.cleanupSession()}clearClientCtrlTimer(){this._clientCtrlTimer&&(clearTimeout(this._clientCtrlTimer),this._clientCtrlTimer=null)}clearConnectTimer(){this._connectTimer&&(clearTimeout(this._connectTimer),this._connectTimer=void 0)}clearKeepAlive(){const{LOG_INFO:e}=this.logger;this._keepAliveTimer&&(e("Cancel keepalive timer"),clearInterval(this._keepAliveTimer),this._keepAliveTimer=null),this.resetKeepAliveCounter()}checkNoLocal(e){let t=!0;if(!0===this._sessionProperties.noLocal){const n=e.getRouterCapabilities();t=!!n&&"boolean"==typeof n[u.NO_LOCAL]&&n[u.NO_LOCAL]}return t}checkCompressedSsl(e){const{LOG_TRACE:t}=this.logger;if(this._compressedTLS){const t=e.getRouterCapabilities();return!(!t||"boolean"!=typeof t[u.COMPRESSED_SSL])&&!0===t[u.COMPRESSED_SSL]}return!0}checkSessionDestinationCapability(e){let t=null;return e&&e.getType()&&e.getSubscriptionInfo()&&(e.getSubscriptionInfo().isShare||e.getSubscriptionInfo().isNoExport)&&!this._session.isCapable(u.SHARED_SUBSCRIPTIONS)&&(t=new E("Shared subscriptions are not allowed by router for this client",_.SHARED_SUBSCRIPTIONS_NOT_SUPPORTED,null)),t}clearCurrentError(){this._currentError=null}clearSubscriptionCacheKeys(){this._subscriptionCacheKeys=null}copySubscriptionCacheKeys(){this.clearSubscriptionCacheKeys(),this._subscriptionCacheKeys=Object.keys(this._subscriptionCache||{});const e=A.getP2PTopicSubscription(this._sessionProperties.p2pInboxBase);this._subscriptionCacheKeys.push(e)}createMessagePublisher(){const{LOG_DEBUG:e}=this.logger;if(!this._sessionProperties.publisherProperties.enabled)return;const{MessagePublisher:t,MessagePublisherEventName:n}=r,s=new t({properties:this._sessionProperties.publisherProperties,sessionInterfaceFactory:this._flowInterfaceFactory});s.on(n.UP,()=>this.processEvent(new P({name:y.FLOW_UP},{guaranteedFlowObject:s}))),s.on(n.CONNECT_FAILED_ERROR,e=>this.processEvent(new P({name:y.FLOW_FAILED},{guaranteedFlowObject:s,event:e,eventText:e.description}))),s.on(n.REJECTED_MESSAGE,(e,t)=>{const n=t.smfHeader,s=n.pm_respcode,r=n.pm_respstr,i=d.getADErrorSubcode(s,r),o=O.build(N.REJECTED_MESSAGE_ERROR,r,s,i,e.getCorrelationKey());o.message=e,this.emitSessionEvent(o)}),s.on(n.ACKNOWLEDGED_MESSAGE,e=>{const t=O.build(N.ACKNOWLEDGED_MESSAGE,"Message(s) acknowledged",void 0,0,e.getCorrelationKey());t.message=e,this.emitSessionEvent(t)}),s.on(n.FLOW_NAME_CHANGED,e=>{const{messages:t,count:n}=e;if(n>0){const e=O.build(N.REPUBLISHING_UNACKED_MESSAGES,`Republishing ${n} messages due to Guaranteed Message Publisher failed to reconnect`);e.messages=t,e.count=n,this.emitSessionEvent(e)}}),s.on(n.CAN_SEND,()=>{this.emitSessionEvent(O.build(N.CAN_ACCEPT_DATA,`${s} window is now open and can send`))}),s.on(n.GUARANTEED_MESSAGING_DOWN,()=>{this.emitSessionEvent(O.build(N.GUARANTEED_MESSAGE_PUBLISHER_DOWN,"Guaranteed Message Publishing shut down"))}),this._defaultPublisher=s}sendConsumerSessionUpEvent(e){const{ConsumerFSMEvent:t,ConsumerFSMEventNames:n}=s,r=new t({name:this._session.canConnectConsumer?n.SESSION_UP:n.SESSION_UP_NO_AD});r.guaranteedFlowObject=e,e.processFSMEvent(r)}sendPublisherSessionUpEvent(e){const t=this._session.canConnectPublisher,n=new r.PublisherFSMEvent({name:t?r.PublisherFSMEventNames.SESSION_UP:r.PublisherFSMEventNames.SESSION_UP_NO_AD});n.guaranteedFlowObject=e,e.processFSMEvent(n)}createMessageConsumer(e){const{MessageConsumer:t}=s,n=new t({properties:e,sessionInterfaceFactory:this._flowInterfaceFactory}),r=n.getProperties();if(r.topicEndpointSubscription){const e=this.checkSessionDestinationCapability(r.topicEndpointSubscription);if(e)throw e}const{LOG_WARN:i}=this.logger,o=r.requiredSettlementOutcomes;if(o&&o.length>0&&o.some(e=>e===R.FAILED||R.REJECTED)&&!this._session.isCapable(u.AD_APP_ACK_FAILED)){const e=`Session.capabilitySettlementOutcomeNotSupported: [ ${o.map(e=>`solace.MessageOutcome.${R.nameOf(e)}`).join(", ")} ]`;throw i(e),new E(e,_.INVALID_OPERATION,null)}const a={guaranteedFlowObject:n};return this.processEvent(new P({name:y.CREATE_SUBSCRIBER},a)),n}createQueueBrowser(e){const{MessageConsumerAcknowledgeMode:t,QueueBrowser:n}=s,{LOG_DEBUG:r}=this.logger,i={};return i.queueDescriptor=e.queueDescriptor,i.acknowledgeMode=t.CLIENT,i.browser=!0,Object.prototype.hasOwnProperty.call(e,"connectTimeoutInMsecs")&&(i.connectTimeoutInMsecs=e.connectTimeoutInMsecs),Object.prototype.hasOwnProperty.call(e,"connectAttempts")&&(i.connectAttempts=e.connectAttempts),Object.prototype.hasOwnProperty.call(e,"windowSize")&&(i.windowSize=e.windowSize),Object.prototype.hasOwnProperty.call(e,"transportAcknowledgeTimeoutInMsecs")&&(i.transportAcknowledgeTimeoutInMsecs=e.transportAcknowledgeTimeoutInMsecs),Object.prototype.hasOwnProperty.call(e,"transportAcknowledgeThresholdPercentage")&&(i.transportAcknowledgeThresholdPercentage=e.transportAcknowledgeThresholdPercentage),new n(this.createMessageConsumer(i))}destroyTransportSession(e,t){if(l.nothing(this._transport))return void this.processEvent(new P({name:y.TRANSPORT_DESTROYED}));const{LOG_INFO:n,LOG_ERROR:s}=this.logger;n("Destroy transport session");const r=this._transport.destroy(e,t);this._smfClient=null,r!==a.TransportReturnCode.OK&&s(`Failed to destroy transport session, return code: ${a.TransportReturnCode.describe(r)}`)}disposeInternal(){if(this._disposed)return;const e={transport:()=>{this.destroyTransportSession("Disposing",0),this._transport=null,this._smfClient=null},session:()=>{this.cleanupSession(),this._session=null,this._sessionProperties=null,this._correlatedReqs=null,this._flowInterfaceFactory=null},statistics:()=>{this._sessionStatistics&&(this._sessionStatistics.resetStats(),this._sessionStatistics=null),this._kaStats=null},"subscription cache":()=>{this._subscriptionCache&&(Object.keys(this._subscriptionCache).forEach(e=>this.removeFromSubscriptionCache(e)),this._subscriptionCache=null),this.clearSubscriptionCacheKeys(),this._subscriptionCacheCount=0},MessagePublishers:()=>{this._defaultPublisher&&(this._defaultPublisher.dispose(),this._defaultPublisher=null)},MessageConsumers:()=>{this._consumers.disposeAll(),this._consumers=null},"host list":()=>{this._currentHost=null,this._hosts=null}};Object.keys(e).forEach(t=>{const{LOG_TRACE:n,LOG_INFO:s}=this.logger,r=e[t];try{r()}catch(e){s(`Dispose: ${t} failed:`,e,"...continuing")}}),this._disposed=!0}emitSessionEvent(e){this._session.sendEvent(e)}enqueueOutstandingCorrelatedReq(e,t,n,s,r){if(l.nothing(e))return;const{LOG_INFO:i}=this.logger;i(`Enqueue outstanding ctrl request correlationTag=${e}`);let o=null;t&&(o=setTimeout(t,n||this._sessionProperties.readTimeoutInMsecs));const a=new h(e,o,s,r);this._correlatedReqs[e]=a}errorInFsm(e,t,n=null){const{LOG_INFO:s}=this.logger,r=new P({name:y.EXCEPTION});return s(`Handling error in FSM: ${e} ${n&&n.stack}`),this.setCurrentError({eventText:e,errorSubcode:t,eventReason:n}),this.processEvent(r)}flushTransportSession(e){this._transport?this._transport.flush(e):e()}getCorrelationTag(){return this._smfClient.nextCorrelationTag()}getCurrentStateName(){const e=this.getCurrentState();return e?e===this.getFinalState()?b.DISPOSED:this.getCurrentState().getName():null}getStat(e){if(void 0!==this._sessionStatistics)return e===v.TX_TOTAL_DATA_MSGS?this._sessionStatistics.getStat(v.TX_DIRECT_MSGS)+this._sessionStatistics.getStat(v.TX_PERSISTENT_MSGS)+this._sessionStatistics.getStat(v.TX_NONPERSISTENT_MSGS):e===v.TX_TOTAL_DATA_BYTES?this._sessionStatistics.getStat(v.TX_DIRECT_BYTES)+this._sessionStatistics.getStat(v.TX_PERSISTENT_BYTES)+this._sessionStatistics.getStat(v.TX_NONPERSISTENT_BYTES):this._sessionStatistics.getStat(e)}getTransportInfo(){return l.nothing(this._transport)?"Not connected.":this._transport.getInfoStr()}handleADCtrlMessage(e,t){const n=e.getFlowId(),s=t.pm_respstr,r=t.pm_corrtag,{LOG_INFO:o,LOG_DEBUG:c,LOG_WARN:u}=this.logger;if(r){this.updateRxStats(e),o(`Handle SMF response for correlationTag ${r}`);const t=this.cancelOutstandingCorrelatedReq(r);return l.nothing(t)?this.errorInFsm(`Cannot find matching request for response: ${s}`,_.INTERNAL_ERROR):t.respRecvdCallback?(t.respRecvdCallback(e,t),this):(this.incStat(v.RX_REPLY_MSG_DISCARD),this)}let h;const p=e.msgType,{SMFAdProtocolMessageType:d}=i;switch(p){case d.CLIENTACK:case d.CLIENTNACK:case d.CLOSEPUBFLOW:this._defaultPublisher.flowId===n&&(h=this._defaultPublisher);break;default:h=this._consumers.getFlowById(n)}if(h&&!h.disposed)return this.updateRxStats(e,h),h.handleUncorrelatedControlMessage(e),this;const E=e.getResponse(),g=E?`"${E.responseCode} ${E.responseString}" `:"";if(u(`Dropping ADCTRL.${i.SMFAdProtocolMessageType.describe(e.msgType)} ${g}for unknown flow ${n}`),this.incStat(v.RX_DISCARD_NO_MATCHING_CONSUMER),p===d.FLOWCHANGEUPDATE){const t=i.AdProtocolMessage.getFlowChangeUpdateResponse(this._flowId,e.getActiveFlow(),"Unknown Flow Id");this.sendControl(t),a.TransportReturnCode.OK}return this}handleADTrMessage(e,t){const{LOG_DEBUG:n}=this.logger,s=t.pm_ad_flowid,r=this._consumers.getFlowById(s);return!r||r.disposed?(this.updateRxStats(e,this._sessionStatistics),this.incStat(v.RX_DISCARD_NO_MATCHING_CONSUMER),null):(this.updateRxStats(e,r),r.handleDataMessage(e),r)}handleApiSubscriptionTimeout(e,t){if(void 0===this._correlatedReqs[e]||null===this._correlatedReqs[e])return;const{LOG_INFO:n,LOG_ERROR:s}=this.logger;n(`${t||"Subscription timeout"} for correlationTag=${e}`);try{delete this._correlatedReqs[e]||s(`Cannot delete ctrl request ${e}`)}catch(t){s(`Cannot delete ctrl request ${e}, exception: ${t.message}`)}}handleClientCtrlMessage(e,t){let n;const{LOG_INFO:s}=this.logger;this.updateRxStats(e),e.msgType===i.SMFClientCtrlMessageType.LOGIN?(n=a.SMFClient.SMF_CLIENTCTRL_LOGIN_FAKE_CORRELATIONTAG,s("Handle SMF response for ClientCTRL Login")):(n=t.pm_corrtag,s(`Handle SMF response for correlationTag ${n}`));const r=this.cancelOutstandingCorrelatedReq(n);if(l.nothing(r)){const e=t.pm_respstr;return this.errorInFsm(`Cannot find matching request for response: ${e}`,_.INTERNAL_ERROR)}return r.respRecvdCallback?r.respRecvdCallback(e):(s(`Dropping ClientCtrl message due to mismatched correlation tag ${n}`),this.incStat(v.RX_REPLY_MSG_DISCARD))}handleClientCtrlResponse(e){const t=new P({name:y.TRANSPORT_PROTOCOL_CLIENTCTRL});t.smfMsg=e,this.processEvent(t)}handleClientCtrlTimeout(){const{LOG_INFO:e}=this.logger;e("ClientCtrl timeout for session");const t=new P({name:y.DOWNGRADE_TIMEOUT});this.processEvent(t)}handleConnectTimeout(){const{LOG_INFO:e}=this.logger;e("Connection timeout. Disconnecting");const t=new P({name:y.CONNECT_TIMEOUT});this.processEvent(t)}handleUpdatePropertyTimeout(e,t){const{LOG_ERROR:n}=this.logger;try{delete this._correlatedReqs[e]||n(`Cannot delete ctrl request ${e}`)}catch(t){n(`Cannot delete ctrl request ${e}, exception: ${t.message}`)}const s=O.build(N.PROPERTY_UPDATE_ERROR,t,null,_.TIMEOUT,null,null);this.sendEvent(s)}handleRejectedTrMessage(e){const t=e.pm_respcode,n=e.pm_tr_topicname_bytes,s=n?n.replace(/\0/g,""):"",r=e.pm_respstr,i=d.getErrorSubcode(t,r);this.emitSessionEvent(O.build(N.REJECTED_MESSAGE_ERROR,r,t,i,null,`Topic: ${s}`))}handleSMFMessage(e){try{const t=e.smfHeader;if(t.discardMessage)return this._sessionStatistics&&this._sessionStatistics.incStat(v.RX_DISCARD_SMF_UNKNOWN_ELEMENT),null;switch(t.smf_protocol){case i.SMFProtocol.TRMSG:return t.smf_adf?this.handleADTrMessage(e,t):(this.updateRxStats(e,this._sessionStatistics),0===t.pm_respcode?this._session.handleDataMessage(e):this.handleRejectedTrMessage(t));case i.SMFProtocol.ADCTRL:return this.handleADCtrlMessage(e,t);case i.SMFProtocol.CLIENTCTRL:return this.handleClientCtrlMessage(e,t);case i.SMFProtocol.SMP:return this.handleSMPMessage(e,t);case i.SMFProtocol.KEEPALIVE:case i.SMFProtocol.KEEPALIVEV2:return null;default:return this.handleUnknownProtocolMessage(e,t)}}catch(e){const{LOG_ERROR:t}=this.logger;return t(`Exception in handleSMFMessage, exception: ${e.stack}`),this.errorInFsm(`Exception in handleSMFMessage: ${e.message}`,e.subcode||_.INTERNAL_ERROR,e)}}handleSMFParseError(e){return this.errorInFsm(e,_.PROTOCOL_ERROR)}handleSMPMessage(e,t){this.updateRxStats(e);const n=this.cancelOutstandingCorrelatedReq(t.pm_corrtag||"");if(l.nothing(n)||l.nothing(n.respRecvdCallback)){const t=new P({name:y.TRANSPORT_PROTOCOL_SMP});return t.smfMsg=e,this.processEvent(t)}return n.respRecvdCallback(e,n)}handleSubscriptionUpdateError(e,t,n,s,r){const i=d.getErrorSubcode(e,t);i!==_.SUBSCRIPTION_ALREADY_PRESENT&&i!==_.SUBSCRIPTION_NOT_FOUND&&this.removeFromSubscriptionCache(n),this._session.handleSubscriptionUpdateError(e,t,n,s,r)}handleSubscriptionTimeout(e){const{LOG_ERROR:t}=this.logger;try{let n=!1;this._correlatedReqs&&(n=delete this._correlatedReqs[e]),n||t(`Cannot delete ctrl request ${e}`)}catch(n){t(`Cannot delete ctrl request ${e}`,n)}const n=new P({name:y.SUBSCRIBE_TIMEOUT});this.processEvent(n)}handleTransportEvent(e){const{LOG_INFO:t,LOG_WARN:n}=this.logger,s=e.getInfoStr()||"";let r;switch(t(`Receive transport event: ${e}`),e.getTransportEventCode()){case a.TransportSessionEventCode.UP_NOTICE:r=new P({name:y.TRANSPORT_UP}),r.sessionId=e.getSessionId(),this.processEvent(r);break;case a.TransportSessionEventCode.DESTROYED_NOTICE:r=new P({name:y.TRANSPORT_DESTROYED}),r.sessionId=e.getSessionId(),r.eventText=s,r.errorSubcode=e.getSubcode(),r.eventReason=e,this._smfClient=null,this._transport=null,this.processEvent(r);break;case a.TransportSessionEventCode.CAN_ACCEPT_DATA:this.GuaranteedFlowControlledRelief(),r=new P({name:y.TRANSPORT_CAN_ACCEPT_DATA}),r.sessionId=e.getSessionId(),this.processEvent(r);break;case a.TransportSessionEventCode.SEND_ERROR:r=new P({name:y.SEND_ERROR}),r.sessionId=e.getSessionId(),r.eventText=e.getInfoStr(),r.errorSubcode=e.getSubcode(),r.eventReason=e,this.processEvent(r);break;case a.TransportSessionEventCode.DATA_DECODE_ERROR:case a.TransportSessionEventCode.PARSE_FAILURE:return this.errorInFsm(e.getInfoStr(),e.getSubcode());default:n("Received unknown transport session event",e)}return!0}handleUnknownProtocolMessage(e,t){const{LOG_INFO:n,LOG_ERROR:s}=this.logger;return this.updateRxStats(e),t&&t.smf_protocol===i.SMFProtocol.TSESSION?(s(`Received transport session message instead of SMF message, protocol 0x${G(t.smf_protocol)}`),s(`Transport MessageType=${e.messageType}, target sessionId=${G(e.sessionId)}`),this.errorInFsm("Received message with unknown protocol",_.PARSE_FAILURE)):(this._sessionStatistics&&this._sessionStatistics.incStat(v.RX_DISCARD_SMF_UNKNOWN_ELEMENT),n(`Drop message with unknown protocol 0x${G(t.smf_protocol)}`),null)}incStat(e,t){return this._sessionStatistics?this._sessionStatistics.incStat(e,t):void 0}initTransport(){const{LOG_INFO:e}=this.logger,t=this._currentHost;e(`Creating transport session ${t}`),this._kaStats={lastMsgWritten:0,lastBytesWritten:0},this._smfClient=new a.SMFClient(e=>this.handleSMFMessage(e),e=>this.handleSMFParseError(e),this),this._transport=a.TransportFactory.createTransport(t,e=>this.handleTransportEvent(e),this._smfClient,this._sessionProperties.clone(),()=>this.sessionIdHex),this.injectTransportInterceptor(this._transportInterceptor)}injectTransportInterceptor(e){this._transportInterceptor=e,this._transport&&this._transport.setInterceptor(e)}keepAliveTimeout(){const{LOG_TRACE:e,LOG_DEBUG:t,LOG_INFO:n}=this.logger;if(this._keepAliveCounter>=this._sessionProperties.keepAliveIntervalsLimit)return n(`Exceed maximum keep alive intervals limit ${this._sessionProperties.keepAliveIntervalsLimit}`),this._keepAliveTimer&&clearInterval(this._keepAliveTimer),this.errorInFsm("Exceed maximum keep alive intervals limit",_.KEEP_ALIVE_FAILURE);const s=this._transport.getClientStats(),r=s.msgWritten,o=s.bytesWritten,c=new i.KeepAliveMessage;return this.send(c,null,!0)!==a.TransportReturnCode.OK?this.errorInFsm("Cannot send keep alive message",_.KEEP_ALIVE_FAILURE):(this._kaStats.lastMsgWritten===r&&this._kaStats.lastBytesWritten<o||(this._keepAliveCounter++,this._kaStats.lastMsgWritten,this._kaStats.lastBytesWritten),this._keepAliveCounter,this._kaStats.lastBytesWritten=s.bytesWritten,this._kaStats.lastMsgWritten=s.msgWritten,!0)}prepareAndSendMessage(e){const{LOG_WARN:t,LOG_DEBUG:n}=this.logger;if(e instanceof I){let n;if(this._sessionProperties.payloadCompressionLevel>0&&(l.anything(e._binaryAttachment)&&e._binaryAttachment.length>0||l.anything(e._structuredContainer))){let n,s=0;try{{const t={level:this._sessionProperties.payloadCompressionLevel,flush:Q.Z_FINISH};if(l.anything(e.getSdtContainer())){const r=F.encodeSingleElement(e.getSdtContainer()),i=B(r);s=i.length,n=Q.zlibSync(i,t)}else s=e._binaryAttachment.length,n=Q.zlibSync(e._binaryAttachment,t);n=B(n)}n.length+9<s?(e._setCompressedBinaryAttachment(n),l.nothing(e.getHttpContentEncoding())?e._compressedCE="deflate":e._compressedCE=e.getHttpContentEncoding()+", deflate"):n.length}catch(e){t("Error occurred while compressing, message attachment was not compressed. Original attachment will be sent. ",e)}}const s=e.getDeliveryMode();switch(s){case C.DIRECT:if(!this._transport)return;e._payload_is_memoized=!1,e._memoized_csumm=null,e._memoized_payload=null,n=this.sendToTransport(e);break;case C.PERSISTENT:case C.NON_PERSISTENT:if(!this._defaultPublisher){const e=this._session.adLocallyDisabled?"locally disabled":"remotely unsupported";throw new E("Session does not provide Guaranteed Message Publish capability",_.GM_UNAVAILABLE,e)}this._gmSendDisallowed&&this._gmSendDisallowed(),n=this._defaultPublisher.prepareAdMessageAndSend(e);break;default:{const{LOG_ERROR:e}=this.logger;e("Unhandled message delivery mode",C.describe(s))}}if(l.anything(e._getCompressedBinaryAttachment())&&e._setCompressedBinaryAttachment(),delete e._compressedCE,n!==a.TransportReturnCode.OK){if(n===a.TransportReturnCode.NO_SPACE)throw this._userBackpressured=!0,new E("Cannot send message - no space in transport",_.INSUFFICIENT_SPACE,a.TransportReturnCode.describe(n));this.setCurrentError(new E("Cannot send message",_.INVALID_OPERATION,a.TransportReturnCode.describe(n))),this.processEvent(new P({name:y.EXCEPTION}))}}}GuaranteedFlowControlledRelief(){this._defaultPublisher&&this._defaultPublisher.processFSMEvent(new r.PublisherFSMEvent({name:r.PublisherFSMEventNames.CAN_SEND}))}reapplySubscriptions(){const{LOG_INFO:e,LOG_DEBUG:t}=this.logger,{SolclientFactory:{createTopicDestination:n}}=o;if(e(`Reapplying subscriptions, count=${this._subscriptionCacheKeys.length}`),!this._subscriptionCacheKeys)return!0;try{for(;this._subscriptionCacheKeys.length;){const e=this._subscriptionCacheKeys.shift(),t=0===this._subscriptionCacheKeys.length,s=n(e),r=this.sendSubscribe(s,t,null,this._sessionProperties.readTimeoutInMsecs,null);r!==a.TransportReturnCode.OK&&this.errorInFsm(`Error occurred sending subscription: ${a.TransportReturnCode.describe(r)}`,_.INTERNAL_ERROR)}}catch(e){if(e instanceof E&&e.subcode===_.INSUFFICIENT_SPACE)return!1;this.errorInFsm(`Unexpected expection occurred while reapplying subscriptions: ${e}`,e.subcode||_.INTERNAL_ERROR,e)}return!0}removeFromSubscriptionCache(e){if(l.nothing(e)||!this._subscriptionCache)return null;const{LOG_DEBUG:t,LOG_ERROR:n}=this.logger,s=e instanceof p?e.name:e,r=this._subscriptionCache[s];if(null==r)return null;try{delete this._subscriptionCache[s]?this._subscriptionCacheCount--:n(`Cannot remove subscription ${s}`)}catch(e){n(`Cannot remove subscription ${s}`,e)}return r}reset(){this.resetStats(),this.sessionId=null,this._keepAliveTimer=null,this.resetKeepAliveCounter(),this._correlatedReqs={},this._disposed=!1,this._smfClient=null,this._kaStats={lastMsgWritten:0,lastBytesWritten:0},this._subscriptionCache=null,this._subscriptionCacheKeys=null,this._subscriptionCacheCount=0,this._sessionProperties.reapplySubscriptions&&(this._subscriptionCache={}),this._eventCode=null,this._responseCode=null,this.eventText=null,this.errorSubcode=null,this.eventReason=null}resetKeepAliveCounter(){this._keepAliveCounter=0}resetStats(){return this._sessionStatistics?this._sessionStatistics.resetStats():void 0}scheduleKeepAlive(){const{LOG_DEBUG:e,LOG_ERROR:t}=this.logger,{keepAliveIntervalInMsecs:n}=this._sessionProperties;0!==n&&(this._keepAliveTimer&&clearInterval(this._keepAliveTimer),this._keepAliveTimer=setInterval(()=>{try{this.keepAliveTimeout()}catch(e){t("Error occurred in keepAliveTimeout",e)}},n))}send(e,t=this._sessionStatistics,n=!1){try{return this.sendToTransport(e,t,n)}catch(e){const{LOG_TRACE:t}=this.logger;e.message,e.stack,this.errorInFsm(`Send operation failed: ${e.message}`,e.subcode||_.CONNECTION_ERROR)}return a.TransportReturnCode.CONNECTION_ERROR}sendToTransport(e,t=this._sessionStatistics,n=!1){let s=a.TransportReturnCode.CONNECTION_ERROR;if(!this._transport)throw new E("Transport has been destroyed",_.INTERNAL_ERROR);const r=i.Codec.Encode.encodeCompoundMessage(e);switch(s=this._transport.send(r,n),s){case a.TransportReturnCode.OK:this.updateTxStats(e,t);break;case a.TransportReturnCode.NO_SPACE:if(!n)break;default:throw new E(`Transport returned ${a.TransportReturnCode.describe(s)}`,_.INTERNAL_ERROR)}return s}sendClientCtrlLogin(){const{LOG_INFO:e,LOG_DEBUG:t,LOG_TRACE:n}=this.logger;this._compressedTLS=this._sessionProperties.compressionLevel>0&&null!==this._currentHost.match(/tcps:/i),this._plaintextTLS=null!==this._currentHost.match(/tcps:/i)&&this._sessionProperties.sslConnectionDowngradeTo===M.PLAINTEXT,this._plaintextTLS,this._compressedTLS;const s=i.ClientCtrlMessage.getLogin(this._sessionProperties,this._compressedTLS,this._plaintextTLS),r=this.send(s);if(r!==a.TransportReturnCode.OK)this._responseCode=null,this.eventReason=null,r===a.TransportReturnCode.NO_SPACE?(this.eventText="Cannot send client control - no space in transport",this.errorSubcode=_.INSUFFICIENT_SPACE):(e(`Cannot send client ctrl, return code\n ${a.TransportReturnCode.describe(r)}`),this.eventText="Cannot send client ctrl",this.errorSubcode=_.INVALID_OPERATION);else{const t=a.SMFClient.SMF_CLIENTCTRL_LOGIN_FAKE_CORRELATIONTAG;e(`Using internally correlationTag=${t} for tracking ClientCTRL Login`),this.enqueueOutstandingCorrelatedReq(t,null,null,null,e=>this.handleClientCtrlResponse(e))}return r}sendSubscribe(e,t,n,s,r){const{LOG_INFO:o,LOG_DEBUG:u}=this.logger;c(e instanceof p,"sendSubscribe requires a Destination, not a string");const l=this.getCorrelationTag(),h=i.SMPMessage.getSubscriptionMessage(l,e,!0,t);c(h.encodedUtf8Subscription,"Encoded SMP message was invalid");const d=this.send(h);return d!==a.TransportReturnCode.OK?(o("Subscribe failed",a.TransportReturnCode.describe(d)),d):(t&&this.enqueueOutstandingCorrelatedReq(l,()=>this.handleSubscriptionTimeout(l),s||this._sessionProperties.readTimeoutInMsecs,n,r),d)}sendUpdateProperty(e,t,n,s,r){const o=this._smfClient.nextCorrelationTag(),c=i.ClientCtrlMessage.getUpdate(e,t,o),u=this.send(c);return u!==a.TransportReturnCode.OK||this.enqueueOutstandingCorrelatedReq(o,()=>this.handleUpdatePropertyTimeout(o),s||this._sessionProperties.readTimeoutInMsecs,n,r),u}provisionEndpoint(e,t,n,s){const{LOG_DEBUG:r}=this.logger,o=this._smfClient.nextCorrelationTag(),c=i.AdProtocolMessage.getCreate(e,t,o),u=this.send(c);if(u!==a.TransportReturnCode.OK)return LOG_INFO("Provision failed",a.TransportReturnCode.describe(u)),u;this.enqueueOutstandingCorrelatedReq(o,null,0,n,s)}deprovisionEndpoint(e,t,n){const{LOG_DEBUG:s}=this.logger,r=this._smfClient.nextCorrelationTag(),o=i.AdProtocolMessage.getDelete(e,r),c=this.send(o);if(c!==a.TransportReturnCode.OK)return LOG_INFO("Deprovision failed",a.TransportReturnCode.describe(c)),c;this.enqueueOutstandingCorrelatedReq(r,null,0,t,n)}setClientCtrlTimer(){this.clearClientCtrlTimer(),this._clientCtrlTimer=setTimeout(()=>this.handleClientCtrlTimeout(),this._sessionProperties.transportDowngradeTimeoutInMsecs)}setConnectTimer(){this.clearConnectTimer(),this._connectTimer=setTimeout(()=>this.handleConnectTimeout(),this._sessionProperties.connectTimeoutInMsecs)}setCurrentError(e){const t=this._currentError||{},{LOG_TRACE:n}=this.logger;Object.keys(e).forEach(n=>null!==e[n]&&void 0!==e[n]&&(null!==t[n]&&void 0!==t[n]?(t[n],e[n],!1):(t[n]=e[n],!0))),this._currentError=t}subscriptionUpdate(e,t,n,s,r,o,c){const u=this.checkSessionDestinationCapability(e);if(u)throw u;const l=U[r]||U.default,h=r!==D.REMOVE_DTE_SUBSCRIPTION,p=r===D.ADD_SUBSCRIPTION||r===D.ADD_P2PINBOX,d=this.getCorrelationTag(),_=(h?i.SMPMessage.getSubscriptionMessage:i.AdProtocolMessage.getDTEUnsubscribeMessage)(d,e,p,t),E=this.send(_,void 0,o);return E!==a.TransportReturnCode.OK||(t&&this.enqueueOutstandingCorrelatedReq(d,()=>this.handleApiSubscriptionTimeout(d,l),s||this._sessionProperties.readTimeoutInMsecs,n,c),r===D.ADD_SUBSCRIPTION&&this._sessionProperties.reapplySubscriptions?this.addToSubscriptionCache(e):r===D.REMOVE_SUBSCRIPTION&&this._sessionProperties.reapplySubscriptions&&this.removeFromSubscriptionCache(e)),E}queueSubscriptionUpdate(e,t,n,s,r,o){const c=s?U[D.ADD_SUBSCRIPTION]:U[D.REMOVE_SUBSCRIPTION],u=this.getCorrelationTag(),l=i.SMPMessage.getQueueSubscriptionMessage(u,e,t,s),h=this.send(l,void 0,r);return h!==a.TransportReturnCode.OK||this.enqueueOutstandingCorrelatedReq(u,()=>{const e=this._correlatedReqs[u];this.handleApiSubscriptionTimeout(u,c),o(null,e)},n||this._sessionProperties.readTimeoutInMsecs,null,o),h}updateRxStats(e,t=this._sessionStatistics){if(!t)return;const n=e.smfHeader;if(!n)return;const s=n.pm_deliverymode||0,r=V[s],o=q[s],a=n.messageLength;switch(n.smf_protocol){case i.SMFProtocol.TRMSG:0===n.pm_respcode&&(t.incStat(v.RX_TOTAL_DATA_MSGS),t.incStat(r),t.incStat(v.RX_TOTAL_DATA_BYTES,a),t.incStat(o,a),n.smf_di&&t.incStat(v.RX_DISCARD_MSG_INDICATION));break;case i.SMFProtocol.CLIENTCTRL:case i.SMFProtocol.SMP:case i.SMFProtocol.KEEPALIVE:case i.SMFProtocol.KEEPALIVEV2:case i.SMFProtocol.ADCTRL:t.incStat(v.RX_CONTROL_MSGS),t.incStat(v.RX_CONTROL_BYTES,a)}}updateTxStats(e,t=this._sessionStatistics){if(!t)return;void 0!==e.getReplyTo&&e.getReplyTo()&&t.incStat(v.TX_REQUEST_SENT);const n=e.smfHeader;if(!n)return;const s=n.pm_deliverymode||0;let r=$[s],o=W[s];s!==C.DIRECT&&e.isRedelivered()&&(r=H[s],o=Y[s]);const a=n.messageLength;switch(n.smf_protocol){case i.SMFProtocol.TRMSG:t.incStat(r),t.incStat(o,a);break;case i.SMFProtocol.CLIENTCTRL:case i.SMFProtocol.SMP:case i.SMFProtocol.KEEPALIVE:case i.SMFProtocol.KEEPALIVEV2:case i.SMFProtocol.ADCTRL:t.incStat(v.TX_CONTROL_MSGS),t.incStat(v.TX_CONTROL_BYTES,a)}}updateReadonlySessionProps(e){const t=this._sessionProperties;t._setVpnNameInUse(e.getVpnNameInUseValue()||"");const n=t.virtualRouterName,s=e.getVridInUseValue()||"";t._setVirtualRouterName(s),""!==n&&n!==s&&this.handleVirtualRouterNameChange(n,s),t._setP2pInboxBase(e.getP2PTopicValue()||""),t._setP2pInboxInUse(A.getP2PInboxTopic(t.p2pInboxBase)),this._session.updateCapabilities(e.getRouterCapabilities());const r=this._session._getCapability(u.GUARANTEED_MESSAGE_PUBLISH);this._gmSendDisallowed="boolean"!=typeof r||r?null:()=>{throw new E("Sending guaranteed message is not allowed by router for this client",_.INVALID_OPERATION,null)}}handleVirtualRouterNameChange(e,t){this._consumers&&(this._consumers.flows.forEach(e=>e.onVRNChanged()),this._consumers.reconnectingFlows.forEach(e=>e.onVRNChanged())),this.emitSessionEvent(O.build(N.VIRTUALROUTER_NAME_CHANGED,`Virtual router name is changed from ${e} to ${t}`,null,0,null,null))}get sessionIdHex(){return this.sessionId&&G(this.sessionId)||"N/A"}updateTransportCompression(e){const{LOG_TRACE:t}=this.logger;return this._plaintextTLS,this._compressedTLS,this._plaintextTLS?(a.TransportFactory.severTls(this._transport,this._compressedTLS,e),null):this._compressedTLS?a.TransportFactory.startCompression(this._transport):this._transport}}},56:(e,t,n)=>{var s=n(2195);const r=n(3450),{Flow:i,PrivateFlowEventName:o}=n(8860),{LogFormatter:a}=n(2694),{MessagePublisherEventName:c}=n(3840),{MessagePublisherProperties:u}=n(996),{PublisherFSM:l}=n(2577),{PublisherFSMEvent:h}=n(9728),{PublisherFSMEventNames:p}=n(3865),{LOG_WARN:d}=new a;e.exports.MessagePublisher=class extends i{constructor({properties:e,sessionInterfaceFactory:t}={}){super(new u(e),t,{direct:c.ACKNOWLEDGED_MESSAGE,emits:c.values}),this._fsm=this._makeFSM();const n=new a;n.formatter=function(...e){return["[message-publisher]",...e]},this.log=n.wrap(this.log,this),this._bindWaiting=!0,this.on(o.BIND_WAITING,this._onBindWaiting.bind(this)),this.on(c.CONNECT_FAILED_ERROR,this._onBindFailed.bind(this)),this.on(c.DOWN,this._onDown.bind(this)),this.on(c.UP,this._onUp.bind(this))}_onBindFailed(){this._bindWaiting=!1}_onBindWaiting(){this._bindWaiting=!0}_onDown(){this._bindWaiting=!1}_onUp(){this._bindWaiting=!1}_makeFSM(){return new l({publisher:this,name:"PublisherFSM",sessionInterface:this._sessionInterface,properties:this._properties})}get flowId(){return this._flowId}set flowId(e){this._flowId=e}get name(){return this._flowName}set name(e){this._flowName=e}get publisherId(){return this._publisherId}set publisherId(e){this._publisherId=e}get properties(){return this._properties.clone()}connect(){super.connect(),this._fsm.getCurrentState()||this._fsm.start()}_disconnectSession(){super._disconnectSession(),this.processFSMEvent(new h({name:p.FLOW_CLOSE}))}getDisposedEvent(){return c.DISPOSED}handleAck(e){this.processFSMEvent(new h({name:p.ACK},{ack:e}))}handleNack(e,t){this.processFSMEvent(new h({name:p.ACK},{nack:e,ctrlMessage:t}))}handleUncorrelatedControlMessage(e){const t=e.msgType,{SMFAdProtocolMessageType:n}=r;switch(t){case n.CLIENTACK:{const t=e.getLastMsgIdAcked();e.smfHeader.pm_respcode>299?this.handleNack(t,e):this.handleAck(t);break}case n.CLIENTNACK:{const t=e.getLastMsgIdAcked();this.handleNack(t,e);break}case n.CLOSEPUBFLOW:this.processFSMEvent(new h({name:p.FLOW_UNBOUND}));break;default:d(`Dropping unhandled AD control message for ${this}`,n.describe(t))}}prepareAdMessageAndSend(e){return this._fsm.prepareAdMessageAndSend(e)}isBindWaiting(){return this._bindWaiting}inspect(){return Object.assign(super.inspect(),{name:this.name,publisherId:this.publisherId})}toString(){return s(this)}_disposeFSM(){this.processFSMEvent(new h({name:p.DISPOSE}))}_isDisconnected(){return this._fsm.isDisconnected()}}},73:(e,t,n)=>{const{Enum:s}=n(7444);e.exports.WebTransportState=s.new({DOWN:"WebTransportDown",CONNECTING:"WebTransportConnecting",DOWNGRADING:"WebTransportDowngrading",DESTROYING:"WebTransportDestroying",UP:"WebTransportUp"})},77:e=>{e.exports.UUID={generateUUID:function(){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)})}}},85:(e,t,n)=>{const s={6.4:"10.0",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"Server 2003",5.1:"XP",5.01:"2000 SP1","5.0":"2000","4.0":"4.0"},r="undefined"!=typeof window?window:n.g,i=(r.process,{product:"solclientjs",platform:"unknown",agent:"Gecko"});try{if(r.navigator){const e=e=>e.replace(/[^a-zA-Z0-9_/.]/g,"-");Object.assign(i,{platform:r.navigator.platform,agent:r.navigator.product,description:e(r.navigator.userAgent),navigator:r.navigator});const t=function(){if("undefined"==typeof navigator||!navigator)return null;const e=navigator.userAgent,t={browser:{name:"unknown",version:"0.0.0"},platform:{os:"unknown",arch:"unknown",version:"unknown"}},n=(...t)=>t.some(t=>e.indexOf(t)>=0),r=(...e)=>e.filter(Boolean).shift();Object.assign(t,[["edge",/Edge\/([0-9._]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9.]+)(?:\s|$)/],["opera",/Opera\/([0-9.]+)(?:\s|$)/],["opera",/OPR\/([0-9.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv:([0-9.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9.]+);.*Trident\/[4-8].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([