"use strict";(this.webpackChunk_msteams_react_web_client=this.webpackChunk_msteams_react_web_client||[]).push([[310925],{468975:(e,s,t)=>{var a;t.r(s),t.d(s,{PIEMessageType:()=>a,PIEStatsProvider:()=>r}),function(e){e.Sync="Sync",e.Async="Async",e.Event="Event"}(a||(a={}));var i=t(477088),n=t(488459);class r{constructor(e,s,t){this._syncRoundTripTimeThresholdMs=16,this._asyncRoundTripTimeThresholdMs=500,(0,n.N_)(),this._hostCommunicationService=e,this._stats={syncMethodsTotal:0,asyncMethodsTotal:0,eventsTotal:0,syncOutliersTotal:0,asyncOutliersTotal:0},s&&(this._syncRoundTripTimeThresholdMs=s),t&&(this._asyncRoundTripTimeThresholdMs=t),this._pendingMatches=new Map,this._outlierCallbacks=[],this._loggerEnabled=!1,this.registerCallback(),this.startEtwModule()}getStats(){return this._stats}addOutlierCallback(e){this._outlierCallbacks.push(e)}setLogger(e){this._logger=e}getLogger(){return this._logger}enableLogger(){this._loggerEnabled=!0}disableLogger(){this._loggerEnabled=!1}async startEtwModule(){this._etwModule=await this._hostCommunicationService.loadModule("etw")}registerCallback(){i.HostBridge.registerForHostMessageNotification((e=>this.onMessage(e)))}onMessage(e){const s=Date.now(),t=this.buildPIEMessage(e,s);t&&(this.updateTotals(t),this.calculateRoundTripTime(t),this._loggerEnabled&&this._logger?.log(t))}buildPIEMessage(e,s){if(!e.messageName)return null;if(e.messageName.startsWith("vdiwv2.")&&!(e=this.extractVdiWv2Message(e)).messageName)return null;const[t,i]=e.messageName.split(".");let n;if(e.isEvent)n=a.Event;else if(e.isAsync)n=a.Async;else{if(!e.syncId)return null;n=a.Sync}return{messageName:i,messageId:e.messageId,namespace:t,timestamp:s,type:n,envelope:e.envelope}}extractVdiWv2Message(e){let s;try{if(s=JSON.parse(e.envelope.message.message),!s.messageName)return e}catch(s){return e}const t=e;return t.messageName=s.messageName,t.syncId=s.syncId,t}updateTotals(e){e.type===a.Sync?this._stats.syncMethodsTotal++:e.type===a.Async?this._stats.asyncMethodsTotal++:this._stats.eventsTotal++}calculateRoundTripTime(e){if(e.type===a.Event||!e.messageId)return;const s=this._pendingMatches.get(e.messageId);s?(this.onMatch(e.timestamp,s),this._pendingMatches.delete(e.messageId)):this._pendingMatches.set(e.messageId,e)}onMatch(e,s){const t=e-s.timestamp;let i;if(i=s.type===a.Async?this._asyncRoundTripTimeThresholdMs:this._syncRoundTripTimeThresholdMs,t>=i&&"writePieMessageEvent"!==s.messageName&&"writeEtwEvent"!==s.messageName){this._etwModule?.writePieMessageEvent?.({messageName:s.messageName,messageSize:null==s.envelope.message?0:JSON.stringify(s.envelope.message).length,roundTripMs:Math.trunc(s.roundTripTime??0)}),s.roundTripTime=t,s.type===a.Async?this._stats.asyncOutliersTotal++:this._stats.syncOutliersTotal++;for(const e of this._outlierCallbacks)e(s)}}}}}]);
//# sourceMappingURL=https://local.teams.office.com/sourcemaps/hashed-assets/pie-stats-provider-cbc112a7c464a574.js.map