@cloudflare/realtimekit-recording-sdk 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +49 -57
- package/dist/index.cjs.js +3 -3
- package/dist/index.es.js +721 -714
- package/dist/index.iife.js +3 -3
- package/package.json +81 -1
- package/types/controllers/RealtimeKitController.d.ts +1 -1
- package/types/controllers/RecordingController.d.ts +3 -3
- package/types/controllers/WebsocketController.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/sdk.d.ts +1 -1
- package/types/utils/logger.d.ts +2 -2
- package/types/utils/mock.d.ts +1 -1
- package/types/controllers/DyteController.d.ts +0 -26
package/dist/index.iife.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var si=Object.defineProperty;var oi=(I,k,E)=>k in I?si(I,k,{enumerable:!0,configurable:!0,writable:!0,value:E}):I[k]=E;var Zt=(I,k,E)=>(oi(I,typeof k!="symbol"?k+"":k,E),E),et=(I,k,E)=>{if(!k.has(I))throw TypeError("Cannot "+E)};var l=(I,k,E)=>(et(I,k,"read from private field"),E?E.call(I):k.get(I)),x=(I,k,E)=>{if(k.has(I))throw TypeError("Cannot add the same private member more than once");k instanceof WeakSet?k.add(I):k.set(I,E)},D=(I,k,E,le)=>(et(I,k,"write to private field"),le?le.call(I,E):k.set(I,E),E);var Yt=(I,k,E)=>(et(I,k,"access private method"),E);var RecordingSDK=function(I){var ne,z,ye,ue,Ve,qt,Q,ie,ve,H,S,K,$,fe;"use strict";var k={exports:{}},E=typeof Reflect=="object"?Reflect:null,le=E&&typeof E.apply=="function"?E.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)},ke;E&&typeof E.ownKeys=="function"?ke=E.ownKeys:Object.getOwnPropertySymbols?ke=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ke=function(e){return Object.getOwnPropertyNames(e)};function zt(n){console&&console.warn&&console.warn(n)}var tt=Number.isNaN||function(e){return e!==e};function w(){w.init.call(this)}k.exports=w,k.exports.once=tn,w.EventEmitter=w,w.prototype._events=void 0,w.prototype._eventsCount=0,w.prototype._maxListeners=void 0;var nt=10;function Ne(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(w,"defaultMaxListeners",{enumerable:!0,get:function(){return nt},set:function(n){if(typeof n!="number"||n<0||tt(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");nt=n}}),w.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},w.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||tt(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function it(n){return n._maxListeners===void 0?w.defaultMaxListeners:n._maxListeners}w.prototype.getMaxListeners=function(){return it(this)},w.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var r=e==="error",s=this._events;if(s!==void 0)r=r&&s.error===void 0;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var f=s[e];if(f===void 0)return!1;if(typeof f=="function")le(f,this,t);else for(var h=f.length,d=ct(f,h),i=0;i<h;++i)le(d[i],this,t);return!0};function rt(n,e,t,i){var r,s,o;if(Ne(t),s=n._events,s===void 0?(s=n._events=Object.create(null),n._eventsCount=0):(s.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),s=n._events),o=s[e]),o===void 0)o=s[e]=t,++n._eventsCount;else if(typeof o=="function"?o=s[e]=i?[t,o]:[o,t]:i?o.unshift(t):o.push(t),r=it(n),r>0&&o.length>r&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=o.length,zt(a)}return n}w.prototype.addListener=function(e,t){return rt(this,e,t,!1)},w.prototype.on=w.prototype.addListener,w.prototype.prependListener=function(e,t){return rt(this,e,t,!0)};function Qt(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function st(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},r=Qt.bind(i);return r.listener=t,i.wrapFn=r,r}w.prototype.once=function(e,t){return Ne(t),this.on(e,st(this,e,t)),this},w.prototype.prependOnceListener=function(e,t){return Ne(t),this.prependListener(e,st(this,e,t)),this},w.prototype.removeListener=function(e,t){var i,r,s,o,a;if(Ne(t),r=this._events,r===void 0)return this;if(i=r[e],i===void 0)return this;if(i===t||i.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if(typeof i!="function"){for(s=-1,o=i.length-1;o>=0;o--)if(i[o]===t||i[o].listener===t){a=i[o].listener,s=o;break}if(s<0)return this;s===0?i.shift():Ht(i,s),i.length===1&&(r[e]=i[0]),r.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this},w.prototype.off=w.prototype.removeListener,w.prototype.removeAllListeners=function(e){var t,i,r;if(i=this._events,i===void 0)return this;if(i.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):i[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete i[e]),this;if(arguments.length===0){var s=Object.keys(i),o;for(r=0;r<s.length;++r)o=s[r],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=i[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function ot(n,e,t){var i=n._events;if(i===void 0)return[];var r=i[e];return r===void 0?[]:typeof r=="function"?t?[r.listener||r]:[r]:t?en(r):ct(r,r.length)}w.prototype.listeners=function(e){return ot(this,e,!0)},w.prototype.rawListeners=function(e){return ot(this,e,!1)},w.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):at.call(n,e)},w.prototype.listenerCount=at;function at(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}w.prototype.eventNames=function(){return this._eventsCount>0?ke(this._events):[]};function ct(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function Ht(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function en(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function tn(n,e){return new Promise(function(t,i){function r(o){n.removeListener(e,s),i(o)}function s(){typeof n.removeListener=="function"&&n.removeListener("error",r),t([].slice.call(arguments))}ut(n,e,s,{once:!0}),e!=="error"&&nn(n,r,{once:!0})})}function nn(n,e,t){typeof n.on=="function"&&ut(n,"error",e,t)}function ut(n,e,t,i){if(typeof n.on=="function")i.once?n.once(e,t):n.on(e,t);else if(typeof n.addEventListener=="function")n.addEventListener(e,function r(s){i.once&&n.removeEventListener(e,r),t(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}var rn=k.exports;class sn{constructor(){Zt(this,"client")}logToConsole(){return window.devMode===!0&&!this.isInitialized()}init(e){this.client=e}isInitialized(){return this.client!==void 0}generateMessage(e){return`RealtimeKitRecordingLogger::${e}`}info(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.info(this.generateMessage(e),t,i)),this.logToConsole()&&console.log(e)}error(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.error(this.generateMessage(e),t,i)),this.logToConsole()&&console.error(e)}debug(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.debug(this.generateMessage(e),t,i)),this.logToConsole()&&console.debug(e)}log(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.log(this.generateMessage(e),t,i)),this.logToConsole()&&console.log(e)}warn(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.warn(this.generateMessage(e),t,i)),this.logToConsole()&&console.warn(e)}}const y=new sn,ft=1e3,on=60*ft,an=1*ft;class cn extends rn.EventEmitter{constructor(t,i){super();x(this,Ve);x(this,ne,null);x(this,z,!1);x(this,ye,!1);x(this,ue,null);this.meeting=t,this.options=i,Yt(this,Ve,qt).call(this)}cleanup(){y.info("Cleaning up recording controller"),delete window.dyteRecording,delete window.realtimeKitRecording,this.meeting.removeAllListeners(),this.removeAllListeners(),l(this,ue)!==null&&clearInterval(l(this,ue))}getParticipantCount(){return this.meeting.getParticipantCount()}getWaitlistedCount(){return this.meeting.getWaitlistedCount()}scanMeetingState(){if(!this.options.autoStop)return;if(this.getParticipantCount()>0||this.getWaitlistedCount()>0){D(this,ne,null),D(this,z,!1),window.triggerDyteRecording=!0,window.triggerRealtimeKitRecording=!0;return}if(l(this,ne)===null){D(this,ne,new Date);return}if(new Date().getTime()-l(this,ne).getTime()>this.options.waitTimeMs){y.info("Setting triggerDyteRecording & triggerRealtimeKitRecording to false"),D(this,z,!0),window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1;return}D(this,z,!1),window.triggerDyteRecording=!0,window.triggerRealtimeKitRecording=!0}stopRecording(){if(this.options.autoStop)throw new Error("Cannot stop recording when autoStop is true");y.info("Stopping recording"),window.triggerDyteRecording&&(window.triggerDyteRecording=!1),window.triggerRealtimeKitRecording&&(window.triggerRealtimeKitRecording=!1)}get meetingJoined(){return l(this,ye)}}ne=new WeakMap,z=new WeakMap,ye=new WeakMap,ue=new WeakMap,Ve=new WeakSet,qt=function(){window.dyteRecording!==void 0&&(window.dyteRecording=void 0,window.realtimeKitRecording=void 0,window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1),window.realtimeKitRecording!==void 0&&(window.dyteRecording=void 0,window.realtimeKitRecording=void 0,window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1),window.triggerDyteRecording=!0,window.triggerRealtimeKitRecording=!0,window.dyteRecording={getParticipantCount:()=>this.getParticipantCount(),isMeetingEnded:()=>l(this,z),isMeetingJoined:()=>this.meetingJoined,getMeeting:()=>this.meeting.getMeeting()},window.realtimeKitRecording={getParticipantCount:()=>this.getParticipantCount(),isMeetingEnded:()=>l(this,z),isMeetingJoined:()=>this.meetingJoined,getMeeting:()=>this.meeting.getMeeting()},this.meeting.handleParticipantJoin(()=>{y.info(`Participant joined. Total participants: ${this.getParticipantCount()}. Scanning meeting state`),this.scanMeetingState(),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleParticipantLeave(()=>{y.info(`Participant left. Remaining participants: ${this.getParticipantCount()}. Scanning meeting state`),this.scanMeetingState(),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleMeetingJoined(()=>{y.info("Meeting joined"),D(this,ye,!0),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleMeetingLeft(({state:t})=>{t!=="ended"&&t!=="kicked"||(y.info("Meeting ended"),this.emit("meetingEnded"),this.cleanup(),window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1)}),this.options.autoStop&&D(this,ue,setInterval(()=>{this.scanMeetingState()},this.options.scanInterval))};class un{constructor(e){this.meeting=e}getParticipantCount(){return this.meeting.participants.active.size}getMeeting(){return this.meeting}getWaitlistedCount(){return this.meeting.participants.waitlisted.toArray().length}handleMeetingJoined(e){this.meeting.self.on("roomJoined",e)}handleMeetingLeft(e){this.meeting.self.on("roomLeft",e)}handleParticipantJoin(e){this.meeting.participants.active.on("participantJoined",e)}handleParticipantLeave(e){this.meeting.participants.active.on("participantLeft",e)}removeAllListeners(){this.meeting.self.removeAllListeners()}}function ht(n){let e=typeof n;if(e=="object"){if(Array.isArray(n))return"array";if(n===null)return"null"}return e}function fn(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}let j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),Ie=[];for(let n=0;n<j.length;n++)Ie[j[n].charCodeAt(0)]=n;Ie["-".charCodeAt(0)]=j.indexOf("+"),Ie["_".charCodeAt(0)]=j.indexOf("/");function hn(n){let e=n.length*3/4;n[n.length-2]=="="?e-=2:n[n.length-1]=="="&&(e-=1);let t=new Uint8Array(e),i=0,r=0,s,o=0;for(let a=0;a<n.length;a++){if(s=Ie[n.charCodeAt(a)],s===void 0)switch(n[a]){case"=":r=0;case`
|
|
2
|
-
`:case"\r":case" ":case" ":continue;default:throw Error("invalid base64 string.")}switch(r){case 0:o=s,r=1;break;case 1:t[i++]=o<<2|(s&48)>>4,o=s,r=2;break;case 2:t[i++]=(o&15)<<4|(s&60)>>2,o=s,r=3;break;case 3:t[i++]=(o&3)<<6|s,r=0;break}}if(r==1)throw Error("invalid base64 string.");return t.subarray(0,i)}function ln(n){let e="",t=0,i,r=0;for(let s=0;s<n.length;s++)switch(i=n[s],t){case 0:e+=j[i>>2],r=(i&3)<<4,t=1;break;case 1:e+=j[r|i>>4],r=(i&15)<<2,t=2;break;case 2:e+=j[r|i>>6],e+=j[i&63],t=0;break}return t&&(e+=j[r],e+="=",t==1&&(e+="=")),e}var Ee;(function(n){n.symbol=Symbol.for("protobuf-ts/unknown"),n.onRead=(t,i,r,s,o)=>{(e(i)?i[n.symbol]:i[n.symbol]=[]).push({no:r,wireType:s,data:o})},n.onWrite=(t,i,r)=>{for(let{no:s,wireType:o,data:a}of n.list(i))r.tag(s,o).raw(a)},n.list=(t,i)=>{if(e(t)){let r=t[n.symbol];return i?r.filter(s=>s.no==i):r}return[]},n.last=(t,i)=>n.list(t,i).slice(-1)[0];const e=t=>t&&Array.isArray(t[n.symbol])})(Ee||(Ee={}));var F;(function(n){n[n.Varint=0]="Varint",n[n.Bit64=1]="Bit64",n[n.LengthDelimited=2]="LengthDelimited",n[n.StartGroup=3]="StartGroup",n[n.EndGroup=4]="EndGroup",n[n.Bit32=5]="Bit32"})(F||(F={}));function dn(){let n=0,e=0;for(let i=0;i<28;i+=7){let r=this.buf[this.pos++];if(n|=(r&127)<<i,!(r&128))return this.assertBounds(),[n,e]}let t=this.buf[this.pos++];if(n|=(t&15)<<28,e=(t&112)>>4,!(t&128))return this.assertBounds(),[n,e];for(let i=3;i<=31;i+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<i,!(r&128))return this.assertBounds(),[n,e]}throw new Error("invalid varint")}function We(n,e,t){for(let s=0;s<28;s=s+7){const o=n>>>s,a=!(!(o>>>7)&&e==0),f=(a?o|128:o)&255;if(t.push(f),!a)return}const i=n>>>28&15|(e&7)<<4,r=!!(e>>3);if(t.push((r?i|128:i)&255),!!r){for(let s=3;s<31;s=s+7){const o=e>>>s,a=!!(o>>>7),f=(a?o|128:o)&255;if(t.push(f),!a)return}t.push(e>>>31&1)}}const Te=65536*65536;function lt(n){let e=n[0]=="-";e&&(n=n.slice(1));const t=1e6;let i=0,r=0;function s(o,a){const f=Number(n.slice(o,a));r*=t,i=i*t+f,i>=Te&&(r=r+(i/Te|0),i=i%Te)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),[e,i,r]}function $e(n,e){if(e>>>0<=2097151)return""+(Te*e+(n>>>0));let t=n&16777215,i=(n>>>24|e<<8)>>>0&16777215,r=e>>16&65535,s=t+i*6777216+r*6710656,o=i+r*8147497,a=r*2,f=1e7;s>=f&&(o+=Math.floor(s/f),s%=f),o>=f&&(a+=Math.floor(o/f),o%=f);function h(d,N){let g=d?String(d):"";return N?"0000000".slice(g.length)+g:g}return h(a,0)+h(o,a)+h(s,1)}function dt(n,e){if(n>=0){for(;n>127;)e.push(n&127|128),n=n>>>7;e.push(n)}else{for(let t=0;t<9;t++)e.push(n&127|128),n=n>>7;e.push(1)}}function gn(){let n=this.buf[this.pos++],e=n&127;if(!(n&128))return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<7,!(n&128))return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<14,!(n&128))return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<21,!(n&128))return this.assertBounds(),e;n=this.buf[this.pos++],e|=(n&15)<<28;for(let t=5;n&128&&t<10;t++)n=this.buf[this.pos++];if(n&128)throw new Error("invalid varint");return this.assertBounds(),e>>>0}let v;function mn(){const n=new DataView(new ArrayBuffer(8));v=globalThis.BigInt!==void 0&&typeof n.getBigInt64=="function"&&typeof n.getBigUint64=="function"&&typeof n.setBigInt64=="function"&&typeof n.setBigUint64=="function"?{MIN:BigInt("-9223372036854775808"),MAX:BigInt("9223372036854775807"),UMIN:BigInt("0"),UMAX:BigInt("18446744073709551615"),C:BigInt,V:n}:void 0}mn();function gt(n){if(!n)throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support")}const mt=/^-?[0-9]+$/,Re=4294967296,Oe=2147483648;class pt{constructor(e,t){this.lo=e|0,this.hi=t|0}isZero(){return this.lo==0&&this.hi==0}toNumber(){let e=this.hi*Re+(this.lo>>>0);if(!Number.isSafeInteger(e))throw new Error("cannot convert to safe number");return e}}class B extends pt{static from(e){if(v)switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=="")throw new Error("string is no integer");e=v.C(e);case"number":if(e===0)return this.ZERO;e=v.C(e);case"bigint":if(!e)return this.ZERO;if(e<v.UMIN)throw new Error("signed value for ulong");if(e>v.UMAX)throw new Error("ulong too large");return v.V.setBigUint64(0,e,!0),new B(v.V.getInt32(0,!0),v.V.getInt32(4,!0))}else switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=e.trim(),!mt.test(e))throw new Error("string is no integer");let[t,i,r]=lt(e);if(t)throw new Error("signed value for ulong");return new B(i,r);case"number":if(e==0)return this.ZERO;if(!Number.isSafeInteger(e))throw new Error("number is no integer");if(e<0)throw new Error("signed value for ulong");return new B(e,e/Re)}throw new Error("unknown value "+typeof e)}toString(){return v?this.toBigInt().toString():$e(this.lo,this.hi)}toBigInt(){return gt(v),v.V.setInt32(0,this.lo,!0),v.V.setInt32(4,this.hi,!0),v.V.getBigUint64(0,!0)}}B.ZERO=new B(0,0);class C extends pt{static from(e){if(v)switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=="")throw new Error("string is no integer");e=v.C(e);case"number":if(e===0)return this.ZERO;e=v.C(e);case"bigint":if(!e)return this.ZERO;if(e<v.MIN)throw new Error("signed long too small");if(e>v.MAX)throw new Error("signed long too large");return v.V.setBigInt64(0,e,!0),new C(v.V.getInt32(0,!0),v.V.getInt32(4,!0))}else switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=e.trim(),!mt.test(e))throw new Error("string is no integer");let[t,i,r]=lt(e);if(t){if(r>Oe||r==Oe&&i!=0)throw new Error("signed long too small")}else if(r>=Oe)throw new Error("signed long too large");let s=new C(i,r);return t?s.negate():s;case"number":if(e==0)return this.ZERO;if(!Number.isSafeInteger(e))throw new Error("number is no integer");return e>0?new C(e,e/Re):new C(-e,-e/Re).negate()}throw new Error("unknown value "+typeof e)}isNegative(){return(this.hi&Oe)!==0}negate(){let e=~this.hi,t=this.lo;return t?t=~t+1:e+=1,new C(t,e)}toString(){if(v)return this.toBigInt().toString();if(this.isNegative()){let e=this.negate();return"-"+$e(e.lo,e.hi)}return $e(this.lo,this.hi)}toBigInt(){return gt(v),v.V.setInt32(0,this.lo,!0),v.V.setInt32(4,this.hi,!0),v.V.getBigInt64(0,!0)}}C.ZERO=new C(0,0);const wt={readUnknownField:!0,readerFactory:n=>new wn(n)};function pn(n){return n?Object.assign(Object.assign({},wt),n):wt}class wn{constructor(e,t){this.varint64=dn,this.uint32=gn,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t!=null?t:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0})}tag(){let e=this.uint32(),t=e>>>3,i=e&7;if(t<=0||i<0||i>5)throw new Error("illegal tag: field no "+t+" wire type "+i);return[t,i]}skip(e){let t=this.pos;switch(e){case F.Varint:for(;this.buf[this.pos++]&128;);break;case F.Bit64:this.pos+=4;case F.Bit32:this.pos+=4;break;case F.LengthDelimited:let i=this.uint32();this.pos+=i;break;case F.StartGroup:let r;for(;(r=this.tag()[1])!==F.EndGroup;)this.skip(r);break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(t,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return new C(...this.varint64())}uint64(){return new B(...this.varint64())}sint64(){let[e,t]=this.varint64(),i=-(e&1);return e=(e>>>1|(t&1)<<31)^i,t=t>>>1^i,new C(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return new B(this.sfixed32(),this.sfixed32())}sfixed64(){return new C(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}}function m(n,e){if(!n)throw new Error(e)}const bn=34028234663852886e22,yn=-34028234663852886e22,vn=4294967295,kn=2147483647,Nn=-2147483648;function de(n){if(typeof n!="number")throw new Error("invalid int 32: "+typeof n);if(!Number.isInteger(n)||n>kn||n<Nn)throw new Error("invalid int 32: "+n)}function Le(n){if(typeof n!="number")throw new Error("invalid uint 32: "+typeof n);if(!Number.isInteger(n)||n>vn||n<0)throw new Error("invalid uint 32: "+n)}function je(n){if(typeof n!="number")throw new Error("invalid float 32: "+typeof n);if(Number.isFinite(n)&&(n>bn||n<yn))throw new Error("invalid float 32: "+n)}const bt={writeUnknownFields:!0,writerFactory:()=>new En};function In(n){return n?Object.assign(Object.assign({},bt),n):bt}class En{constructor(e){this.stack=[],this.textEncoder=e!=null?e:new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let r=0;r<this.chunks.length;r++)e+=this.chunks[r].length;let t=new Uint8Array(e),i=0;for(let r=0;r<this.chunks.length;r++)t.set(this.chunks[r],i),i+=this.chunks[r].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw new Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(Le(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return de(e),dt(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){je(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){Le(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){de(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return de(e),e=(e<<1^e>>31)>>>0,dt(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),i=new DataView(t.buffer),r=C.from(e);return i.setInt32(0,r.lo,!0),i.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),i=new DataView(t.buffer),r=B.from(e);return i.setInt32(0,r.lo,!0),i.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=C.from(e);return We(t.lo,t.hi,this.buf),this}sint64(e){let t=C.from(e),i=t.hi>>31,r=t.lo<<1^i,s=(t.hi<<1|t.lo>>>31)^i;return We(r,s,this.buf),this}uint64(e){let t=B.from(e);return We(t.lo,t.hi,this.buf),this}}const yt={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0},vt={ignoreUnknownFields:!1};function Tn(n){return n?Object.assign(Object.assign({},vt),n):vt}function Rn(n){return n?Object.assign(Object.assign({},yt),n):yt}const kt=Symbol.for("protobuf-ts/message-type");function Nt(n){let e=!1;const t=[];for(let i=0;i<n.length;i++){let r=n.charAt(i);r=="_"?e=!0:/\d/.test(r)?(t.push(r),e=!0):e?(t.push(r.toUpperCase()),e=!1):i==0?t.push(r.toLowerCase()):t.push(r)}return t.join("")}var c;(function(n){n[n.DOUBLE=1]="DOUBLE",n[n.FLOAT=2]="FLOAT",n[n.INT64=3]="INT64",n[n.UINT64=4]="UINT64",n[n.INT32=5]="INT32",n[n.FIXED64=6]="FIXED64",n[n.FIXED32=7]="FIXED32",n[n.BOOL=8]="BOOL",n[n.STRING=9]="STRING",n[n.BYTES=12]="BYTES",n[n.UINT32=13]="UINT32",n[n.SFIXED32=15]="SFIXED32",n[n.SFIXED64=16]="SFIXED64",n[n.SINT32=17]="SINT32",n[n.SINT64=18]="SINT64"})(c||(c={}));var W;(function(n){n[n.BIGINT=0]="BIGINT",n[n.STRING=1]="STRING",n[n.NUMBER=2]="NUMBER"})(W||(W={}));var Se;(function(n){n[n.NO=0]="NO",n[n.PACKED=1]="PACKED",n[n.UNPACKED=2]="UNPACKED"})(Se||(Se={}));function On(n){var e,t,i,r;return n.localName=(e=n.localName)!==null&&e!==void 0?e:Nt(n.name),n.jsonName=(t=n.jsonName)!==null&&t!==void 0?t:Nt(n.name),n.repeat=(i=n.repeat)!==null&&i!==void 0?i:Se.NO,n.opt=(r=n.opt)!==null&&r!==void 0?r:n.repeat||n.oneof?!1:n.kind=="message",n}function Ln(n){if(typeof n!="object"||n===null||!n.hasOwnProperty("oneofKind"))return!1;switch(typeof n.oneofKind){case"string":return n[n.oneofKind]===void 0?!1:Object.keys(n).length==2;case"undefined":return Object.keys(n).length==1;default:return!1}}class Sn{constructor(e){var t;this.fields=(t=e.fields)!==null&&t!==void 0?t:[]}prepare(){if(this.data)return;const e=[],t=[],i=[];for(let r of this.fields)if(r.oneof)i.includes(r.oneof)||(i.push(r.oneof),e.push(r.oneof),t.push(r.oneof));else switch(t.push(r.localName),r.kind){case"scalar":case"enum":(!r.opt||r.repeat)&&e.push(r.localName);break;case"message":r.repeat&&e.push(r.localName);break;case"map":e.push(r.localName);break}this.data={req:e,known:t,oneofs:Object.values(i)}}is(e,t,i=!1){if(t<0)return!0;if(e==null||typeof e!="object")return!1;this.prepare();let r=Object.keys(e),s=this.data;if(r.length<s.req.length||s.req.some(o=>!r.includes(o))||!i&&r.some(o=>!s.known.includes(o)))return!1;if(t<1)return!0;for(const o of s.oneofs){const a=e[o];if(!Ln(a))return!1;if(a.oneofKind===void 0)continue;const f=this.fields.find(h=>h.localName===a.oneofKind);if(!f||!this.field(a[a.oneofKind],f,i,t))return!1}for(const o of this.fields)if(o.oneof===void 0&&!this.field(e[o.localName],o,i,t))return!1;return!0}field(e,t,i,r){let s=t.repeat;switch(t.kind){case"scalar":return e===void 0?t.opt:s?this.scalars(e,t.T,r,t.L):this.scalar(e,t.T,t.L);case"enum":return e===void 0?t.opt:s?this.scalars(e,c.INT32,r):this.scalar(e,c.INT32);case"message":return e===void 0?!0:s?this.messages(e,t.T(),i,r):this.message(e,t.T(),i,r);case"map":if(typeof e!="object"||e===null)return!1;if(r<2)return!0;if(!this.mapKeys(e,t.K,r))return!1;switch(t.V.kind){case"scalar":return this.scalars(Object.values(e),t.V.T,r,t.V.L);case"enum":return this.scalars(Object.values(e),c.INT32,r);case"message":return this.messages(Object.values(e),t.V.T(),i,r)}break}return!0}message(e,t,i,r){return i?t.isAssignable(e,r):t.is(e,r)}messages(e,t,i,r){if(!Array.isArray(e))return!1;if(r<2)return!0;if(i){for(let s=0;s<e.length&&s<r;s++)if(!t.isAssignable(e[s],r-1))return!1}else for(let s=0;s<e.length&&s<r;s++)if(!t.is(e[s],r-1))return!1;return!0}scalar(e,t,i){let r=typeof e;switch(t){case c.UINT64:case c.FIXED64:case c.INT64:case c.SFIXED64:case c.SINT64:switch(i){case W.BIGINT:return r=="bigint";case W.NUMBER:return r=="number"&&!isNaN(e);default:return r=="string"}case c.BOOL:return r=="boolean";case c.STRING:return r=="string";case c.BYTES:return e instanceof Uint8Array;case c.DOUBLE:case c.FLOAT:return r=="number"&&!isNaN(e);default:return r=="number"&&Number.isInteger(e)}}scalars(e,t,i,r){if(!Array.isArray(e))return!1;if(i<2)return!0;if(Array.isArray(e)){for(let s=0;s<e.length&&s<i;s++)if(!this.scalar(e[s],t,r))return!1}return!0}mapKeys(e,t,i){let r=Object.keys(e);switch(t){case c.INT32:case c.FIXED32:case c.SFIXED32:case c.SINT32:case c.UINT32:return this.scalars(r.slice(0,i).map(s=>parseInt(s)),t,i);case c.BOOL:return this.scalars(r.slice(0,i).map(s=>s=="true"?!0:s=="false"?!1:s),t,i);default:return this.scalars(r,t,i,W.STRING)}}}function V(n,e){switch(e){case W.BIGINT:return n.toBigInt();case W.NUMBER:return n.toNumber();default:return n.toString()}}class Fn{constructor(e){this.info=e}prepare(){var e;if(this.fMap===void 0){this.fMap={};const t=(e=this.info.fields)!==null&&e!==void 0?e:[];for(const i of t)this.fMap[i.name]=i,this.fMap[i.jsonName]=i,this.fMap[i.localName]=i}}assert(e,t,i){if(!e){let r=ht(i);throw(r=="number"||r=="boolean")&&(r=i.toString()),new Error(`Cannot parse JSON ${r} for ${this.info.typeName}#${t}`)}}read(e,t,i){this.prepare();const r=[];for(const[s,o]of Object.entries(e)){const a=this.fMap[s];if(!a){if(!i.ignoreUnknownFields)throw new Error(`Found unknown field while reading ${this.info.typeName} from JSON format. JSON key: ${s}`);continue}const f=a.localName;let h;if(a.oneof){if(o===null&&(a.kind!=="enum"||a.T()[0]!=="google.protobuf.NullValue"))continue;if(r.includes(a.oneof))throw new Error(`Multiple members of the oneof group "${a.oneof}" of ${this.info.typeName} are present in JSON.`);r.push(a.oneof),h=t[a.oneof]={oneofKind:f}}else h=t;if(a.kind=="map"){if(o===null)continue;this.assert(fn(o),a.name,o);const d=h[f];for(const[N,g]of Object.entries(o)){this.assert(g!==null,a.name+" map value",null);let _;switch(a.V.kind){case"message":_=a.V.T().internalJsonRead(g,i);break;case"enum":if(_=this.enum(a.V.T(),g,a.name,i.ignoreUnknownFields),_===!1)continue;break;case"scalar":_=this.scalar(g,a.V.T,a.V.L,a.name);break}this.assert(_!==void 0,a.name+" map value",g);let U=N;a.K==c.BOOL&&(U=U=="true"?!0:U=="false"?!1:U),U=this.scalar(U,a.K,W.STRING,a.name).toString(),d[U]=_}}else if(a.repeat){if(o===null)continue;this.assert(Array.isArray(o),a.name,o);const d=h[f];for(const N of o){this.assert(N!==null,a.name,null);let g;switch(a.kind){case"message":g=a.T().internalJsonRead(N,i);break;case"enum":if(g=this.enum(a.T(),N,a.name,i.ignoreUnknownFields),g===!1)continue;break;case"scalar":g=this.scalar(N,a.T,a.L,a.name);break}this.assert(g!==void 0,a.name,o),d.push(g)}}else switch(a.kind){case"message":if(o===null&&a.T().typeName!="google.protobuf.Value"){this.assert(a.oneof===void 0,a.name+" (oneof member)",null);continue}h[f]=a.T().internalJsonRead(o,i,h[f]);break;case"enum":if(o===null)continue;let d=this.enum(a.T(),o,a.name,i.ignoreUnknownFields);if(d===!1)continue;h[f]=d;break;case"scalar":if(o===null)continue;h[f]=this.scalar(o,a.T,a.L,a.name);break}}}enum(e,t,i,r){if(e[0]=="google.protobuf.NullValue"&&m(t===null||t==="NULL_VALUE",`Unable to parse field ${this.info.typeName}#${i}, enum ${e[0]} only accepts null.`),t===null)return 0;switch(typeof t){case"number":return m(Number.isInteger(t),`Unable to parse field ${this.info.typeName}#${i}, enum can only be integral number, got ${t}.`),t;case"string":let s=t;e[2]&&t.substring(0,e[2].length)===e[2]&&(s=t.substring(e[2].length));let o=e[1][s];return typeof o=="undefined"&&r?!1:(m(typeof o=="number",`Unable to parse field ${this.info.typeName}#${i}, enum ${e[0]} has no value for "${t}".`),o)}m(!1,`Unable to parse field ${this.info.typeName}#${i}, cannot parse enum value from ${typeof t}".`)}scalar(e,t,i,r){let s;try{switch(t){case c.DOUBLE:case c.FLOAT:if(e===null)return 0;if(e==="NaN")return Number.NaN;if(e==="Infinity")return Number.POSITIVE_INFINITY;if(e==="-Infinity")return Number.NEGATIVE_INFINITY;if(e===""){s="empty string";break}if(typeof e=="string"&&e.trim().length!==e.length){s="extra whitespace";break}if(typeof e!="string"&&typeof e!="number")break;let o=Number(e);if(Number.isNaN(o)){s="not a number";break}if(!Number.isFinite(o)){s="too large or small";break}return t==c.FLOAT&&je(o),o;case c.INT32:case c.FIXED32:case c.SFIXED32:case c.SINT32:case c.UINT32:if(e===null)return 0;let a;if(typeof e=="number"?a=e:e===""?s="empty string":typeof e=="string"&&(e.trim().length!==e.length?s="extra whitespace":a=Number(e)),a===void 0)break;return t==c.UINT32?Le(a):de(a),a;case c.INT64:case c.SFIXED64:case c.SINT64:if(e===null)return V(C.ZERO,i);if(typeof e!="number"&&typeof e!="string")break;return V(C.from(e),i);case c.FIXED64:case c.UINT64:if(e===null)return V(B.ZERO,i);if(typeof e!="number"&&typeof e!="string")break;return V(B.from(e),i);case c.BOOL:if(e===null)return!1;if(typeof e!="boolean")break;return e;case c.STRING:if(e===null)return"";if(typeof e!="string"){s="extra whitespace";break}try{encodeURIComponent(e)}catch(f){f="invalid UTF8";break}return e;case c.BYTES:if(e===null||e==="")return new Uint8Array(0);if(typeof e!="string")break;return hn(e)}}catch(o){s=o.message}this.assert(!1,r+(s?" - "+s:""),e)}}class Cn{constructor(e){var t;this.fields=(t=e.fields)!==null&&t!==void 0?t:[]}write(e,t){const i={},r=e;for(const s of this.fields){if(!s.oneof){let h=this.field(s,r[s.localName],t);h!==void 0&&(i[t.useProtoFieldName?s.name:s.jsonName]=h);continue}const o=r[s.oneof];if(o.oneofKind!==s.localName)continue;const a=s.kind=="scalar"||s.kind=="enum"?Object.assign(Object.assign({},t),{emitDefaultValues:!0}):t;let f=this.field(s,o[s.localName],a);m(f!==void 0),i[t.useProtoFieldName?s.name:s.jsonName]=f}return i}field(e,t,i){let r;if(e.kind=="map"){m(typeof t=="object"&&t!==null);const s={};switch(e.V.kind){case"scalar":for(const[f,h]of Object.entries(t)){const d=this.scalar(e.V.T,h,e.name,!1,!0);m(d!==void 0),s[f.toString()]=d}break;case"message":const o=e.V.T();for(const[f,h]of Object.entries(t)){const d=this.message(o,h,e.name,i);m(d!==void 0),s[f.toString()]=d}break;case"enum":const a=e.V.T();for(const[f,h]of Object.entries(t)){m(h===void 0||typeof h=="number");const d=this.enum(a,h,e.name,!1,!0,i.enumAsInteger);m(d!==void 0),s[f.toString()]=d}break}(i.emitDefaultValues||Object.keys(s).length>0)&&(r=s)}else if(e.repeat){m(Array.isArray(t));const s=[];switch(e.kind){case"scalar":for(let f=0;f<t.length;f++){const h=this.scalar(e.T,t[f],e.name,e.opt,!0);m(h!==void 0),s.push(h)}break;case"enum":const o=e.T();for(let f=0;f<t.length;f++){m(t[f]===void 0||typeof t[f]=="number");const h=this.enum(o,t[f],e.name,e.opt,!0,i.enumAsInteger);m(h!==void 0),s.push(h)}break;case"message":const a=e.T();for(let f=0;f<t.length;f++){const h=this.message(a,t[f],e.name,i);m(h!==void 0),s.push(h)}break}(i.emitDefaultValues||s.length>0||i.emitDefaultValues)&&(r=s)}else switch(e.kind){case"scalar":r=this.scalar(e.T,t,e.name,e.opt,i.emitDefaultValues);break;case"enum":r=this.enum(e.T(),t,e.name,e.opt,i.emitDefaultValues,i.enumAsInteger);break;case"message":r=this.message(e.T(),t,e.name,i);break}return r}enum(e,t,i,r,s,o){if(e[0]=="google.protobuf.NullValue")return!s&&!r?void 0:null;if(t===void 0){m(r);return}if(!(t===0&&!s&&!r))return m(typeof t=="number"),m(Number.isInteger(t)),o||!e[1].hasOwnProperty(t)?t:e[2]?e[2]+e[1][t]:e[1][t]}message(e,t,i,r){return t===void 0?r.emitDefaultValues?null:void 0:e.internalJsonWrite(t,r)}scalar(e,t,i,r,s){if(t===void 0){m(r);return}const o=s||r;switch(e){case c.INT32:case c.SFIXED32:case c.SINT32:return t===0?o?0:void 0:(de(t),t);case c.FIXED32:case c.UINT32:return t===0?o?0:void 0:(Le(t),t);case c.FLOAT:je(t);case c.DOUBLE:return t===0?o?0:void 0:(m(typeof t=="number"),Number.isNaN(t)?"NaN":t===Number.POSITIVE_INFINITY?"Infinity":t===Number.NEGATIVE_INFINITY?"-Infinity":t);case c.STRING:return t===""?o?"":void 0:(m(typeof t=="string"),t);case c.BOOL:return t===!1?o?!1:void 0:(m(typeof t=="boolean"),t);case c.UINT64:case c.FIXED64:m(typeof t=="number"||typeof t=="string"||typeof t=="bigint");let a=B.from(t);return a.isZero()&&!o?void 0:a.toString();case c.INT64:case c.SFIXED64:case c.SINT64:m(typeof t=="number"||typeof t=="string"||typeof t=="bigint");let f=C.from(t);return f.isZero()&&!o?void 0:f.toString();case c.BYTES:return m(t instanceof Uint8Array),t.byteLength?ln(t):o?"":void 0}}}function Je(n,e=W.STRING){switch(n){case c.BOOL:return!1;case c.UINT64:case c.FIXED64:return V(B.ZERO,e);case c.INT64:case c.SFIXED64:case c.SINT64:return V(C.ZERO,e);case c.DOUBLE:case c.FLOAT:return 0;case c.BYTES:return new Uint8Array(0);case c.STRING:return"";default:return 0}}class Mn{constructor(e){this.info=e}prepare(){var e;if(!this.fieldNoToField){const t=(e=this.info.fields)!==null&&e!==void 0?e:[];this.fieldNoToField=new Map(t.map(i=>[i.no,i]))}}read(e,t,i,r){this.prepare();const s=r===void 0?e.len:e.pos+r;for(;e.pos<s;){const[o,a]=e.tag(),f=this.fieldNoToField.get(o);if(!f){let g=i.readUnknownField;if(g=="throw")throw new Error(`Unknown field ${o} (wire type ${a}) for ${this.info.typeName}`);let _=e.skip(a);g!==!1&&(g===!0?Ee.onRead:g)(this.info.typeName,t,o,a,_);continue}let h=t,d=f.repeat,N=f.localName;switch(f.oneof&&(h=h[f.oneof],h.oneofKind!==N&&(h=t[f.oneof]={oneofKind:N})),f.kind){case"scalar":case"enum":let g=f.kind=="enum"?c.INT32:f.T,_=f.kind=="scalar"?f.L:void 0;if(d){let re=h[N];if(a==F.LengthDelimited&&g!=c.STRING&&g!=c.BYTES){let he=e.uint32()+e.pos;for(;e.pos<he;)re.push(this.scalar(e,g,_))}else re.push(this.scalar(e,g,_))}else h[N]=this.scalar(e,g,_);break;case"message":if(d){let re=h[N],he=f.T().internalBinaryRead(e,e.uint32(),i);re.push(he)}else h[N]=f.T().internalBinaryRead(e,e.uint32(),i,h[N]);break;case"map":let[U,Pe]=this.mapEntry(f,e,i);h[N][U]=Pe;break}}}mapEntry(e,t,i){let r=t.uint32(),s=t.pos+r,o,a;for(;t.pos<s;){let[f,h]=t.tag();switch(f){case 1:e.K==c.BOOL?o=t.bool().toString():o=this.scalar(t,e.K,W.STRING);break;case 2:switch(e.V.kind){case"scalar":a=this.scalar(t,e.V.T,e.V.L);break;case"enum":a=t.int32();break;case"message":a=e.V.T().internalBinaryRead(t,t.uint32(),i);break}break;default:throw new Error(`Unknown field ${f} (wire type ${h}) in map entry for ${this.info.typeName}#${e.name}`)}}if(o===void 0){let f=Je(e.K);o=e.K==c.BOOL?f.toString():f}if(a===void 0)switch(e.V.kind){case"scalar":a=Je(e.V.T,e.V.L);break;case"enum":a=0;break;case"message":a=e.V.T().create();break}return[o,a]}scalar(e,t,i){switch(t){case c.INT32:return e.int32();case c.STRING:return e.string();case c.BOOL:return e.bool();case c.DOUBLE:return e.double();case c.FLOAT:return e.float();case c.INT64:return V(e.int64(),i);case c.UINT64:return V(e.uint64(),i);case c.FIXED64:return V(e.fixed64(),i);case c.FIXED32:return e.fixed32();case c.BYTES:return e.bytes();case c.UINT32:return e.uint32();case c.SFIXED32:return e.sfixed32();case c.SFIXED64:return V(e.sfixed64(),i);case c.SINT32:return e.sint32();case c.SINT64:return V(e.sint64(),i)}}}class An{constructor(e){this.info=e}prepare(){if(!this.fields){const e=this.info.fields?this.info.fields.concat():[];this.fields=e.sort((t,i)=>t.no-i.no)}}write(e,t,i){this.prepare();for(const s of this.fields){let o,a,f=s.repeat,h=s.localName;if(s.oneof){const d=e[s.oneof];if(d.oneofKind!==h)continue;o=d[h],a=!0}else o=e[h],a=!1;switch(s.kind){case"scalar":case"enum":let d=s.kind=="enum"?c.INT32:s.T;if(f)if(m(Array.isArray(o)),f==Se.PACKED)this.packed(t,d,s.no,o);else for(const N of o)this.scalar(t,d,s.no,N,!0);else o===void 0?m(s.opt):this.scalar(t,d,s.no,o,a||s.opt);break;case"message":if(f){m(Array.isArray(o));for(const N of o)this.message(t,i,s.T(),s.no,N)}else this.message(t,i,s.T(),s.no,o);break;case"map":m(typeof o=="object"&&o!==null);for(const[N,g]of Object.entries(o))this.mapEntry(t,i,s,N,g);break}}let r=i.writeUnknownFields;r!==!1&&(r===!0?Ee.onWrite:r)(this.info.typeName,e,t)}mapEntry(e,t,i,r,s){e.tag(i.no,F.LengthDelimited),e.fork();let o=r;switch(i.K){case c.INT32:case c.FIXED32:case c.UINT32:case c.SFIXED32:case c.SINT32:o=Number.parseInt(r);break;case c.BOOL:m(r=="true"||r=="false"),o=r=="true";break}switch(this.scalar(e,i.K,1,o,!0),i.V.kind){case"scalar":this.scalar(e,i.V.T,2,s,!0);break;case"enum":this.scalar(e,c.INT32,2,s,!0);break;case"message":this.message(e,t,i.V.T(),2,s);break}e.join()}message(e,t,i,r,s){s!==void 0&&(i.internalBinaryWrite(s,e.tag(r,F.LengthDelimited).fork(),t),e.join())}scalar(e,t,i,r,s){let[o,a,f]=this.scalarInfo(t,r);(!f||s)&&(e.tag(i,o),e[a](r))}packed(e,t,i,r){if(!r.length)return;m(t!==c.BYTES&&t!==c.STRING),e.tag(i,F.LengthDelimited),e.fork();let[,s]=this.scalarInfo(t);for(let o=0;o<r.length;o++)e[s](r[o]);e.join()}scalarInfo(e,t){let i=F.Varint,r,s=t===void 0,o=t===0;switch(e){case c.INT32:r="int32";break;case c.STRING:o=s||!t.length,i=F.LengthDelimited,r="string";break;case c.BOOL:o=t===!1,r="bool";break;case c.UINT32:r="uint32";break;case c.DOUBLE:i=F.Bit64,r="double";break;case c.FLOAT:i=F.Bit32,r="float";break;case c.INT64:o=s||C.from(t).isZero(),r="int64";break;case c.UINT64:o=s||B.from(t).isZero(),r="uint64";break;case c.FIXED64:o=s||B.from(t).isZero(),i=F.Bit64,r="fixed64";break;case c.BYTES:o=s||!t.byteLength,i=F.LengthDelimited,r="bytes";break;case c.FIXED32:i=F.Bit32,r="fixed32";break;case c.SFIXED32:i=F.Bit32,r="sfixed32";break;case c.SFIXED64:o=s||C.from(t).isZero(),i=F.Bit64,r="sfixed64";break;case c.SINT32:r="sint32";break;case c.SINT64:o=s||C.from(t).isZero(),r="sint64";break}return[i,r,s||o]}}function Dn(n){const e=n.messagePrototype?Object.create(n.messagePrototype):Object.defineProperty({},kt,{value:n});for(let t of n.fields){let i=t.localName;if(!t.opt)if(t.oneof)e[t.oneof]={oneofKind:void 0};else if(t.repeat)e[i]=[];else switch(t.kind){case"scalar":e[i]=Je(t.T,t.L);break;case"enum":e[i]=0;break;case"map":e[i]={};break}}return e}function Xe(n,e,t){let i,r=t,s;for(let o of n.fields){let a=o.localName;if(o.oneof){const f=r[o.oneof];if((f==null?void 0:f.oneofKind)==null)continue;if(i=f[a],s=e[o.oneof],s.oneofKind=f.oneofKind,i==null){delete s[a];continue}}else if(i=r[a],s=e,i==null)continue;switch(o.repeat&&(s[a].length=i.length),o.kind){case"scalar":case"enum":if(o.repeat)for(let h=0;h<i.length;h++)s[a][h]=i[h];else s[a]=i;break;case"message":let f=o.T();if(o.repeat)for(let h=0;h<i.length;h++)s[a][h]=f.create(i[h]);else s[a]===void 0?s[a]=f.create(i):f.mergePartial(s[a],i);break;case"map":switch(o.V.kind){case"scalar":case"enum":Object.assign(s[a],i);break;case"message":let h=o.V.T();for(let d of Object.keys(i))s[a][d]=h.create(i[d]);break}break}}}function Bn(n,e,t){if(e===t)return!0;if(!e||!t)return!1;for(let i of n.fields){let r=i.localName,s=i.oneof?e[i.oneof][r]:e[r],o=i.oneof?t[i.oneof][r]:t[r];switch(i.kind){case"enum":case"scalar":let a=i.kind=="enum"?c.INT32:i.T;if(!(i.repeat?Et(a,s,o):It(a,s,o)))return!1;break;case"map":if(!(i.V.kind=="message"?Tt(i.V.T(),Fe(s),Fe(o)):Et(i.V.kind=="enum"?c.INT32:i.V.T,Fe(s),Fe(o))))return!1;break;case"message":let f=i.T();if(!(i.repeat?Tt(f,s,o):f.equals(s,o)))return!1;break}}return!0}const Fe=Object.values;function It(n,e,t){if(e===t)return!0;if(n!==c.BYTES)return!1;let i=e,r=t;if(i.length!==r.length)return!1;for(let s=0;s<i.length;s++)if(i[s]!=r[s])return!1;return!0}function Et(n,e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!It(n,e[i],t[i]))return!1;return!0}function Tt(n,e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!n.equals(e[i],t[i]))return!1;return!0}const Rt=Object.getOwnPropertyDescriptors(Object.getPrototypeOf({})),_n=Rt[kt]={};class xn{constructor(e,t,i){this.defaultCheckDepth=16,this.typeName=e,this.fields=t.map(On),this.options=i!=null?i:{},_n.value=this,this.messagePrototype=Object.create(null,Rt),this.refTypeCheck=new Sn(this),this.refJsonReader=new Fn(this),this.refJsonWriter=new Cn(this),this.refBinReader=new Mn(this),this.refBinWriter=new An(this)}create(e){let t=Dn(this);return e!==void 0&&Xe(this,t,e),t}clone(e){let t=this.create();return Xe(this,t,e),t}equals(e,t){return Bn(this,e,t)}is(e,t=this.defaultCheckDepth){return this.refTypeCheck.is(e,t,!1)}isAssignable(e,t=this.defaultCheckDepth){return this.refTypeCheck.is(e,t,!0)}mergePartial(e,t){Xe(this,e,t)}fromBinary(e,t){let i=pn(t);return this.internalBinaryRead(i.readerFactory(e),e.byteLength,i)}fromJson(e,t){return this.internalJsonRead(e,Tn(t))}fromJsonString(e,t){let i=JSON.parse(e);return this.fromJson(i,t)}toJson(e,t){return this.internalJsonWrite(e,Rn(t))}toJsonString(e,t){var i;let r=this.toJson(e,t);return JSON.stringify(r,null,(i=t==null?void 0:t.prettySpaces)!==null&&i!==void 0?i:0)}toBinary(e,t){let i=In(t);return this.internalBinaryWrite(e,i.writerFactory(),i).finish()}internalJsonRead(e,t,i){if(e!==null&&typeof e=="object"&&!Array.isArray(e)){let r=i!=null?i:this.create();return this.refJsonReader.read(e,r,t),r}throw new Error(`Unable to parse message ${this.typeName} from JSON ${ht(e)}.`)}internalJsonWrite(e,t){return this.refJsonWriter.write(e,t)}internalBinaryWrite(e,t,i){return this.refBinWriter.write(e,t,i),t}internalBinaryRead(e,t,i,r){let s=r!=null?r:this.create();return this.refBinReader.read(e,s,i,t),s}}var Kn=Object.defineProperty,Un=(n,e,t)=>e in n?Kn(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Vn=(n,e,t)=>(Un(n,typeof e!="symbol"?e+"":e,t),t),Ge=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)},u=(n,e,t)=>(Ge(n,e,"read from private field"),t?t.call(n):e.get(n)),T=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},p=(n,e,t,i)=>(Ge(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t),R=(n,e,t)=>(Ge(n,e,"access private method"),t),Ce={},Pn={get exports(){return Ce},set exports(n){Ce=n}},se=typeof Reflect=="object"?Reflect:null,Ot=se&&typeof se.apply=="function"?se.apply:function(n,e,t){return Function.prototype.apply.call(n,e,t)},Me;se&&typeof se.ownKeys=="function"?Me=se.ownKeys:Object.getOwnPropertySymbols?Me=function(n){return Object.getOwnPropertyNames(n).concat(Object.getOwnPropertySymbols(n))}:Me=function(n){return Object.getOwnPropertyNames(n)};function Wn(n){console&&console.warn&&console.warn(n)}var Lt=Number.isNaN||function(n){return n!==n};function b(){b.init.call(this)}Pn.exports=b,Ce.once=Xn,b.EventEmitter=b,b.prototype._events=void 0,b.prototype._eventsCount=0,b.prototype._maxListeners=void 0;var St=10;function Ae(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(b,"defaultMaxListeners",{enumerable:!0,get:function(){return St},set:function(n){if(typeof n!="number"||n<0||Lt(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");St=n}}),b.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},b.prototype.setMaxListeners=function(n){if(typeof n!="number"||n<0||Lt(n))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+n+".");return this._maxListeners=n,this};function Ft(n){return n._maxListeners===void 0?b.defaultMaxListeners:n._maxListeners}b.prototype.getMaxListeners=function(){return Ft(this)},b.prototype.emit=function(n){for(var e=[],t=1;t<arguments.length;t++)e.push(arguments[t]);var i=n==="error",r=this._events;if(r!==void 0)i=i&&r.error===void 0;else if(!i)return!1;if(i){var s;if(e.length>0&&(s=e[0]),s instanceof Error)throw s;var o=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw o.context=s,o}var a=r[n];if(a===void 0)return!1;if(typeof a=="function")Ot(a,this,e);else for(var f=a.length,h=Bt(a,f),t=0;t<f;++t)Ot(h[t],this,e);return!0};function Ct(n,e,t,i){var r,s,o;if(Ae(t),s=n._events,s===void 0?(s=n._events=Object.create(null),n._eventsCount=0):(s.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),s=n._events),o=s[e]),o===void 0)o=s[e]=t,++n._eventsCount;else if(typeof o=="function"?o=s[e]=i?[t,o]:[o,t]:i?o.unshift(t):o.push(t),r=Ft(n),r>0&&o.length>r&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=o.length,Wn(a)}return n}b.prototype.addListener=function(n,e){return Ct(this,n,e,!1)},b.prototype.on=b.prototype.addListener,b.prototype.prependListener=function(n,e){return Ct(this,n,e,!0)};function $n(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Mt(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},r=$n.bind(i);return r.listener=t,i.wrapFn=r,r}b.prototype.once=function(n,e){return Ae(e),this.on(n,Mt(this,n,e)),this},b.prototype.prependOnceListener=function(n,e){return Ae(e),this.prependListener(n,Mt(this,n,e)),this},b.prototype.removeListener=function(n,e){var t,i,r,s,o;if(Ae(e),i=this._events,i===void 0)return this;if(t=i[n],t===void 0)return this;if(t===e||t.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete i[n],i.removeListener&&this.emit("removeListener",n,t.listener||e));else if(typeof t!="function"){for(r=-1,s=t.length-1;s>=0;s--)if(t[s]===e||t[s].listener===e){o=t[s].listener,r=s;break}if(r<0)return this;r===0?t.shift():jn(t,r),t.length===1&&(i[n]=t[0]),i.removeListener!==void 0&&this.emit("removeListener",n,o||e)}return this},b.prototype.off=b.prototype.removeListener,b.prototype.removeAllListeners=function(n){var e,t,i;if(t=this._events,t===void 0)return this;if(t.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):t[n]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete t[n]),this;if(arguments.length===0){var r=Object.keys(t),s;for(i=0;i<r.length;++i)s=r[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=t[n],typeof e=="function")this.removeListener(n,e);else if(e!==void 0)for(i=e.length-1;i>=0;i--)this.removeListener(n,e[i]);return this};function At(n,e,t){var i=n._events;if(i===void 0)return[];var r=i[e];return r===void 0?[]:typeof r=="function"?t?[r.listener||r]:[r]:t?Jn(r):Bt(r,r.length)}b.prototype.listeners=function(n){return At(this,n,!0)},b.prototype.rawListeners=function(n){return At(this,n,!1)},b.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):Dt.call(n,e)},b.prototype.listenerCount=Dt;function Dt(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}b.prototype.eventNames=function(){return this._eventsCount>0?Me(this._events):[]};function Bt(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function jn(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function Jn(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function Xn(n,e){return new Promise(function(t,i){function r(o){n.removeListener(e,s),i(o)}function s(){typeof n.removeListener=="function"&&n.removeListener("error",r),t([].slice.call(arguments))}_t(n,e,s,{once:!0}),e!=="error"&&Gn(n,r,{once:!0})})}function Gn(n,e,t){typeof n.on=="function"&&_t(n,"error",e,t)}function _t(n,e,t,i){if(typeof n.on=="function")i.once?n.once(e,t):n.on(e,t);else if(typeof n.addEventListener=="function")n.addEventListener(e,function r(s){i.once&&n.removeEventListener(e,r),t(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}class Zn extends xn{constructor(){super("message.v1.SocketMessage",[{no:1,name:"event",kind:"scalar",T:13},{no:2,name:"id",kind:"scalar",opt:!0,T:9},{no:3,name:"payload",kind:"scalar",opt:!0,T:12},{no:4,name:"metadata",kind:"scalar",opt:!0,T:12}])}}const xt=new Zn;class Kt{static encode(e){return xt.toBinary(e)}static decode(e){return xt.fromBinary(new Uint8Array(e))}}function Yn(n,e){return Math.floor(Math.random()*(e-n+1)+n)}var G;class qn{constructor(e={}){Vn(this,"opts"),T(this,G,void 0),this.opts={initialTimeout:e.initialTimeout||1e3,maxTimeout:e.maxTimeout||1e4,factor:e.factor||2},p(this,G,0)}async wait(){p(this,G,u(this,G)+1);const e=Yn(0,Math.min(this.opts.maxTimeout,this.opts.initialTimeout*2**u(this,G)));await new Promise(t=>{setTimeout(t,e)})}getAttempts(){return u(this,G)}reset(){p(this,G,0)}}G=new WeakMap;const Z={debug:0,info:1,warn:2,error:3};var ee,te;class zn{constructor(e){T(this,ee,void 0),T(this,te,void 0),p(this,ee,console),p(this,te,e)}debug(...e){Z[u(this,te)]>Z.debug||u(this,ee).debug("[Sockrates]:",...e)}info(...e){Z[u(this,te)]>Z.info||u(this,ee).info("[Sockrates]:",...e)}warn(...e){Z[u(this,te)]>Z.warn||u(this,ee).warn("[Sockrates]:",...e)}error(...e){Z[u(this,te)]>Z.error||u(this,ee).error("[Sockrates]:",...e)}}ee=new WeakMap,te=new WeakMap;var Ut=(n=>(n[n.CONNECTING=0]="CONNECTING",n[n.OPEN=1]="OPEN",n[n.CLOSING=2]="CLOSING",n[n.CLOSED=3]="CLOSED",n))(Ut||{});const Qn="2",Hn="3";var L,oe,O,M,Y,A,J,q,P,ae,X,Ze,Vt,ge,De,Ye,Pt,qe,Wt,Be,ze,Qe,$t,me,_e,pe,xe,Ke,He,ce,we,be,Ue;class ei{constructor(e,t){var g,_,U,Pe,re,he,jt,Jt,Xt,Gt;T(this,Ze),T(this,ge),T(this,Ye),T(this,qe),T(this,Be),T(this,Qe),T(this,me),T(this,pe),T(this,Ke),T(this,ce),T(this,be),T(this,L,void 0),T(this,oe,void 0),T(this,O,void 0),T(this,M,void 0),T(this,Y,void 0),T(this,A,void 0),T(this,J,void 0),T(this,q,void 0),T(this,P,void 0),T(this,ae,void 0),T(this,X,void 0);var i,r,s,o,a,f,h,d,N;p(this,oe,e),p(this,Y,[]),p(this,A,new Ce),p(this,J,!0),p(this,P,!1),p(this,O,t!=null?t:{}),(g=(i=u(this,O)).autoReconnect)!=null||(i.autoReconnect=!0),(_=(r=u(this,O)).retryConnectionInterval)!=null||(r.retryConnectionInterval=1e3),(U=(s=u(this,O)).pingTimeout)!=null||(s.pingTimeout=3e4),(Pe=(o=u(this,O)).connectionTimeout)!=null||(o.connectionTimeout=5e3),(re=(a=u(this,O)).debug)!=null||(a.debug=!0),(he=(f=u(this,O)).maxReconnectionAttempts)!=null||(f.maxReconnectionAttempts=10),(jt=(h=u(this,O)).disconnectOnPingTimeout)!=null||(h.disconnectOnPingTimeout=!0),(Jt=(d=u(this,O)).queueOnDisconnect)!=null||(d.queueOnDisconnect=!1),(Xt=(N=u(this,O)).flushOnReconnect)!=null||(N.flushOnReconnect=!1),p(this,q,{code:void 0,reason:void 0}),p(this,M,(Gt=u(this,O).logger)!=null?Gt:new zn(u(this,O).debug?"debug":"info")),p(this,X,new qn)}get readyState(){var e;return(e=u(this,L))==null?void 0:e.readyState}get url(){return u(this,oe)}updateURL(e){p(this,oe,e),R(this,Qe,$t).call(this)}get config(){return u(this,O)}get sendQueue(){return u(this,Y)}flush(){if(!u(this,O).queueOnDisconnect)return!1;const e=[];return u(this,Y).forEach(t=>{this.send(t.event,t.id,t.payload,t.metadata)||e.push(t)}),p(this,Y,e),u(this,Y)}async connect(e=!1){if(!e&&[0,1].includes(this.readyState)){u(this,M).debug("Websocket was already connecting or connected.");return}if(u(this,J)!==!1)return new Promise((t,i)=>{R(this,ce,we).call(this),R(this,be,Ue).call(this);try{p(this,L,new WebSocket(R(this,Ze,Vt).call(this,u(this,oe)))),u(this,L).binaryType="arraybuffer",u(this,M).debug("Connecting");const r=setTimeout(()=>{u(this,M).debug("Connection timeout. Closing socket"),p(this,J,!0),R(this,be,Ue).call(this),u(this,L).close(3001,"Connection Timeout"),u(this,O).autoReconnect&&!u(this,P)&&(u(this,A).emit("reconnecting"),R(this,me,_e).call(this)),i(new Error("Connection timed out!"))},u(this,O).connectionTimeout);u(this,L).onopen=()=>{u(this,M).debug(`Ready State: ${Ut[u(this,L).readyState]}`),r&&clearTimeout(r),R(this,Ke,He).call(this),p(this,q,{code:void 0,reason:void 0}),u(this,A).emit("connected"),u(this,O).flushOnReconnect&&this.flush(),t()},u(this,L).onclose=s=>{try{r&&clearTimeout(r);const{code:o,reason:a}=s;i(a),u(this,M).debug("Socket closed. Close event:",{event:s}),u(this,M).debug(`Connection closed code: ${o}`),u(this,M).debug(`Connection closed reason: ${a}`),u(this,P)||R(this,Be,ze).call(this,o,a)}catch(o){R(this,ge,De).call(this,o)}},u(this,L).onerror=s=>{R(this,ge,De).call(this,s)},u(this,L).onmessage=s=>R(this,Ye,Pt).call(this,s)}catch(r){R(this,ge,De).call(this,r,i)}})}send(e,t,i,r){const s={event:e,id:t,payload:i,metadata:r};if(u(this,O).queueOnDisconnect&&(!u(this,L)||u(this,L).readyState!==1))return u(this,M).debug("Queuing message since socket is not connected!",s),u(this,Y).push(s),!1;const o=Kt.encode(s);return R(this,pe,xe).call(this,o)}emit(e,t,i,r){return this.send(e,t,i,r)}sendRaw(e){return R(this,pe,xe).call(this,e)}receive(e,t){return u(this,A).on(e.toString(),t)}on(e,t){if(typeof e=="string"&&(e==="connected"||e==="disconnected"||e==="errored"||e==="reconnected"||e==="reconnecting"||e==="reconnectAttempt"||e==="reconnectFailure"||e==="failed")){u(this,A).on(e,t);return}this.receive(e,t)}removeAllListeners(){u(this,A).removeAllListeners()}removeReceiver(e,t){this.removeListener(e,t)}removeListener(e,t){u(this,A).removeListener(e.toString(),t)}removeReceivers(e){this.removeListeners(e)}removeListeners(e){u(this,A).listeners(e.toString()).map(t=>this.removeListener(e,t))}disconnect(){p(this,J,!1),R(this,ce,we).call(this),this.removeAllListeners(),p(this,q,{code:1e3,reason:"Sockrates disconnect method called"}),u(this,L).close(1e3,"Sockrates disconnect method called.")}}L=new WeakMap,oe=new WeakMap,O=new WeakMap,M=new WeakMap,Y=new WeakMap,A=new WeakMap,J=new WeakMap,q=new WeakMap,P=new WeakMap,ae=new WeakMap,X=new WeakMap,Ze=new WeakSet,Vt=function(n){if(n.startsWith("ws://")||n.startsWith("wss://"))return n;if(n.startsWith("https://"))return`wss://${n.substring(8)}`;if(n.startsWith("http://"))return`ws://${n.substring(7)}`;throw new Error("Invalid URL. URL must start with http(s):// or ws(s)://.")},ge=new WeakSet,De=function(n,e){u(this,M).error("Error:",{error:n}),u(this,A).emit("errored",{error:n}),e==null||e(n)},Ye=new WeakSet,Pt=function(n){if(R(this,Ke,He).call(this),n.data===Qn){u(this,M).debug("Received ping from server"),R(this,pe,xe).call(this,Hn);return}const e=Kt.decode(n.data),{id:t,payload:i}=e;u(this,M).debug("Received message",{event:e.event,messageID:t}),u(this,A).emit(e.event.toString(),{id:t,payload:i})},qe=new WeakSet,Wt=function(){return u(this,L).readyState===1},Be=new WeakSet,ze=function(n,e){p(this,q,{reason:e,code:n}),u(this,A).emit("disconnected",{code:n,reason:e})},Qe=new WeakSet,$t=function(){const{reason:n,code:e}=u(this,q);e&&e!==1e3&&u(this,J)&&u(this,O).autoReconnect&&!u(this,P)&&(u(this,M).debug(`Triggering reconnection due to ${n}.`),u(this,A).emit("reconnecting"),R(this,me,_e).call(this))},me=new WeakSet,_e=async function(n=!0){if(n&&u(this,P)){u(this,M).debug("Reconnect called when already in a reconnect loop. Ignoring.");return}if(u(this,P)||u(this,X).reset(),u(this,O).maxReconnectionAttempts!==null&&u(this,X).getAttempts()>=u(this,O).maxReconnectionAttempts){u(this,A).emit("failed"),p(this,P,!1);return}p(this,P,!0),R(this,be,Ue).call(this),R(this,ce,we).call(this);try{if(await u(this,X).wait(),u(this,J)===!1)return;if(u(this,M).debug(`Reconnection attempt ${u(this,X).getAttempts()}`),u(this,A).emit("reconnectAttempt",{attempt:u(this,X).getAttempts()}),await this.connect(),!R(this,qe,Wt).call(this))throw Error("Reconnect Failed");p(this,P,!1),p(this,q,{code:void 0,reason:void 0}),u(this,A).emit("reconnected")}catch(e){u(this,M).debug("Failed to reconnect."),u(this,A).emit("reconnectFailure",{attempt:u(this,X).getAttempts()}),R(this,me,_e).call(this,!1)}},pe=new WeakSet,xe=function(n){try{return u(this,L).send(n),!0}catch(e){return u(this,M).error(e.message),!1}},Ke=new WeakSet,He=function(){this.config.disconnectOnPingTimeout&&(u(this,M).debug("Resetting ping timeout"),R(this,ce,we).call(this),p(this,ae,setTimeout(()=>{var n;u(this,M).debug("Disconnecting the socket due to ping timeout"),p(this,J,!0);const e=3002,t="Ping timeout";(n=u(this,L))==null||n.close(e,t),R(this,Be,ze).call(this,e,t)},u(this,O).pingTimeout)))},ce=new WeakSet,we=function(){u(this,ae)&&(clearTimeout(u(this,ae)),p(this,ae,void 0))},be=new WeakSet,Ue=function(){u(this,L)&&(u(this,L).onopen=void 0,u(this,L).onerror=void 0,u(this,L).onmessage=void 0,u(this,L).onclose=void 0)};class ti{constructor(e,t){this.url=e,console.info(`Creating websocket with url: ${e} and config: ${t}`)}sendRaw(e){return console.info(`Sending raw message to websocket: ${e}`),!0}connect(e){return console.info(`Connecting to websocket: ${this.url} with force: ${e}`),Promise.resolve()}disconnect(){console.info(`Disconnecting from websocket: ${this.url}`)}on(e,t){console.info(`Adding listener to websocket: ${e} with listener: ${t}`)}}class ni{constructor(e,t=!1){x(this,Q,null);x(this,ie,!1);x(this,ve,!1);this.wsUrl=e,this.devMode=t}get connected(){return l(this,ie)}async connect(e){let t;this.devMode?t=new ti(this.wsUrl,{queueOnDisconnect:!0,flushOnReconnect:!0}):t=new ei(this.wsUrl,{queueOnDisconnect:!0,flushOnReconnect:!0}),e.participants.addListener("broadcastedMessage",i=>t.sendRaw(JSON.stringify(i))),y.info("Connecting to websocket"),t.on("connected",()=>{y.info("Connected to websocket")}),await t.connect(!0),D(this,Q,t),D(this,ie,!0)}disconnect(){l(this,Q)&&(l(this,Q).disconnect(),D(this,ie,!1))}startRecordingMessage(){if(l(this,ve))throw new Error("Start recording message already sent");if(l(this,Q)&&l(this,ie))D(this,ve,!0),l(this,Q).sendRaw(JSON.stringify({type:"StartRecording"}));else throw new Error("Not connected to websocket, make sure you have called init.")}}Q=new WeakMap,ie=new WeakMap,ve=new WeakMap;class ii{constructor(){}checkIfSDKEnabled(){return y.info("Check if SDK enabled"),window.dyteRecordingSdk===!0||window.realtimeKitRecordingSdk===!0}checkIfRecordingTriggerAdded(){return y.info("Check if recording trigger added"),window.triggerDyteRecording===!0||window.triggerRealtimeKitRecording===!0}checkMeetingJoined(){var e;return y.info("Check if meeting joined getter available"),((e=window.realtimeKitRecording)==null?void 0:e.isMeetingJoined())!==!0}checkParticipantCount(){var e;return y.info("Check if participant count getter available"),((e=window.realtimeKitRecording)==null?void 0:e.getParticipantCount())!==void 0}pageLoadTests(){y.info("Running on page load tests");let e=[];if(this.checkIfSDKEnabled()||e.push("SDK not enabled"),e.length>0)throw new Error(e.join(", "))}sdkInitTests(){y.info("Running SDK init tests");let e=[];if(this.checkIfRecordingTriggerAdded()||e.push("Recording trigger not added"),this.checkParticipantCount()||e.push("Participant count getter not working"),e.length>0)throw new Error(e.join(`
|
|
3
|
-
`))}showAlert(e){
|
|
1
|
+
var gi=Object.defineProperty;var mi=(R,E,O)=>E in R?gi(R,E,{enumerable:!0,configurable:!0,writable:!0,value:O}):R[E]=O;var on=(R,E,O)=>(mi(R,typeof E!="symbol"?E+"":E,O),O),st=(R,E,O)=>{if(!E.has(R))throw TypeError("Cannot "+O)};var l=(R,E,O)=>(st(R,E,"read from private field"),O?O.call(R):E.get(R)),x=(R,E,O)=>{if(E.has(R))throw TypeError("Cannot add the same private member more than once");E instanceof WeakSet?E.add(R):E.set(R,O)},D=(R,E,O,ge)=>(st(R,E,"write to private field"),ge?ge.call(R,O):E.set(R,O),O);var an=(R,E,O)=>(st(R,E,"access private method"),O);var RecordingSDK=function(R){var ne,z,Ie,he,je,cn,Q,ie,Ne,H,F,K,$,le;"use strict";var E={exports:{}},O=typeof Reflect=="object"?Reflect:null,ge=O&&typeof O.apply=="function"?O.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)},Ee;O&&typeof O.ownKeys=="function"?Ee=O.ownKeys:Object.getOwnPropertySymbols?Ee=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Ee=function(e){return Object.getOwnPropertyNames(e)};function un(n){console&&console.warn&&console.warn(n)}var ot=Number.isNaN||function(e){return e!==e};function b(){b.init.call(this)}E.exports=b,E.exports.once=dn,b.EventEmitter=b,b.prototype._events=void 0,b.prototype._eventsCount=0,b.prototype._maxListeners=void 0;var at=10;function Te(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(b,"defaultMaxListeners",{enumerable:!0,get:function(){return at},set:function(n){if(typeof n!="number"||n<0||ot(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");at=n}}),b.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},b.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||ot(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function ct(n){return n._maxListeners===void 0?b.defaultMaxListeners:n._maxListeners}b.prototype.getMaxListeners=function(){return ct(this)},b.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var r=e==="error",s=this._events;if(s!==void 0)r=r&&s.error===void 0;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var f=s[e];if(f===void 0)return!1;if(typeof f=="function")ge(f,this,t);else for(var h=f.length,d=dt(f,h),i=0;i<h;++i)ge(d[i],this,t);return!0};function ut(n,e,t,i){var r,s,o;if(Te(t),s=n._events,s===void 0?(s=n._events=Object.create(null),n._eventsCount=0):(s.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),s=n._events),o=s[e]),o===void 0)o=s[e]=t,++n._eventsCount;else if(typeof o=="function"?o=s[e]=i?[t,o]:[o,t]:i?o.unshift(t):o.push(t),r=ct(n),r>0&&o.length>r&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=o.length,un(a)}return n}b.prototype.addListener=function(e,t){return ut(this,e,t,!1)},b.prototype.on=b.prototype.addListener,b.prototype.prependListener=function(e,t){return ut(this,e,t,!0)};function fn(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ft(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},r=fn.bind(i);return r.listener=t,i.wrapFn=r,r}b.prototype.once=function(e,t){return Te(t),this.on(e,ft(this,e,t)),this},b.prototype.prependOnceListener=function(e,t){return Te(t),this.prependListener(e,ft(this,e,t)),this},b.prototype.removeListener=function(e,t){var i,r,s,o,a;if(Te(t),r=this._events,r===void 0)return this;if(i=r[e],i===void 0)return this;if(i===t||i.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if(typeof i!="function"){for(s=-1,o=i.length-1;o>=0;o--)if(i[o]===t||i[o].listener===t){a=i[o].listener,s=o;break}if(s<0)return this;s===0?i.shift():hn(i,s),i.length===1&&(r[e]=i[0]),r.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this},b.prototype.off=b.prototype.removeListener,b.prototype.removeAllListeners=function(e){var t,i,r;if(i=this._events,i===void 0)return this;if(i.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):i[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete i[e]),this;if(arguments.length===0){var s=Object.keys(i),o;for(r=0;r<s.length;++r)o=s[r],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=i[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function ht(n,e,t){var i=n._events;if(i===void 0)return[];var r=i[e];return r===void 0?[]:typeof r=="function"?t?[r.listener||r]:[r]:t?ln(r):dt(r,r.length)}b.prototype.listeners=function(e){return ht(this,e,!0)},b.prototype.rawListeners=function(e){return ht(this,e,!1)},b.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):lt.call(n,e)},b.prototype.listenerCount=lt;function lt(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}b.prototype.eventNames=function(){return this._eventsCount>0?Ee(this._events):[]};function dt(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function hn(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function ln(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function dn(n,e){return new Promise(function(t,i){function r(o){n.removeListener(e,s),i(o)}function s(){typeof n.removeListener=="function"&&n.removeListener("error",r),t([].slice.call(arguments))}gt(n,e,s,{once:!0}),e!=="error"&&gn(n,r,{once:!0})})}function gn(n,e,t){typeof n.on=="function"&>(n,"error",e,t)}function gt(n,e,t,i){if(typeof n.on=="function")i.once?n.once(e,t):n.on(e,t);else if(typeof n.addEventListener=="function")n.addEventListener(e,function r(s){i.once&&n.removeEventListener(e,r),t(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}var mn=E.exports;class pn{constructor(){on(this,"client")}logToConsole(){return window.devMode===!0&&!this.isInitialized()}init(e){this.client=e}isInitialized(){return this.client!==void 0}generateMessage(e){return`RealtimeKitRecordingLogger::${e}`}info(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.info(this.generateMessage(e),t,i)),this.logToConsole()&&console.log(e)}error(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.error(this.generateMessage(e),t,i)),this.logToConsole()&&console.error(e)}debug(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.debug(this.generateMessage(e),t,i)),this.logToConsole()&&console.debug(e)}log(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.log(this.generateMessage(e),t,i)),this.logToConsole()&&console.log(e)}warn(e,t,i){var r;this.isInitialized()&&((r=this.client)==null||r.__internals__.logger.warn(this.generateMessage(e),t,i)),this.logToConsole()&&console.warn(e)}}const I=new pn,mt=1e3,wn=60*mt,bn=1*mt;class yn extends mn.EventEmitter{constructor(t,i){super();x(this,je);x(this,ne,null);x(this,z,!1);x(this,Ie,!1);x(this,he,null);this.meeting=t,this.options=i,an(this,je,cn).call(this)}cleanup(){I.info("Cleaning up recording controller"),delete window.dyteRecording,delete window.realtimeKitRecording,this.meeting.removeAllListeners(),this.removeAllListeners(),l(this,he)!==null&&clearInterval(l(this,he))}getParticipantCount(){return this.meeting.getParticipantCount()}getWaitlistedCount(){return this.meeting.getWaitlistedCount()}scanMeetingState(){if(!this.options.autoStop)return;if(this.getParticipantCount()>0||this.getWaitlistedCount()>0){D(this,ne,null),D(this,z,!1),window.triggerDyteRecording=!0,window.triggerRealtimeKitRecording=!0;return}if(l(this,ne)===null){D(this,ne,new Date);return}if(new Date().getTime()-l(this,ne).getTime()>this.options.waitTimeMs){I.info("Setting triggerDyteRecording & triggerRealtimeKitRecording to false"),D(this,z,!0),window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1;return}D(this,z,!1),window.triggerDyteRecording=!0,window.triggerRealtimeKitRecording=!0}stopRecording(){if(this.options.autoStop)throw new Error("Cannot stop recording when autoStop is true");I.info("Stopping recording"),window.triggerDyteRecording&&(window.triggerDyteRecording=!1),window.triggerRealtimeKitRecording&&(window.triggerRealtimeKitRecording=!1)}get meetingJoined(){return l(this,Ie)}}ne=new WeakMap,z=new WeakMap,Ie=new WeakMap,he=new WeakMap,je=new WeakSet,cn=function(){window.dyteRecording!==void 0&&(window.dyteRecording=void 0,window.realtimeKitRecording=void 0,window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1),window.realtimeKitRecording!==void 0&&(window.dyteRecording=void 0,window.realtimeKitRecording=void 0,window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1),window.triggerDyteRecording=!0,window.triggerRealtimeKitRecording=!0,window.dyteRecording={getParticipantCount:()=>this.getParticipantCount(),isMeetingEnded:()=>l(this,z),isMeetingJoined:()=>this.meetingJoined,getMeeting:()=>this.meeting.getMeeting()},window.realtimeKitRecording={getParticipantCount:()=>this.getParticipantCount(),isMeetingEnded:()=>l(this,z),isMeetingJoined:()=>this.meetingJoined,getMeeting:()=>this.meeting.getMeeting()},this.meeting.handleParticipantJoin(()=>{I.info(`Participant joined. Total participants: ${this.getParticipantCount()}. Scanning meeting state`),this.scanMeetingState(),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleParticipantLeave(()=>{I.info(`Participant left. Remaining participants: ${this.getParticipantCount()}. Scanning meeting state`),this.scanMeetingState(),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleMeetingJoined(()=>{I.info("Meeting joined"),D(this,Ie,!0),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleMeetingLeft(({state:t})=>{t!=="ended"&&t!=="kicked"||(I.info("Meeting ended"),this.emit("meetingEnded"),this.cleanup(),window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1)}),this.options.autoStop&&D(this,he,setInterval(()=>{this.scanMeetingState()},this.options.scanInterval))};class vn{constructor(e){this.meeting=e}getParticipantCount(){return this.meeting.participants.active.size}getMeeting(){return this.meeting}getWaitlistedCount(){return this.meeting.participants.waitlisted.toArray().length}handleMeetingJoined(e){this.meeting.self.on("roomJoined",e)}handleMeetingLeft(e){this.meeting.self.on("roomLeft",e)}handleParticipantJoin(e){this.meeting.participants.active.on("participantJoined",e)}handleParticipantLeave(e){this.meeting.participants.active.on("participantLeft",e)}removeAllListeners(){this.meeting.self.removeAllListeners()}}function pt(n){let e=typeof n;if(e=="object"){if(Array.isArray(n))return"array";if(n===null)return"null"}return e}function kn(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}let j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),Re=[];for(let n=0;n<j.length;n++)Re[j[n].charCodeAt(0)]=n;Re["-".charCodeAt(0)]=j.indexOf("+"),Re["_".charCodeAt(0)]=j.indexOf("/");function In(n){let e=n.length*3/4;n[n.length-2]=="="?e-=2:n[n.length-1]=="="&&(e-=1);let t=new Uint8Array(e),i=0,r=0,s,o=0;for(let a=0;a<n.length;a++){if(s=Re[n.charCodeAt(a)],s===void 0)switch(n[a]){case"=":r=0;case`
|
|
2
|
+
`:case"\r":case" ":case" ":continue;default:throw Error("invalid base64 string.")}switch(r){case 0:o=s,r=1;break;case 1:t[i++]=o<<2|(s&48)>>4,o=s,r=2;break;case 2:t[i++]=(o&15)<<4|(s&60)>>2,o=s,r=3;break;case 3:t[i++]=(o&3)<<6|s,r=0;break}}if(r==1)throw Error("invalid base64 string.");return t.subarray(0,i)}function Nn(n){let e="",t=0,i,r=0;for(let s=0;s<n.length;s++)switch(i=n[s],t){case 0:e+=j[i>>2],r=(i&3)<<4,t=1;break;case 1:e+=j[r|i>>4],r=(i&15)<<2,t=2;break;case 2:e+=j[r|i>>6],e+=j[i&63],t=0;break}return t&&(e+=j[r],e+="=",t==1&&(e+="=")),e}var Oe;(function(n){n.symbol=Symbol.for("protobuf-ts/unknown"),n.onRead=(t,i,r,s,o)=>{(e(i)?i[n.symbol]:i[n.symbol]=[]).push({no:r,wireType:s,data:o})},n.onWrite=(t,i,r)=>{for(let{no:s,wireType:o,data:a}of n.list(i))r.tag(s,o).raw(a)},n.list=(t,i)=>{if(e(t)){let r=t[n.symbol];return i?r.filter(s=>s.no==i):r}return[]},n.last=(t,i)=>n.list(t,i).slice(-1)[0];const e=t=>t&&Array.isArray(t[n.symbol])})(Oe||(Oe={}));var C;(function(n){n[n.Varint=0]="Varint",n[n.Bit64=1]="Bit64",n[n.LengthDelimited=2]="LengthDelimited",n[n.StartGroup=3]="StartGroup",n[n.EndGroup=4]="EndGroup",n[n.Bit32=5]="Bit32"})(C||(C={}));function En(){let n=0,e=0;for(let i=0;i<28;i+=7){let r=this.buf[this.pos++];if(n|=(r&127)<<i,!(r&128))return this.assertBounds(),[n,e]}let t=this.buf[this.pos++];if(n|=(t&15)<<28,e=(t&112)>>4,!(t&128))return this.assertBounds(),[n,e];for(let i=3;i<=31;i+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<i,!(r&128))return this.assertBounds(),[n,e]}throw new Error("invalid varint")}function Xe(n,e,t){for(let s=0;s<28;s=s+7){const o=n>>>s,a=!(!(o>>>7)&&e==0),f=(a?o|128:o)&255;if(t.push(f),!a)return}const i=n>>>28&15|(e&7)<<4,r=!!(e>>3);if(t.push((r?i|128:i)&255),!!r){for(let s=3;s<31;s=s+7){const o=e>>>s,a=!!(o>>>7),f=(a?o|128:o)&255;if(t.push(f),!a)return}t.push(e>>>31&1)}}const Le=65536*65536;function wt(n){let e=n[0]=="-";e&&(n=n.slice(1));const t=1e6;let i=0,r=0;function s(o,a){const f=Number(n.slice(o,a));r*=t,i=i*t+f,i>=Le&&(r=r+(i/Le|0),i=i%Le)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),[e,i,r]}function Ge(n,e){if(e>>>0<=2097151)return""+(Le*e+(n>>>0));let t=n&16777215,i=(n>>>24|e<<8)>>>0&16777215,r=e>>16&65535,s=t+i*6777216+r*6710656,o=i+r*8147497,a=r*2,f=1e7;s>=f&&(o+=Math.floor(s/f),s%=f),o>=f&&(a+=Math.floor(o/f),o%=f);function h(d,T){let g=d?String(d):"";return T?"0000000".slice(g.length)+g:g}return h(a,0)+h(o,a)+h(s,1)}function bt(n,e){if(n>=0){for(;n>127;)e.push(n&127|128),n=n>>>7;e.push(n)}else{for(let t=0;t<9;t++)e.push(n&127|128),n=n>>7;e.push(1)}}function Tn(){let n=this.buf[this.pos++],e=n&127;if(!(n&128))return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<7,!(n&128))return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<14,!(n&128))return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<21,!(n&128))return this.assertBounds(),e;n=this.buf[this.pos++],e|=(n&15)<<28;for(let t=5;n&128&&t<10;t++)n=this.buf[this.pos++];if(n&128)throw new Error("invalid varint");return this.assertBounds(),e>>>0}let N;function Rn(){const n=new DataView(new ArrayBuffer(8));N=globalThis.BigInt!==void 0&&typeof n.getBigInt64=="function"&&typeof n.getBigUint64=="function"&&typeof n.setBigInt64=="function"&&typeof n.setBigUint64=="function"?{MIN:BigInt("-9223372036854775808"),MAX:BigInt("9223372036854775807"),UMIN:BigInt("0"),UMAX:BigInt("18446744073709551615"),C:BigInt,V:n}:void 0}Rn();function yt(n){if(!n)throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support")}const vt=/^-?[0-9]+$/,Se=4294967296,Fe=2147483648;class kt{constructor(e,t){this.lo=e|0,this.hi=t|0}isZero(){return this.lo==0&&this.hi==0}toNumber(){let e=this.hi*Se+(this.lo>>>0);if(!Number.isSafeInteger(e))throw new Error("cannot convert to safe number");return e}}class B extends kt{static from(e){if(N)switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=="")throw new Error("string is no integer");e=N.C(e);case"number":if(e===0)return this.ZERO;e=N.C(e);case"bigint":if(!e)return this.ZERO;if(e<N.UMIN)throw new Error("signed value for ulong");if(e>N.UMAX)throw new Error("ulong too large");return N.V.setBigUint64(0,e,!0),new B(N.V.getInt32(0,!0),N.V.getInt32(4,!0))}else switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=e.trim(),!vt.test(e))throw new Error("string is no integer");let[t,i,r]=wt(e);if(t)throw new Error("signed value for ulong");return new B(i,r);case"number":if(e==0)return this.ZERO;if(!Number.isSafeInteger(e))throw new Error("number is no integer");if(e<0)throw new Error("signed value for ulong");return new B(e,e/Se)}throw new Error("unknown value "+typeof e)}toString(){return N?this.toBigInt().toString():Ge(this.lo,this.hi)}toBigInt(){return yt(N),N.V.setInt32(0,this.lo,!0),N.V.setInt32(4,this.hi,!0),N.V.getBigUint64(0,!0)}}B.ZERO=new B(0,0);class M extends kt{static from(e){if(N)switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=="")throw new Error("string is no integer");e=N.C(e);case"number":if(e===0)return this.ZERO;e=N.C(e);case"bigint":if(!e)return this.ZERO;if(e<N.MIN)throw new Error("signed long too small");if(e>N.MAX)throw new Error("signed long too large");return N.V.setBigInt64(0,e,!0),new M(N.V.getInt32(0,!0),N.V.getInt32(4,!0))}else switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=e.trim(),!vt.test(e))throw new Error("string is no integer");let[t,i,r]=wt(e);if(t){if(r>Fe||r==Fe&&i!=0)throw new Error("signed long too small")}else if(r>=Fe)throw new Error("signed long too large");let s=new M(i,r);return t?s.negate():s;case"number":if(e==0)return this.ZERO;if(!Number.isSafeInteger(e))throw new Error("number is no integer");return e>0?new M(e,e/Se):new M(-e,-e/Se).negate()}throw new Error("unknown value "+typeof e)}isNegative(){return(this.hi&Fe)!==0}negate(){let e=~this.hi,t=this.lo;return t?t=~t+1:e+=1,new M(t,e)}toString(){if(N)return this.toBigInt().toString();if(this.isNegative()){let e=this.negate();return"-"+Ge(e.lo,e.hi)}return Ge(this.lo,this.hi)}toBigInt(){return yt(N),N.V.setInt32(0,this.lo,!0),N.V.setInt32(4,this.hi,!0),N.V.getBigInt64(0,!0)}}M.ZERO=new M(0,0);const It={readUnknownField:!0,readerFactory:n=>new Ln(n)};function On(n){return n?Object.assign(Object.assign({},It),n):It}class Ln{constructor(e,t){this.varint64=En,this.uint32=Tn,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t!=null?t:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0})}tag(){let e=this.uint32(),t=e>>>3,i=e&7;if(t<=0||i<0||i>5)throw new Error("illegal tag: field no "+t+" wire type "+i);return[t,i]}skip(e){let t=this.pos;switch(e){case C.Varint:for(;this.buf[this.pos++]&128;);break;case C.Bit64:this.pos+=4;case C.Bit32:this.pos+=4;break;case C.LengthDelimited:let i=this.uint32();this.pos+=i;break;case C.StartGroup:let r;for(;(r=this.tag()[1])!==C.EndGroup;)this.skip(r);break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(t,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return new M(...this.varint64())}uint64(){return new B(...this.varint64())}sint64(){let[e,t]=this.varint64(),i=-(e&1);return e=(e>>>1|(t&1)<<31)^i,t=t>>>1^i,new M(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return new B(this.sfixed32(),this.sfixed32())}sfixed64(){return new M(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}}function m(n,e){if(!n)throw new Error(e)}const Sn=34028234663852886e22,Fn=-34028234663852886e22,Cn=4294967295,Mn=2147483647,An=-2147483648;function me(n){if(typeof n!="number")throw new Error("invalid int 32: "+typeof n);if(!Number.isInteger(n)||n>Mn||n<An)throw new Error("invalid int 32: "+n)}function Ce(n){if(typeof n!="number")throw new Error("invalid uint 32: "+typeof n);if(!Number.isInteger(n)||n>Cn||n<0)throw new Error("invalid uint 32: "+n)}function Ze(n){if(typeof n!="number")throw new Error("invalid float 32: "+typeof n);if(Number.isFinite(n)&&(n>Sn||n<Fn))throw new Error("invalid float 32: "+n)}const Nt={writeUnknownFields:!0,writerFactory:()=>new Bn};function Dn(n){return n?Object.assign(Object.assign({},Nt),n):Nt}class Bn{constructor(e){this.stack=[],this.textEncoder=e!=null?e:new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let r=0;r<this.chunks.length;r++)e+=this.chunks[r].length;let t=new Uint8Array(e),i=0;for(let r=0;r<this.chunks.length;r++)t.set(this.chunks[r],i),i+=this.chunks[r].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw new Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(Ce(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return me(e),bt(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){Ze(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){Ce(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){me(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return me(e),e=(e<<1^e>>31)>>>0,bt(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),i=new DataView(t.buffer),r=M.from(e);return i.setInt32(0,r.lo,!0),i.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),i=new DataView(t.buffer),r=B.from(e);return i.setInt32(0,r.lo,!0),i.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=M.from(e);return Xe(t.lo,t.hi,this.buf),this}sint64(e){let t=M.from(e),i=t.hi>>31,r=t.lo<<1^i,s=(t.hi<<1|t.lo>>>31)^i;return Xe(r,s,this.buf),this}uint64(e){let t=B.from(e);return Xe(t.lo,t.hi,this.buf),this}}const Et={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0},Tt={ignoreUnknownFields:!1};function _n(n){return n?Object.assign(Object.assign({},Tt),n):Tt}function xn(n){return n?Object.assign(Object.assign({},Et),n):Et}const Rt=Symbol.for("protobuf-ts/message-type");function Ot(n){let e=!1;const t=[];for(let i=0;i<n.length;i++){let r=n.charAt(i);r=="_"?e=!0:/\d/.test(r)?(t.push(r),e=!0):e?(t.push(r.toUpperCase()),e=!1):i==0?t.push(r.toLowerCase()):t.push(r)}return t.join("")}var u;(function(n){n[n.DOUBLE=1]="DOUBLE",n[n.FLOAT=2]="FLOAT",n[n.INT64=3]="INT64",n[n.UINT64=4]="UINT64",n[n.INT32=5]="INT32",n[n.FIXED64=6]="FIXED64",n[n.FIXED32=7]="FIXED32",n[n.BOOL=8]="BOOL",n[n.STRING=9]="STRING",n[n.BYTES=12]="BYTES",n[n.UINT32=13]="UINT32",n[n.SFIXED32=15]="SFIXED32",n[n.SFIXED64=16]="SFIXED64",n[n.SINT32=17]="SINT32",n[n.SINT64=18]="SINT64"})(u||(u={}));var W;(function(n){n[n.BIGINT=0]="BIGINT",n[n.STRING=1]="STRING",n[n.NUMBER=2]="NUMBER"})(W||(W={}));var Me;(function(n){n[n.NO=0]="NO",n[n.PACKED=1]="PACKED",n[n.UNPACKED=2]="UNPACKED"})(Me||(Me={}));function Kn(n){var e,t,i,r;return n.localName=(e=n.localName)!==null&&e!==void 0?e:Ot(n.name),n.jsonName=(t=n.jsonName)!==null&&t!==void 0?t:Ot(n.name),n.repeat=(i=n.repeat)!==null&&i!==void 0?i:Me.NO,n.opt=(r=n.opt)!==null&&r!==void 0?r:n.repeat||n.oneof?!1:n.kind=="message",n}function Vn(n){if(typeof n!="object"||n===null||!n.hasOwnProperty("oneofKind"))return!1;switch(typeof n.oneofKind){case"string":return n[n.oneofKind]===void 0?!1:Object.keys(n).length==2;case"undefined":return Object.keys(n).length==1;default:return!1}}class Un{constructor(e){var t;this.fields=(t=e.fields)!==null&&t!==void 0?t:[]}prepare(){if(this.data)return;const e=[],t=[],i=[];for(let r of this.fields)if(r.oneof)i.includes(r.oneof)||(i.push(r.oneof),e.push(r.oneof),t.push(r.oneof));else switch(t.push(r.localName),r.kind){case"scalar":case"enum":(!r.opt||r.repeat)&&e.push(r.localName);break;case"message":r.repeat&&e.push(r.localName);break;case"map":e.push(r.localName);break}this.data={req:e,known:t,oneofs:Object.values(i)}}is(e,t,i=!1){if(t<0)return!0;if(e==null||typeof e!="object")return!1;this.prepare();let r=Object.keys(e),s=this.data;if(r.length<s.req.length||s.req.some(o=>!r.includes(o))||!i&&r.some(o=>!s.known.includes(o)))return!1;if(t<1)return!0;for(const o of s.oneofs){const a=e[o];if(!Vn(a))return!1;if(a.oneofKind===void 0)continue;const f=this.fields.find(h=>h.localName===a.oneofKind);if(!f||!this.field(a[a.oneofKind],f,i,t))return!1}for(const o of this.fields)if(o.oneof===void 0&&!this.field(e[o.localName],o,i,t))return!1;return!0}field(e,t,i,r){let s=t.repeat;switch(t.kind){case"scalar":return e===void 0?t.opt:s?this.scalars(e,t.T,r,t.L):this.scalar(e,t.T,t.L);case"enum":return e===void 0?t.opt:s?this.scalars(e,u.INT32,r):this.scalar(e,u.INT32);case"message":return e===void 0?!0:s?this.messages(e,t.T(),i,r):this.message(e,t.T(),i,r);case"map":if(typeof e!="object"||e===null)return!1;if(r<2)return!0;if(!this.mapKeys(e,t.K,r))return!1;switch(t.V.kind){case"scalar":return this.scalars(Object.values(e),t.V.T,r,t.V.L);case"enum":return this.scalars(Object.values(e),u.INT32,r);case"message":return this.messages(Object.values(e),t.V.T(),i,r)}break}return!0}message(e,t,i,r){return i?t.isAssignable(e,r):t.is(e,r)}messages(e,t,i,r){if(!Array.isArray(e))return!1;if(r<2)return!0;if(i){for(let s=0;s<e.length&&s<r;s++)if(!t.isAssignable(e[s],r-1))return!1}else for(let s=0;s<e.length&&s<r;s++)if(!t.is(e[s],r-1))return!1;return!0}scalar(e,t,i){let r=typeof e;switch(t){case u.UINT64:case u.FIXED64:case u.INT64:case u.SFIXED64:case u.SINT64:switch(i){case W.BIGINT:return r=="bigint";case W.NUMBER:return r=="number"&&!isNaN(e);default:return r=="string"}case u.BOOL:return r=="boolean";case u.STRING:return r=="string";case u.BYTES:return e instanceof Uint8Array;case u.DOUBLE:case u.FLOAT:return r=="number"&&!isNaN(e);default:return r=="number"&&Number.isInteger(e)}}scalars(e,t,i,r){if(!Array.isArray(e))return!1;if(i<2)return!0;if(Array.isArray(e)){for(let s=0;s<e.length&&s<i;s++)if(!this.scalar(e[s],t,r))return!1}return!0}mapKeys(e,t,i){let r=Object.keys(e);switch(t){case u.INT32:case u.FIXED32:case u.SFIXED32:case u.SINT32:case u.UINT32:return this.scalars(r.slice(0,i).map(s=>parseInt(s)),t,i);case u.BOOL:return this.scalars(r.slice(0,i).map(s=>s=="true"?!0:s=="false"?!1:s),t,i);default:return this.scalars(r,t,i,W.STRING)}}}function U(n,e){switch(e){case W.BIGINT:return n.toBigInt();case W.NUMBER:return n.toNumber();default:return n.toString()}}class Pn{constructor(e){this.info=e}prepare(){var e;if(this.fMap===void 0){this.fMap={};const t=(e=this.info.fields)!==null&&e!==void 0?e:[];for(const i of t)this.fMap[i.name]=i,this.fMap[i.jsonName]=i,this.fMap[i.localName]=i}}assert(e,t,i){if(!e){let r=pt(i);throw(r=="number"||r=="boolean")&&(r=i.toString()),new Error(`Cannot parse JSON ${r} for ${this.info.typeName}#${t}`)}}read(e,t,i){this.prepare();const r=[];for(const[s,o]of Object.entries(e)){const a=this.fMap[s];if(!a){if(!i.ignoreUnknownFields)throw new Error(`Found unknown field while reading ${this.info.typeName} from JSON format. JSON key: ${s}`);continue}const f=a.localName;let h;if(a.oneof){if(o===null&&(a.kind!=="enum"||a.T()[0]!=="google.protobuf.NullValue"))continue;if(r.includes(a.oneof))throw new Error(`Multiple members of the oneof group "${a.oneof}" of ${this.info.typeName} are present in JSON.`);r.push(a.oneof),h=t[a.oneof]={oneofKind:f}}else h=t;if(a.kind=="map"){if(o===null)continue;this.assert(kn(o),a.name,o);const d=h[f];for(const[T,g]of Object.entries(o)){this.assert(g!==null,a.name+" map value",null);let _;switch(a.V.kind){case"message":_=a.V.T().internalJsonRead(g,i);break;case"enum":if(_=this.enum(a.V.T(),g,a.name,i.ignoreUnknownFields),_===!1)continue;break;case"scalar":_=this.scalar(g,a.V.T,a.V.L,a.name);break}this.assert(_!==void 0,a.name+" map value",g);let V=T;a.K==u.BOOL&&(V=V=="true"?!0:V=="false"?!1:V),V=this.scalar(V,a.K,W.STRING,a.name).toString(),d[V]=_}}else if(a.repeat){if(o===null)continue;this.assert(Array.isArray(o),a.name,o);const d=h[f];for(const T of o){this.assert(T!==null,a.name,null);let g;switch(a.kind){case"message":g=a.T().internalJsonRead(T,i);break;case"enum":if(g=this.enum(a.T(),T,a.name,i.ignoreUnknownFields),g===!1)continue;break;case"scalar":g=this.scalar(T,a.T,a.L,a.name);break}this.assert(g!==void 0,a.name,o),d.push(g)}}else switch(a.kind){case"message":if(o===null&&a.T().typeName!="google.protobuf.Value"){this.assert(a.oneof===void 0,a.name+" (oneof member)",null);continue}h[f]=a.T().internalJsonRead(o,i,h[f]);break;case"enum":if(o===null)continue;let d=this.enum(a.T(),o,a.name,i.ignoreUnknownFields);if(d===!1)continue;h[f]=d;break;case"scalar":if(o===null)continue;h[f]=this.scalar(o,a.T,a.L,a.name);break}}}enum(e,t,i,r){if(e[0]=="google.protobuf.NullValue"&&m(t===null||t==="NULL_VALUE",`Unable to parse field ${this.info.typeName}#${i}, enum ${e[0]} only accepts null.`),t===null)return 0;switch(typeof t){case"number":return m(Number.isInteger(t),`Unable to parse field ${this.info.typeName}#${i}, enum can only be integral number, got ${t}.`),t;case"string":let s=t;e[2]&&t.substring(0,e[2].length)===e[2]&&(s=t.substring(e[2].length));let o=e[1][s];return typeof o=="undefined"&&r?!1:(m(typeof o=="number",`Unable to parse field ${this.info.typeName}#${i}, enum ${e[0]} has no value for "${t}".`),o)}m(!1,`Unable to parse field ${this.info.typeName}#${i}, cannot parse enum value from ${typeof t}".`)}scalar(e,t,i,r){let s;try{switch(t){case u.DOUBLE:case u.FLOAT:if(e===null)return 0;if(e==="NaN")return Number.NaN;if(e==="Infinity")return Number.POSITIVE_INFINITY;if(e==="-Infinity")return Number.NEGATIVE_INFINITY;if(e===""){s="empty string";break}if(typeof e=="string"&&e.trim().length!==e.length){s="extra whitespace";break}if(typeof e!="string"&&typeof e!="number")break;let o=Number(e);if(Number.isNaN(o)){s="not a number";break}if(!Number.isFinite(o)){s="too large or small";break}return t==u.FLOAT&&Ze(o),o;case u.INT32:case u.FIXED32:case u.SFIXED32:case u.SINT32:case u.UINT32:if(e===null)return 0;let a;if(typeof e=="number"?a=e:e===""?s="empty string":typeof e=="string"&&(e.trim().length!==e.length?s="extra whitespace":a=Number(e)),a===void 0)break;return t==u.UINT32?Ce(a):me(a),a;case u.INT64:case u.SFIXED64:case u.SINT64:if(e===null)return U(M.ZERO,i);if(typeof e!="number"&&typeof e!="string")break;return U(M.from(e),i);case u.FIXED64:case u.UINT64:if(e===null)return U(B.ZERO,i);if(typeof e!="number"&&typeof e!="string")break;return U(B.from(e),i);case u.BOOL:if(e===null)return!1;if(typeof e!="boolean")break;return e;case u.STRING:if(e===null)return"";if(typeof e!="string"){s="extra whitespace";break}try{encodeURIComponent(e)}catch(f){f="invalid UTF8";break}return e;case u.BYTES:if(e===null||e==="")return new Uint8Array(0);if(typeof e!="string")break;return In(e)}}catch(o){s=o.message}this.assert(!1,r+(s?" - "+s:""),e)}}class Wn{constructor(e){var t;this.fields=(t=e.fields)!==null&&t!==void 0?t:[]}write(e,t){const i={},r=e;for(const s of this.fields){if(!s.oneof){let h=this.field(s,r[s.localName],t);h!==void 0&&(i[t.useProtoFieldName?s.name:s.jsonName]=h);continue}const o=r[s.oneof];if(o.oneofKind!==s.localName)continue;const a=s.kind=="scalar"||s.kind=="enum"?Object.assign(Object.assign({},t),{emitDefaultValues:!0}):t;let f=this.field(s,o[s.localName],a);m(f!==void 0),i[t.useProtoFieldName?s.name:s.jsonName]=f}return i}field(e,t,i){let r;if(e.kind=="map"){m(typeof t=="object"&&t!==null);const s={};switch(e.V.kind){case"scalar":for(const[f,h]of Object.entries(t)){const d=this.scalar(e.V.T,h,e.name,!1,!0);m(d!==void 0),s[f.toString()]=d}break;case"message":const o=e.V.T();for(const[f,h]of Object.entries(t)){const d=this.message(o,h,e.name,i);m(d!==void 0),s[f.toString()]=d}break;case"enum":const a=e.V.T();for(const[f,h]of Object.entries(t)){m(h===void 0||typeof h=="number");const d=this.enum(a,h,e.name,!1,!0,i.enumAsInteger);m(d!==void 0),s[f.toString()]=d}break}(i.emitDefaultValues||Object.keys(s).length>0)&&(r=s)}else if(e.repeat){m(Array.isArray(t));const s=[];switch(e.kind){case"scalar":for(let f=0;f<t.length;f++){const h=this.scalar(e.T,t[f],e.name,e.opt,!0);m(h!==void 0),s.push(h)}break;case"enum":const o=e.T();for(let f=0;f<t.length;f++){m(t[f]===void 0||typeof t[f]=="number");const h=this.enum(o,t[f],e.name,e.opt,!0,i.enumAsInteger);m(h!==void 0),s.push(h)}break;case"message":const a=e.T();for(let f=0;f<t.length;f++){const h=this.message(a,t[f],e.name,i);m(h!==void 0),s.push(h)}break}(i.emitDefaultValues||s.length>0||i.emitDefaultValues)&&(r=s)}else switch(e.kind){case"scalar":r=this.scalar(e.T,t,e.name,e.opt,i.emitDefaultValues);break;case"enum":r=this.enum(e.T(),t,e.name,e.opt,i.emitDefaultValues,i.enumAsInteger);break;case"message":r=this.message(e.T(),t,e.name,i);break}return r}enum(e,t,i,r,s,o){if(e[0]=="google.protobuf.NullValue")return!s&&!r?void 0:null;if(t===void 0){m(r);return}if(!(t===0&&!s&&!r))return m(typeof t=="number"),m(Number.isInteger(t)),o||!e[1].hasOwnProperty(t)?t:e[2]?e[2]+e[1][t]:e[1][t]}message(e,t,i,r){return t===void 0?r.emitDefaultValues?null:void 0:e.internalJsonWrite(t,r)}scalar(e,t,i,r,s){if(t===void 0){m(r);return}const o=s||r;switch(e){case u.INT32:case u.SFIXED32:case u.SINT32:return t===0?o?0:void 0:(me(t),t);case u.FIXED32:case u.UINT32:return t===0?o?0:void 0:(Ce(t),t);case u.FLOAT:Ze(t);case u.DOUBLE:return t===0?o?0:void 0:(m(typeof t=="number"),Number.isNaN(t)?"NaN":t===Number.POSITIVE_INFINITY?"Infinity":t===Number.NEGATIVE_INFINITY?"-Infinity":t);case u.STRING:return t===""?o?"":void 0:(m(typeof t=="string"),t);case u.BOOL:return t===!1?o?!1:void 0:(m(typeof t=="boolean"),t);case u.UINT64:case u.FIXED64:m(typeof t=="number"||typeof t=="string"||typeof t=="bigint");let a=B.from(t);return a.isZero()&&!o?void 0:a.toString();case u.INT64:case u.SFIXED64:case u.SINT64:m(typeof t=="number"||typeof t=="string"||typeof t=="bigint");let f=M.from(t);return f.isZero()&&!o?void 0:f.toString();case u.BYTES:return m(t instanceof Uint8Array),t.byteLength?Nn(t):o?"":void 0}}}function Ye(n,e=W.STRING){switch(n){case u.BOOL:return!1;case u.UINT64:case u.FIXED64:return U(B.ZERO,e);case u.INT64:case u.SFIXED64:case u.SINT64:return U(M.ZERO,e);case u.DOUBLE:case u.FLOAT:return 0;case u.BYTES:return new Uint8Array(0);case u.STRING:return"";default:return 0}}class $n{constructor(e){this.info=e}prepare(){var e;if(!this.fieldNoToField){const t=(e=this.info.fields)!==null&&e!==void 0?e:[];this.fieldNoToField=new Map(t.map(i=>[i.no,i]))}}read(e,t,i,r){this.prepare();const s=r===void 0?e.len:e.pos+r;for(;e.pos<s;){const[o,a]=e.tag(),f=this.fieldNoToField.get(o);if(!f){let g=i.readUnknownField;if(g=="throw")throw new Error(`Unknown field ${o} (wire type ${a}) for ${this.info.typeName}`);let _=e.skip(a);g!==!1&&(g===!0?Oe.onRead:g)(this.info.typeName,t,o,a,_);continue}let h=t,d=f.repeat,T=f.localName;switch(f.oneof&&(h=h[f.oneof],h.oneofKind!==T&&(h=t[f.oneof]={oneofKind:T})),f.kind){case"scalar":case"enum":let g=f.kind=="enum"?u.INT32:f.T,_=f.kind=="scalar"?f.L:void 0;if(d){let re=h[T];if(a==C.LengthDelimited&&g!=u.STRING&&g!=u.BYTES){let de=e.uint32()+e.pos;for(;e.pos<de;)re.push(this.scalar(e,g,_))}else re.push(this.scalar(e,g,_))}else h[T]=this.scalar(e,g,_);break;case"message":if(d){let re=h[T],de=f.T().internalBinaryRead(e,e.uint32(),i);re.push(de)}else h[T]=f.T().internalBinaryRead(e,e.uint32(),i,h[T]);break;case"map":let[V,Je]=this.mapEntry(f,e,i);h[T][V]=Je;break}}}mapEntry(e,t,i){let r=t.uint32(),s=t.pos+r,o,a;for(;t.pos<s;){let[f,h]=t.tag();switch(f){case 1:e.K==u.BOOL?o=t.bool().toString():o=this.scalar(t,e.K,W.STRING);break;case 2:switch(e.V.kind){case"scalar":a=this.scalar(t,e.V.T,e.V.L);break;case"enum":a=t.int32();break;case"message":a=e.V.T().internalBinaryRead(t,t.uint32(),i);break}break;default:throw new Error(`Unknown field ${f} (wire type ${h}) in map entry for ${this.info.typeName}#${e.name}`)}}if(o===void 0){let f=Ye(e.K);o=e.K==u.BOOL?f.toString():f}if(a===void 0)switch(e.V.kind){case"scalar":a=Ye(e.V.T,e.V.L);break;case"enum":a=0;break;case"message":a=e.V.T().create();break}return[o,a]}scalar(e,t,i){switch(t){case u.INT32:return e.int32();case u.STRING:return e.string();case u.BOOL:return e.bool();case u.DOUBLE:return e.double();case u.FLOAT:return e.float();case u.INT64:return U(e.int64(),i);case u.UINT64:return U(e.uint64(),i);case u.FIXED64:return U(e.fixed64(),i);case u.FIXED32:return e.fixed32();case u.BYTES:return e.bytes();case u.UINT32:return e.uint32();case u.SFIXED32:return e.sfixed32();case u.SFIXED64:return U(e.sfixed64(),i);case u.SINT32:return e.sint32();case u.SINT64:return U(e.sint64(),i)}}}class jn{constructor(e){this.info=e}prepare(){if(!this.fields){const e=this.info.fields?this.info.fields.concat():[];this.fields=e.sort((t,i)=>t.no-i.no)}}write(e,t,i){this.prepare();for(const s of this.fields){let o,a,f=s.repeat,h=s.localName;if(s.oneof){const d=e[s.oneof];if(d.oneofKind!==h)continue;o=d[h],a=!0}else o=e[h],a=!1;switch(s.kind){case"scalar":case"enum":let d=s.kind=="enum"?u.INT32:s.T;if(f)if(m(Array.isArray(o)),f==Me.PACKED)this.packed(t,d,s.no,o);else for(const T of o)this.scalar(t,d,s.no,T,!0);else o===void 0?m(s.opt):this.scalar(t,d,s.no,o,a||s.opt);break;case"message":if(f){m(Array.isArray(o));for(const T of o)this.message(t,i,s.T(),s.no,T)}else this.message(t,i,s.T(),s.no,o);break;case"map":m(typeof o=="object"&&o!==null);for(const[T,g]of Object.entries(o))this.mapEntry(t,i,s,T,g);break}}let r=i.writeUnknownFields;r!==!1&&(r===!0?Oe.onWrite:r)(this.info.typeName,e,t)}mapEntry(e,t,i,r,s){e.tag(i.no,C.LengthDelimited),e.fork();let o=r;switch(i.K){case u.INT32:case u.FIXED32:case u.UINT32:case u.SFIXED32:case u.SINT32:o=Number.parseInt(r);break;case u.BOOL:m(r=="true"||r=="false"),o=r=="true";break}switch(this.scalar(e,i.K,1,o,!0),i.V.kind){case"scalar":this.scalar(e,i.V.T,2,s,!0);break;case"enum":this.scalar(e,u.INT32,2,s,!0);break;case"message":this.message(e,t,i.V.T(),2,s);break}e.join()}message(e,t,i,r,s){s!==void 0&&(i.internalBinaryWrite(s,e.tag(r,C.LengthDelimited).fork(),t),e.join())}scalar(e,t,i,r,s){let[o,a,f]=this.scalarInfo(t,r);(!f||s)&&(e.tag(i,o),e[a](r))}packed(e,t,i,r){if(!r.length)return;m(t!==u.BYTES&&t!==u.STRING),e.tag(i,C.LengthDelimited),e.fork();let[,s]=this.scalarInfo(t);for(let o=0;o<r.length;o++)e[s](r[o]);e.join()}scalarInfo(e,t){let i=C.Varint,r,s=t===void 0,o=t===0;switch(e){case u.INT32:r="int32";break;case u.STRING:o=s||!t.length,i=C.LengthDelimited,r="string";break;case u.BOOL:o=t===!1,r="bool";break;case u.UINT32:r="uint32";break;case u.DOUBLE:i=C.Bit64,r="double";break;case u.FLOAT:i=C.Bit32,r="float";break;case u.INT64:o=s||M.from(t).isZero(),r="int64";break;case u.UINT64:o=s||B.from(t).isZero(),r="uint64";break;case u.FIXED64:o=s||B.from(t).isZero(),i=C.Bit64,r="fixed64";break;case u.BYTES:o=s||!t.byteLength,i=C.LengthDelimited,r="bytes";break;case u.FIXED32:i=C.Bit32,r="fixed32";break;case u.SFIXED32:i=C.Bit32,r="sfixed32";break;case u.SFIXED64:o=s||M.from(t).isZero(),i=C.Bit64,r="sfixed64";break;case u.SINT32:r="sint32";break;case u.SINT64:o=s||M.from(t).isZero(),r="sint64";break}return[i,r,s||o]}}function Jn(n){const e=n.messagePrototype?Object.create(n.messagePrototype):Object.defineProperty({},Rt,{value:n});for(let t of n.fields){let i=t.localName;if(!t.opt)if(t.oneof)e[t.oneof]={oneofKind:void 0};else if(t.repeat)e[i]=[];else switch(t.kind){case"scalar":e[i]=Ye(t.T,t.L);break;case"enum":e[i]=0;break;case"map":e[i]={};break}}return e}function qe(n,e,t){let i,r=t,s;for(let o of n.fields){let a=o.localName;if(o.oneof){const f=r[o.oneof];if((f==null?void 0:f.oneofKind)==null)continue;if(i=f[a],s=e[o.oneof],s.oneofKind=f.oneofKind,i==null){delete s[a];continue}}else if(i=r[a],s=e,i==null)continue;switch(o.repeat&&(s[a].length=i.length),o.kind){case"scalar":case"enum":if(o.repeat)for(let h=0;h<i.length;h++)s[a][h]=i[h];else s[a]=i;break;case"message":let f=o.T();if(o.repeat)for(let h=0;h<i.length;h++)s[a][h]=f.create(i[h]);else s[a]===void 0?s[a]=f.create(i):f.mergePartial(s[a],i);break;case"map":switch(o.V.kind){case"scalar":case"enum":Object.assign(s[a],i);break;case"message":let h=o.V.T();for(let d of Object.keys(i))s[a][d]=h.create(i[d]);break}break}}}function Xn(n,e,t){if(e===t)return!0;if(!e||!t)return!1;for(let i of n.fields){let r=i.localName,s=i.oneof?e[i.oneof][r]:e[r],o=i.oneof?t[i.oneof][r]:t[r];switch(i.kind){case"enum":case"scalar":let a=i.kind=="enum"?u.INT32:i.T;if(!(i.repeat?St(a,s,o):Lt(a,s,o)))return!1;break;case"map":if(!(i.V.kind=="message"?Ft(i.V.T(),Ae(s),Ae(o)):St(i.V.kind=="enum"?u.INT32:i.V.T,Ae(s),Ae(o))))return!1;break;case"message":let f=i.T();if(!(i.repeat?Ft(f,s,o):f.equals(s,o)))return!1;break}}return!0}const Ae=Object.values;function Lt(n,e,t){if(e===t)return!0;if(n!==u.BYTES)return!1;let i=e,r=t;if(i.length!==r.length)return!1;for(let s=0;s<i.length;s++)if(i[s]!=r[s])return!1;return!0}function St(n,e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!Lt(n,e[i],t[i]))return!1;return!0}function Ft(n,e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!n.equals(e[i],t[i]))return!1;return!0}const Ct=Object.getOwnPropertyDescriptors(Object.getPrototypeOf({})),Gn=Ct[Rt]={};class Zn{constructor(e,t,i){this.defaultCheckDepth=16,this.typeName=e,this.fields=t.map(Kn),this.options=i!=null?i:{},Gn.value=this,this.messagePrototype=Object.create(null,Ct),this.refTypeCheck=new Un(this),this.refJsonReader=new Pn(this),this.refJsonWriter=new Wn(this),this.refBinReader=new $n(this),this.refBinWriter=new jn(this)}create(e){let t=Jn(this);return e!==void 0&&qe(this,t,e),t}clone(e){let t=this.create();return qe(this,t,e),t}equals(e,t){return Xn(this,e,t)}is(e,t=this.defaultCheckDepth){return this.refTypeCheck.is(e,t,!1)}isAssignable(e,t=this.defaultCheckDepth){return this.refTypeCheck.is(e,t,!0)}mergePartial(e,t){qe(this,e,t)}fromBinary(e,t){let i=On(t);return this.internalBinaryRead(i.readerFactory(e),e.byteLength,i)}fromJson(e,t){return this.internalJsonRead(e,_n(t))}fromJsonString(e,t){let i=JSON.parse(e);return this.fromJson(i,t)}toJson(e,t){return this.internalJsonWrite(e,xn(t))}toJsonString(e,t){var i;let r=this.toJson(e,t);return JSON.stringify(r,null,(i=t==null?void 0:t.prettySpaces)!==null&&i!==void 0?i:0)}toBinary(e,t){let i=Dn(t);return this.internalBinaryWrite(e,i.writerFactory(),i).finish()}internalJsonRead(e,t,i){if(e!==null&&typeof e=="object"&&!Array.isArray(e)){let r=i!=null?i:this.create();return this.refJsonReader.read(e,r,t),r}throw new Error(`Unable to parse message ${this.typeName} from JSON ${pt(e)}.`)}internalJsonWrite(e,t){return this.refJsonWriter.write(e,t)}internalBinaryWrite(e,t,i){return this.refBinWriter.write(e,t,i),t}internalBinaryRead(e,t,i,r){let s=r!=null?r:this.create();return this.refBinReader.read(e,s,i,t),s}}var Yn=Object.defineProperty,qn=(n,e,t)=>e in n?Yn(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,zn=(n,e,t)=>(qn(n,typeof e!="symbol"?e+"":e,t),t),ze=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)},c=(n,e,t)=>(ze(n,e,"read from private field"),t?t.call(n):e.get(n)),y=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},p=(n,e,t,i)=>(ze(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t),w=(n,e,t)=>(ze(n,e,"access private method"),t),De={},Qn={get exports(){return De},set exports(n){De=n}},se=typeof Reflect=="object"?Reflect:null,Mt=se&&typeof se.apply=="function"?se.apply:function(n,e,t){return Function.prototype.apply.call(n,e,t)},Be;se&&typeof se.ownKeys=="function"?Be=se.ownKeys:Object.getOwnPropertySymbols?Be=function(n){return Object.getOwnPropertyNames(n).concat(Object.getOwnPropertySymbols(n))}:Be=function(n){return Object.getOwnPropertyNames(n)};function Hn(n){console&&console.warn&&console.warn(n)}var At=Number.isNaN||function(n){return n!==n};function v(){v.init.call(this)}Qn.exports=v,De.once=ii,v.EventEmitter=v,v.prototype._events=void 0,v.prototype._eventsCount=0,v.prototype._maxListeners=void 0;var Dt=10;function _e(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(v,"defaultMaxListeners",{enumerable:!0,get:function(){return Dt},set:function(n){if(typeof n!="number"||n<0||At(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");Dt=n}}),v.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},v.prototype.setMaxListeners=function(n){if(typeof n!="number"||n<0||At(n))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+n+".");return this._maxListeners=n,this};function Bt(n){return n._maxListeners===void 0?v.defaultMaxListeners:n._maxListeners}v.prototype.getMaxListeners=function(){return Bt(this)},v.prototype.emit=function(n){for(var e=[],t=1;t<arguments.length;t++)e.push(arguments[t]);var i=n==="error",r=this._events;if(r!==void 0)i=i&&r.error===void 0;else if(!i)return!1;if(i){var s;if(e.length>0&&(s=e[0]),s instanceof Error)throw s;var o=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw o.context=s,o}var a=r[n];if(a===void 0)return!1;if(typeof a=="function")Mt(a,this,e);else for(var f=a.length,h=Ut(a,f),t=0;t<f;++t)Mt(h[t],this,e);return!0};function _t(n,e,t,i){var r,s,o;if(_e(t),s=n._events,s===void 0?(s=n._events=Object.create(null),n._eventsCount=0):(s.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),s=n._events),o=s[e]),o===void 0)o=s[e]=t,++n._eventsCount;else if(typeof o=="function"?o=s[e]=i?[t,o]:[o,t]:i?o.unshift(t):o.push(t),r=Bt(n),r>0&&o.length>r&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=o.length,Hn(a)}return n}v.prototype.addListener=function(n,e){return _t(this,n,e,!1)},v.prototype.on=v.prototype.addListener,v.prototype.prependListener=function(n,e){return _t(this,n,e,!0)};function ei(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function xt(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},r=ei.bind(i);return r.listener=t,i.wrapFn=r,r}v.prototype.once=function(n,e){return _e(e),this.on(n,xt(this,n,e)),this},v.prototype.prependOnceListener=function(n,e){return _e(e),this.prependListener(n,xt(this,n,e)),this},v.prototype.removeListener=function(n,e){var t,i,r,s,o;if(_e(e),i=this._events,i===void 0)return this;if(t=i[n],t===void 0)return this;if(t===e||t.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete i[n],i.removeListener&&this.emit("removeListener",n,t.listener||e));else if(typeof t!="function"){for(r=-1,s=t.length-1;s>=0;s--)if(t[s]===e||t[s].listener===e){o=t[s].listener,r=s;break}if(r<0)return this;r===0?t.shift():ti(t,r),t.length===1&&(i[n]=t[0]),i.removeListener!==void 0&&this.emit("removeListener",n,o||e)}return this},v.prototype.off=v.prototype.removeListener,v.prototype.removeAllListeners=function(n){var e,t,i;if(t=this._events,t===void 0)return this;if(t.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):t[n]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete t[n]),this;if(arguments.length===0){var r=Object.keys(t),s;for(i=0;i<r.length;++i)s=r[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=t[n],typeof e=="function")this.removeListener(n,e);else if(e!==void 0)for(i=e.length-1;i>=0;i--)this.removeListener(n,e[i]);return this};function Kt(n,e,t){var i=n._events;if(i===void 0)return[];var r=i[e];return r===void 0?[]:typeof r=="function"?t?[r.listener||r]:[r]:t?ni(r):Ut(r,r.length)}v.prototype.listeners=function(n){return Kt(this,n,!0)},v.prototype.rawListeners=function(n){return Kt(this,n,!1)},v.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):Vt.call(n,e)},v.prototype.listenerCount=Vt;function Vt(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}v.prototype.eventNames=function(){return this._eventsCount>0?Be(this._events):[]};function Ut(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function ti(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function ni(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function ii(n,e){return new Promise(function(t,i){function r(o){n.removeListener(e,s),i(o)}function s(){typeof n.removeListener=="function"&&n.removeListener("error",r),t([].slice.call(arguments))}Pt(n,e,s,{once:!0}),e!=="error"&&ri(n,r,{once:!0})})}function ri(n,e,t){typeof n.on=="function"&&Pt(n,"error",e,t)}function Pt(n,e,t,i){if(typeof n.on=="function")i.once?n.once(e,t):n.on(e,t);else if(typeof n.addEventListener=="function")n.addEventListener(e,function r(s){i.once&&n.removeEventListener(e,r),t(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}class si extends Zn{constructor(){super("message.v1.SocketMessage",[{no:1,name:"event",kind:"scalar",T:13},{no:2,name:"id",kind:"scalar",opt:!0,T:9},{no:3,name:"payload",kind:"scalar",opt:!0,T:12},{no:4,name:"metadata",kind:"scalar",opt:!0,T:12}])}}const Wt=new si;class $t{static encode(e){return Wt.toBinary(e)}static decode(e){return Wt.fromBinary(new Uint8Array(e))}}function oi(n,e){return Math.floor(Math.random()*(e-n+1)+n)}var G;class ai{constructor(e={}){zn(this,"opts"),y(this,G,void 0),this.opts={initialTimeout:e.initialTimeout||1e3,maxTimeout:e.maxTimeout||1e4,factor:e.factor||2},p(this,G,0)}async wait(){p(this,G,c(this,G)+1);const e=oi(0,Math.min(this.opts.maxTimeout,this.opts.initialTimeout*2**c(this,G)));await new Promise(t=>{setTimeout(t,e)})}getAttempts(){return c(this,G)}reset(){p(this,G,0)}}G=new WeakMap;const Z={debug:0,info:1,warn:2,error:3};var ee,te;class ci{constructor(e){y(this,ee,void 0),y(this,te,void 0),p(this,ee,console),p(this,te,e)}debug(...e){Z[c(this,te)]>Z.debug||c(this,ee).debug("[Sockrates]:",...e)}info(...e){Z[c(this,te)]>Z.info||c(this,ee).info("[Sockrates]:",...e)}warn(...e){Z[c(this,te)]>Z.warn||c(this,ee).warn("[Sockrates]:",...e)}error(...e){Z[c(this,te)]>Z.error||c(this,ee).error("[Sockrates]:",...e)}}ee=new WeakMap,te=new WeakMap;var jt=(n=>(n[n.CONNECTING=0]="CONNECTING",n[n.OPEN=1]="OPEN",n[n.CLOSING=2]="CLOSING",n[n.CLOSED=3]="CLOSED",n))(jt||{});const Jt="2",Xt="3";var S,oe,k,L,Y,A,J,q,P,ae,ce,X,Qe,Gt,pe,xe,He,Zt,Ke,et,Ve,tt,nt,Yt,we,Ue,ue,be,Pe,it,fe,ye,rt,qt,ve,We,ke,$e;class ui{constructor(e,t){var V,Je,re,de,zt,Qt,Ht,en,tn,nn,rn,sn;y(this,Qe),y(this,pe),y(this,He),y(this,Ke),y(this,Ve),y(this,nt),y(this,we),y(this,ue),y(this,Pe),y(this,fe),y(this,rt),y(this,ve),y(this,ke),y(this,S,void 0),y(this,oe,void 0),y(this,k,void 0),y(this,L,void 0),y(this,Y,void 0),y(this,A,void 0),y(this,J,void 0),y(this,q,void 0),y(this,P,void 0),y(this,ae,void 0),y(this,ce,void 0),y(this,X,void 0);var i,r,s,o,a,f,h,d,T,g,_;p(this,oe,e),p(this,Y,[]),p(this,A,new De),p(this,J,!0),p(this,P,!1),p(this,k,t!=null?t:{}),(V=(i=c(this,k)).autoReconnect)!=null||(i.autoReconnect=!0),(Je=(r=c(this,k)).retryConnectionInterval)!=null||(r.retryConnectionInterval=1e3),(re=(s=c(this,k)).pingTimeout)!=null||(s.pingTimeout=3e4),(de=(o=c(this,k)).connectionTimeout)!=null||(o.connectionTimeout=5e3),(zt=(a=c(this,k)).debug)!=null||(a.debug=!0),(Qt=(f=c(this,k)).maxReconnectionAttempts)!=null||(f.maxReconnectionAttempts=10),(Ht=(h=c(this,k)).disconnectOnPingTimeout)!=null||(h.disconnectOnPingTimeout=!0),(en=(d=c(this,k)).queueOnDisconnect)!=null||(d.queueOnDisconnect=!1),(tn=(T=c(this,k)).flushOnReconnect)!=null||(T.flushOnReconnect=!1),(nn=(g=c(this,k)).clientInitiatedPings)!=null||(g.clientInitiatedPings=!1),(rn=(_=c(this,k)).clientInitiatedPingInterval)!=null||(_.clientInitiatedPingInterval=3e4),p(this,q,{code:void 0,reason:void 0}),p(this,L,(sn=c(this,k).logger)!=null?sn:new ci(c(this,k).debug?"debug":"info")),p(this,X,new ai)}get readyState(){var e;return(e=c(this,S))==null?void 0:e.readyState}get url(){return c(this,oe)}updateURL(e){p(this,oe,e),w(this,nt,Yt).call(this)}get config(){return c(this,k)}get sendQueue(){return c(this,Y)}flush(){if(!c(this,k).queueOnDisconnect)return!1;const e=[];return c(this,Y).forEach(t=>{this.send(t.event,t.id,t.payload,t.metadata)||e.push(t)}),p(this,Y,e),c(this,Y)}async connect(e=!1){if(!e&&[0,1].includes(this.readyState)){c(this,L).debug("Websocket was already connecting or connected.");return}if(c(this,J)!==!1)return new Promise((t,i)=>{w(this,fe,ye).call(this),w(this,ke,$e).call(this);try{p(this,S,new WebSocket(w(this,Qe,Gt).call(this,c(this,oe)))),c(this,S).binaryType="arraybuffer",c(this,L).debug("Connecting");const r=setTimeout(()=>{c(this,L).debug("Connection timeout. Closing socket"),p(this,J,!0),w(this,ke,$e).call(this),c(this,S).close(3001,"Connection Timeout"),c(this,k).autoReconnect&&!c(this,P)&&(c(this,A).emit("reconnecting"),w(this,we,Ue).call(this)),i(new Error("Connection timed out!"))},c(this,k).connectionTimeout);c(this,S).onopen=()=>{c(this,L).debug(`Ready State: ${jt[c(this,S).readyState]}`),r&&clearTimeout(r),w(this,Pe,it).call(this),w(this,rt,qt).call(this),p(this,q,{code:void 0,reason:void 0}),c(this,A).emit("connected"),c(this,k).flushOnReconnect&&this.flush(),t()},c(this,S).onclose=s=>{try{r&&clearTimeout(r);const{code:o,reason:a}=s;i(a),c(this,L).debug("Socket closed. Close event:",{event:s}),c(this,L).debug(`Connection closed code: ${o}`),c(this,L).debug(`Connection closed reason: ${a}`),c(this,P)||w(this,Ve,tt).call(this,o,a)}catch(o){w(this,pe,xe).call(this,o)}},c(this,S).onerror=s=>{w(this,pe,xe).call(this,s)},c(this,S).onmessage=s=>w(this,He,Zt).call(this,s)}catch(r){w(this,pe,xe).call(this,r,i)}})}send(e,t,i,r){const s={event:e,id:t,payload:i,metadata:r};if(c(this,k).queueOnDisconnect&&(!c(this,S)||c(this,S).readyState!==1))return c(this,L).debug("Queuing message since socket is not connected!",s),c(this,Y).push(s),!1;const o=$t.encode(s);return w(this,ue,be).call(this,o)}emit(e,t,i,r){return this.send(e,t,i,r)}sendRaw(e){return w(this,ue,be).call(this,e)}receive(e,t){return c(this,A).on(e.toString(),t)}on(e,t){if(typeof e=="string"&&(e==="connected"||e==="disconnected"||e==="errored"||e==="reconnected"||e==="reconnecting"||e==="reconnectAttempt"||e==="reconnectFailure"||e==="failed")){c(this,A).on(e,t);return}this.receive(e,t)}removeAllListeners(){c(this,A).removeAllListeners()}removeReceiver(e,t){this.removeListener(e,t)}removeListener(e,t){c(this,A).removeListener(e.toString(),t)}removeReceivers(e){this.removeListeners(e)}removeListeners(e){c(this,A).listeners(e.toString()).map(t=>this.removeListener(e,t))}disconnect(){p(this,J,!1),w(this,fe,ye).call(this),w(this,ve,We).call(this),this.removeAllListeners(),p(this,q,{code:1e3,reason:"Sockrates disconnect method called"}),c(this,S).close(1e3,"Sockrates disconnect method called.")}}S=new WeakMap,oe=new WeakMap,k=new WeakMap,L=new WeakMap,Y=new WeakMap,A=new WeakMap,J=new WeakMap,q=new WeakMap,P=new WeakMap,ae=new WeakMap,ce=new WeakMap,X=new WeakMap,Qe=new WeakSet,Gt=function(n){if(n.startsWith("ws://")||n.startsWith("wss://"))return n;if(n.startsWith("https://"))return`wss://${n.substring(8)}`;if(n.startsWith("http://"))return`ws://${n.substring(7)}`;throw new Error("Invalid URL. URL must start with http(s):// or ws(s)://.")},pe=new WeakSet,xe=function(n,e){c(this,L).error("Error:",{error:n}),c(this,A).emit("errored",{error:n}),e==null||e(n)},He=new WeakSet,Zt=function(n){if(w(this,Pe,it).call(this),n.data===Jt){c(this,L).debug("Received ping from server"),w(this,ue,be).call(this,Xt);return}if(n.data===Xt){c(this,L).debug("Received pong from server");return}const e=$t.decode(n.data),{id:t,payload:i}=e;c(this,L).debug("Received message",{event:e.event,messageID:t}),c(this,A).emit(e.event.toString(),{id:t,payload:i})},Ke=new WeakSet,et=function(){return c(this,S).readyState===1},Ve=new WeakSet,tt=function(n,e){p(this,q,{reason:e,code:n}),c(this,A).emit("disconnected",{code:n,reason:e})},nt=new WeakSet,Yt=function(){const{reason:n,code:e}=c(this,q);e&&e!==1e3&&c(this,J)&&c(this,k).autoReconnect&&!c(this,P)&&(c(this,L).debug(`Triggering reconnection due to ${n}.`),c(this,A).emit("reconnecting"),w(this,we,Ue).call(this))},we=new WeakSet,Ue=async function(n=!0){if(n&&c(this,P)){c(this,L).debug("Reconnect called when already in a reconnect loop. Ignoring.");return}if(c(this,P)||c(this,X).reset(),c(this,k).maxReconnectionAttempts!==null&&c(this,X).getAttempts()>=c(this,k).maxReconnectionAttempts){c(this,A).emit("failed"),p(this,P,!1);return}p(this,P,!0),w(this,ke,$e).call(this),w(this,fe,ye).call(this);try{if(await c(this,X).wait(),c(this,J)===!1)return;if(c(this,L).debug(`Reconnection attempt ${c(this,X).getAttempts()}`),c(this,A).emit("reconnectAttempt",{attempt:c(this,X).getAttempts()}),await this.connect(),!w(this,Ke,et).call(this))throw Error("Reconnect Failed");p(this,P,!1),p(this,q,{code:void 0,reason:void 0}),c(this,A).emit("reconnected")}catch(e){c(this,L).debug("Failed to reconnect."),c(this,A).emit("reconnectFailure",{attempt:c(this,X).getAttempts()}),w(this,we,Ue).call(this,!1)}},ue=new WeakSet,be=function(n){try{return c(this,S).send(n),!0}catch(e){return c(this,L).error(e.message),!1}},Pe=new WeakSet,it=function(){this.config.disconnectOnPingTimeout&&(c(this,L).debug("Resetting ping timeout"),w(this,fe,ye).call(this),p(this,ae,setTimeout(()=>{var n;c(this,L).debug("Disconnecting the socket due to ping timeout"),p(this,J,!0);const e=3002,t="Ping timeout";(n=c(this,S))==null||n.close(e,t),w(this,Ve,tt).call(this,e,t)},c(this,k).pingTimeout)))},fe=new WeakSet,ye=function(){c(this,ae)&&(clearTimeout(c(this,ae)),p(this,ae,void 0))},rt=new WeakSet,qt=function(){w(this,ve,We).call(this),c(this,k).clientInitiatedPings&&p(this,ce,setInterval(()=>{w(this,Ke,et).call(this)&&(c(this,L).debug("Sending client-initiated ping"),w(this,ue,be).call(this,Jt))},c(this,k).clientInitiatedPingInterval))},ve=new WeakSet,We=function(){c(this,ce)&&(clearInterval(c(this,ce)),p(this,ce,void 0))},ke=new WeakSet,$e=function(){w(this,ve,We).call(this),c(this,S)&&(c(this,S).onopen=void 0,c(this,S).onerror=void 0,c(this,S).onmessage=void 0,c(this,S).onclose=void 0)};class fi{constructor(e,t){this.url=e,console.info(`Creating websocket with url: ${e} and config: ${t}`)}sendRaw(e){return console.info(`Sending raw message to websocket: ${e}`),!0}connect(e){return console.info(`Connecting to websocket: ${this.url} with force: ${e}`),Promise.resolve()}disconnect(){console.info(`Disconnecting from websocket: ${this.url}`)}on(e,t){console.info(`Adding listener to websocket: ${e} with listener: ${t}`)}}class hi{constructor(e,t=!1){x(this,Q,null);x(this,ie,!1);x(this,Ne,!1);this.wsUrl=e,this.devMode=t}get connected(){return l(this,ie)}async connect(e){let t;this.devMode?t=new fi(this.wsUrl,{queueOnDisconnect:!0,flushOnReconnect:!0}):t=new ui(this.wsUrl,{queueOnDisconnect:!0,flushOnReconnect:!0}),e.participants.addListener("broadcastedMessage",i=>t.sendRaw(JSON.stringify(i))),I.info("Connecting to websocket"),t.on("connected",()=>{I.info("Connected to websocket")}),await t.connect(!0),D(this,Q,t),D(this,ie,!0)}disconnect(){l(this,Q)&&(l(this,Q).disconnect(),D(this,ie,!1))}startRecordingMessage(){if(l(this,Ne))throw new Error("Start recording message already sent");if(l(this,Q)&&l(this,ie))D(this,Ne,!0),l(this,Q).sendRaw(JSON.stringify({type:"StartRecording"}));else throw new Error("Not connected to websocket, make sure you have called init.")}}Q=new WeakMap,ie=new WeakMap,Ne=new WeakMap;class li{constructor(){}checkIfSDKEnabled(){return I.info("Check if SDK enabled"),window.dyteRecordingSdk===!0||window.realtimeKitRecordingSdk===!0}checkIfRecordingTriggerAdded(){return I.info("Check if recording trigger added"),window.triggerDyteRecording===!0||window.triggerRealtimeKitRecording===!0}checkMeetingJoined(){var e;return I.info("Check if meeting joined getter available"),((e=window.realtimeKitRecording)==null?void 0:e.isMeetingJoined())!==!0}checkParticipantCount(){var e;return I.info("Check if participant count getter available"),((e=window.realtimeKitRecording)==null?void 0:e.getParticipantCount())!==void 0}pageLoadTests(){I.info("Running on page load tests");const e=[];if(this.checkIfSDKEnabled()||e.push("SDK not enabled"),e.length>0)throw new Error(e.join(", "))}sdkInitTests(){I.info("Running SDK init tests");const e=[];if(this.checkIfRecordingTriggerAdded()||e.push("Recording trigger not added"),this.checkParticipantCount()||e.push("Participant count getter not working"),e.length>0)throw new Error(e.join(`
|
|
3
|
+
`))}showAlert(e){I.error(e),e+="You can contact Dyte support for help",window.alert(e)}}class di{constructor(e){x(this,H,void 0);x(this,F,void 0);x(this,K,void 0);x(this,$,void 0);x(this,le,void 0);var t,i,r,s,o;e.waitTimeMs&&!e.autoStop&&I.warn("You have passed both waitTimeMs and autoStop. waitTimeMs will be ignored"),D(this,F,{waitTimeMs:(t=e.waitTimeMs)!=null?t:1*wn,websocketUrl:(i=e.websocketUrl)!=null?i:"ws://localhost:8080/ws",autoStart:(r=e.autoStart)!=null?r:!0,autoStop:(s=e.autoStop)!=null?s:!0,devMode:window.navigator.webdriver==!1,scanInterval:(o=e.scanInterval)!=null?o:bn}),window.dyteRecordingSdk=!0,window.realtimeKitRecordingSdk=!0,window.devMode=l(this,F).devMode,D(this,$,new li),this.performOnPageLoadChecks()}async init(e){I.info("Initializing RealtimeKit Recording SDK");const t=new yn(new vn(e),{autoStop:l(this,F).autoStop,waitTimeMs:l(this,F).waitTimeMs,scanInterval:l(this,F).scanInterval}),i=new hi(l(this,F).websocketUrl,l(this,F).devMode);await i.connect(e),D(this,K,i),D(this,H,t),this.sdkInitTests(),I.init(e),D(this,le,e),l(this,F).autoStart&&await this.startRecording()}async startRecording(){var e,t;if((e=l(this,le))!=null&&e.self.roomJoined){const i="Meeting already joined. Cannot start recording. SDK will call meeting.join() automatically.";if(I.warn(i),l(this,F).devMode)throw new Error(i)}if(await((t=l(this,le))==null?void 0:t.join()),I.info("Sending start recording request"),l(this,K))try{l(this,K).startRecordingMessage()}catch(i){const r=`Failed to start recording with error: ${i}`;if(I.error(r),l(this,F).devMode)throw new Error(r)}}stopRecording(){if(I.info("Stopping RealtimeKit Recording SDK"),l(this,H))l(this,H).stopRecording(),l(this,K)&&l(this,K).connected&&l(this,K).disconnect();else{const e="recording controller not initialized";if(I.error(e),l(this,F).devMode)throw new Error(e)}}async cleanup(){if(I.info("Cleaning up RealtimeKit Recording SDK"),delete window.devMode,delete window.realtimeKitRecordingSdk,delete window.dyteRecordingSdk,l(this,H))try{l(this,H).cleanup(),l(this,K)&&l(this,K).connected&&l(this,K).disconnect()}catch(e){const t=`Failed to cleanup with error: ${e}`;if(I.error(t),l(this,F).devMode)throw new Error(t)}else{const e="recording controller not initialized";if(I.error("recording controller not initialized"),l(this,F).devMode)throw new Error(e)}}performOnPageLoadChecks(){if(l(this,$))try{l(this,$).pageLoadTests()}catch(e){const t=`Failed to perform page load checks with error: ${e}`;if(typeof e=="string"&&l(this,F).devMode&&l(this,$).showAlert(e),l(this,F).devMode)throw new Error(t)}else{const e="SDK Checks controller not initialized";if(l(this,F).devMode)throw new Error(e)}}sdkInitTests(){if(l(this,$))try{l(this,$).sdkInitTests()}catch(e){const t=`Failed to perform sdk init checks with error: ${e}`;if(typeof e=="string"&&l(this,F).devMode&&l(this,$).showAlert(e),l(this,F).devMode)throw new Error(t)}else{const e="SDK Checks controller not initialized";if(l(this,F).devMode)throw new Error(e)}}}return H=new WeakMap,F=new WeakMap,K=new WeakMap,$=new WeakMap,le=new WeakMap,R.RealtimeKitRecording=di,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"}),R}({});
|
package/package.json
CHANGED
|
@@ -1 +1,81 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloudflare/realtimekit-recording-sdk",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"main": "./dist/index.cjs.js",
|
|
5
|
+
"module": "./dist/index.es.js",
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.es.js",
|
|
10
|
+
"require": "./dist/index.cjs.js",
|
|
11
|
+
"types": "./types/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"types"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "vite",
|
|
20
|
+
"build": "tsc && vite build && VITE_IIFE=true vite build -c vite.iife.config.ts",
|
|
21
|
+
"preview": "vite preview",
|
|
22
|
+
"test": "jest --passWithNoTests",
|
|
23
|
+
"test:coverage": "jest --coverage --passWithNoTests",
|
|
24
|
+
"audit": "npm audit --production --audit-level=critical",
|
|
25
|
+
"lint": "eslint src --ext .ts",
|
|
26
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
27
|
+
"changeset": "changeset",
|
|
28
|
+
"release": "bash scripts/release.sh",
|
|
29
|
+
"prepare": "is-ci || husky"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@changesets/cli": "^2.29.8",
|
|
33
|
+
"@commitlint/cli": "^20.4.1",
|
|
34
|
+
"@commitlint/config-conventional": "^20.4.1",
|
|
35
|
+
"@types/cypress": "^1.1.3",
|
|
36
|
+
"@types/jest": "^29.5.11",
|
|
37
|
+
"@types/node": "^20.10.6",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
39
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
40
|
+
"commitizen": "^4.3.1",
|
|
41
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
42
|
+
"cypress": "^13.17.0",
|
|
43
|
+
"eslint": "^8.56.0",
|
|
44
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
45
|
+
"eslint-plugin-import": "^2.32.0",
|
|
46
|
+
"husky": "^9.1.7",
|
|
47
|
+
"is-ci": "^2.0.0",
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
|
+
"prettier": "^3.1.1",
|
|
50
|
+
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
51
|
+
"rollup-plugin-polyfill-node": "^0.12.0",
|
|
52
|
+
"ts-jest": "^29.1.1",
|
|
53
|
+
"ts-node": "^10.9.2",
|
|
54
|
+
"typescript": "~5.5.4",
|
|
55
|
+
"vite": "^4.3.0",
|
|
56
|
+
"vite-plugin-dts": "^2.3.0",
|
|
57
|
+
"@cloudflare/realtimekit": "2.0.0"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@cloudflare/realtimekit-sockrates": "0.2.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@cloudflare/realtimekit": "*"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"author": "Cloudflare",
|
|
69
|
+
"license": "Apache-2.0",
|
|
70
|
+
"homepage": "https://realtime.cloudflare.com",
|
|
71
|
+
"commitlint": {
|
|
72
|
+
"extends": [
|
|
73
|
+
"@commitlint/config-conventional"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
"config": {
|
|
77
|
+
"commitizen": {
|
|
78
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import RealtimeKitClient from
|
|
2
|
-
import { EventEmitter } from
|
|
3
|
-
import { RealtimeKitController } from
|
|
1
|
+
import RealtimeKitClient from '@cloudflare/realtimekit';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { RealtimeKitController } from './RealtimeKitController';
|
|
4
4
|
declare global {
|
|
5
5
|
interface Window {
|
|
6
6
|
triggerDyteRecording: boolean;
|
package/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as RealtimeKitRecording } from
|
|
1
|
+
export { default as RealtimeKitRecording } from './sdk';
|
package/types/sdk.d.ts
CHANGED
package/types/utils/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import RealtimeKitClient from
|
|
2
|
-
import type { LogData } from
|
|
1
|
+
import RealtimeKitClient from '@cloudflare/realtimekit';
|
|
2
|
+
import type { LogData } from '@cloudflare/realtimekit';
|
|
3
3
|
declare class RealtimeKitRecordingLogger {
|
|
4
4
|
private client;
|
|
5
5
|
private logToConsole;
|
package/types/utils/mock.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Listener, SockratesConfig, StateEvents } from
|
|
1
|
+
import { Listener, SockratesConfig, StateEvents } from '@cloudflare/realtimekit-sockrates/dist/types/Sockrates';
|
|
2
2
|
declare type Message = Uint8Array | string;
|
|
3
3
|
export default class SockratesMock {
|
|
4
4
|
private url;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare abstract class DyteController {
|
|
2
|
-
abstract getParticipantCount(): number;
|
|
3
|
-
abstract getWaitlistedCount(): number;
|
|
4
|
-
abstract handleParticipantJoin(handler: () => void): void;
|
|
5
|
-
abstract handleParticipantLeave(handler: () => void): void;
|
|
6
|
-
abstract handleMeetingJoined(handler: () => void): void;
|
|
7
|
-
abstract handleMeetingLeft(handler: ({ state }: {
|
|
8
|
-
state: any;
|
|
9
|
-
}) => void): void;
|
|
10
|
-
abstract removeAllListeners(): void;
|
|
11
|
-
abstract getMeeting(): DyteClient;
|
|
12
|
-
}
|
|
13
|
-
export declare class WebCoreController implements DyteController {
|
|
14
|
-
private meeting;
|
|
15
|
-
constructor(meeting: DyteClient);
|
|
16
|
-
getParticipantCount(): number;
|
|
17
|
-
getMeeting(): DyteClient;
|
|
18
|
-
getWaitlistedCount(): number;
|
|
19
|
-
handleMeetingJoined(handler: () => void): void;
|
|
20
|
-
handleMeetingLeft(handler: ({ state }: {
|
|
21
|
-
state: any;
|
|
22
|
-
}) => void): void;
|
|
23
|
-
handleParticipantJoin(handler: () => void): void;
|
|
24
|
-
handleParticipantLeave(handler: () => void): void;
|
|
25
|
-
removeAllListeners(): void;
|
|
26
|
-
}
|