var F12;!function(e){!function(e){!function(a){"use strict";class t{constructor(e,a,t,i,s){this._ourIdentifier=e;this._nextId=0;this._promiseTable={};this._jsonRpcMethodReceive=a;this._jsonRpcNotificationReceive=t;this._postMessage=i;Date.now||(Date.now=function(){return+new Date});this._startTime=Date.now();s(e=>{this.onMessage(e)})}jsonRpcMethodCall(a,t,i,o,l){i||e.Utility.Assert.failDebugOnly("Trying to insert a promise into the queue without a completed function: The front end will have no way of knowing this promise completed");var n=this._ourIdentifier+"|"+this._nextId;this._nextId++;this._promiseTable[n]={completed:i,error:o};var r=JSON.stringify({id:n,method:a,params:t});if(s.RandomDelay){s.queueData(()=>{this._postMessage(r,l)},r);return!0}return this._postMessage(r,l)}jsonRpcNotification(e,a,t){var i=this._ourIdentifier+"|NULL",o=JSON.stringify({id:i,method:e,params:a});s.RandomDelay?s.queueData(()=>{this._postMessage(o,t)},o):this._postMessage(o,t)}onMessage(a){var t=JSON.parse(a.data),i=t.id.split("|");e.Utility.Assert.areEqual(i.length,2);"NULL"===i[1]?i[0]!==this._ourIdentifier&&this._jsonRpcNotificationReceive(t.method,t.params,t.id):i[0]!==this._ourIdentifier||t.method?s.RandomDelay?s.queueData(()=>{this.handleCall(t)},a.data):this.handleCall(t):s.RandomDelay?s.queueData(()=>{this.handleReply(t)},a.data):this.handleReply(t)}handleReply(a){if(this._promiseTable[a.id]&&this._promiseTable[a.id].completed){if(a.error){e.Utility.Assert.isUndefined(a.data,"Can't have both data and error");this._promiseTable[a.id].error(a.error)}else this._promiseTable[a.id].completed(a.data);delete this._promiseTable[a.id]}else e.Utility.Assert.failDebugOnly("Can't complete a promise that does not exist in the promise table. Probably a dup reply msg.")}handleCall(e){this._jsonRpcMethodReceive(e.method,e.params,(a,t)=>{var i;i=t?JSON.stringify({id:e.id,error:t}):JSON.stringify({id:e.id,data:a});this._postMessage(i)},e.id)}}a.JsonRPCEndpoint=t;class i{constructor(e,a){this.callback=e;this.message=a}}a.RpcDelayData=i;class s{static enableDelay(e,a){s.RandomDelay=!0;s.CalculateDelayTime=e;s.DelayedMessage=a}static disableDelay(){s.RandomDelay=!1;if(s.RandomDelayTimeout){clearTimeout(s.RandomDelayTimeout);s.RandomDelayTimeout=null;s.clearQueue()}}static queueData(e,a){var t=new i(e,a);s.DelayedQueue.push(t);if(!s.RandomDelayTimeout){var o=s.CalculateDelayTime(a);s.RandomDelayTimeout=setTimeout(s.fireRandomly,o)}}static fireRandomly(){var e=s.DelayedQueue.shift();s.DelayedMessage(e.message);e.callback();if(s.DelayedQueue.length>0){var a=s.CalculateDelayTime(s.DelayedQueue[0].message);s.RandomDelayTimeout=setTimeout(s.fireRandomly,a)}else s.RandomDelayTimeout=null}static clearQueue(){for(var e=0;e<s.DelayedQueue.length;e++){var a=s.DelayedQueue[e];s.DelayedMessage(a.message);a.callback()}s.DelayedQueue=[]}}s.RandomDelay=!1;s.DelayedQueue=[];a.RpcDelayHook=s}(e.RPC||(e.RPC={}))}(e.Tools||(e.Tools={}))}(F12||(F12={}));
