@cloudflare/realtimekit-recording-sdk 0.0.0 → 0.0.1-staging.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/README.md +86 -0
- package/dist/index.cjs.js +3 -0
- package/dist/index.es.js +3116 -0
- package/dist/index.iife.js +3 -0
- package/package.json +1 -6
- package/types/controllers/DyteController.d.ts +26 -0
- package/types/controllers/RealtimeKitController.d.ts +27 -0
- package/types/controllers/RecordingController.d.ts +40 -0
- package/types/controllers/SDKChecksController.d.ts +10 -0
- package/types/controllers/WebsocketController.d.ts +11 -0
- package/types/index.d.ts +1 -0
- package/types/sdk.d.ts +53 -0
- package/types/utils/logger.d.ts +16 -0
- package/types/utils/mock.d.ts +11 -0
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!-- PROJECT LOGO -->
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://realtime.cloudflare.com">
|
|
4
|
+
<img src="https://docs.realtime.cloudflare.com/logo/cf.svg" alt="Logo" width="120" />
|
|
5
|
+
</a>
|
|
6
|
+
|
|
7
|
+
<h3 align="center">RealtimeKit Recording SDK by Cloudflare</h3>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
Cloudflare RealtimeKit recording SDK to make custom UIs for recordings.
|
|
11
|
+
<br />
|
|
12
|
+
<a href="https://docs.realtime.cloudflare.com/guides/capabilities/recording/create-record-app-using-sdks"><strong>Explore the docs »</strong></a>
|
|
13
|
+
<br />
|
|
14
|
+
<br />
|
|
15
|
+
·
|
|
16
|
+
<a href="https://dyte.io/contact">Report Bug</a>
|
|
17
|
+
·
|
|
18
|
+
<a href="https://dyte.io/contact">Request Feature</a>
|
|
19
|
+
</p>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<!-- TABLE OF CONTENTS -->
|
|
23
|
+
|
|
24
|
+
## Table of Contents
|
|
25
|
+
|
|
26
|
+
- [About the Project](#about-the-project)
|
|
27
|
+
- [Built With](#built-with)
|
|
28
|
+
- [Getting Started](#getting-started)
|
|
29
|
+
- [Prerequisites](#prerequisites)
|
|
30
|
+
- [Installation](#installation)
|
|
31
|
+
- [Usage](#usage)
|
|
32
|
+
- [Examples](#examples)
|
|
33
|
+
- [Contributing](#contributing)
|
|
34
|
+
- [License](#license)
|
|
35
|
+
|
|
36
|
+
<!-- ABOUT THE PROJECT -->
|
|
37
|
+
|
|
38
|
+
## About The Project
|
|
39
|
+
|
|
40
|
+
The `@cloudflare/realtimekit-recording-sdk` powers the business logic for custom recording UIs.
|
|
41
|
+
|
|
42
|
+
### Built With
|
|
43
|
+
|
|
44
|
+
This SDK is built using TypeScript.
|
|
45
|
+
|
|
46
|
+
<!-- GETTING STARTED -->
|
|
47
|
+
|
|
48
|
+
## Getting Started
|
|
49
|
+
|
|
50
|
+
Follow the steps below to install `@cloudflare/realtimekit-recording-sdk` in your project.
|
|
51
|
+
|
|
52
|
+
### Prerequisites
|
|
53
|
+
|
|
54
|
+
- [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) or [yarn](https://yarnpkg.com/getting-started/install)
|
|
55
|
+
|
|
56
|
+
### Installation
|
|
57
|
+
|
|
58
|
+
Install using NPM
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
npm install @cloudflare/realtimekit-recording-sdk
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
OR
|
|
65
|
+
|
|
66
|
+
Install using yarn
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
yarn add @cloudflare/realtimekit-recording-sdk
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
<!-- USAGE -->
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
To get a detailed description of how to use this library, check out the _[official documentation](https://docs.realtime.cloudflare.com/guides/capabilities/recording/create-record-app-using-sdks)_.
|
|
77
|
+
|
|
78
|
+
## Examples
|
|
79
|
+
|
|
80
|
+
You can find a sample implementation of the recording SDK in the [react-samples](https://github.com/dyte-io/recording-sdk-app-samples) directory.
|
|
81
|
+
|
|
82
|
+
<!--- LICENSE -->
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
All rights reserved. © Cloudflare Inc.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";var Xt=Object.defineProperty;var Gt=(n,e,t)=>e in n?Xt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Qe=(n,e,t)=>(Gt(n,typeof e!="symbol"?e+"":e,t),t),Ke=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var l=(n,e,t)=>(Ke(n,e,"read from private field"),t?t.call(n):e.get(n)),A=(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)},C=(n,e,t,i)=>(Ke(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t);var He=(n,e,t)=>(Ke(n,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Ye={exports:{}},ie=typeof Reflect=="object"?Reflect:null,et=ie&&typeof ie.apply=="function"?ie.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)},ye;ie&&typeof ie.ownKeys=="function"?ye=ie.ownKeys:Object.getOwnPropertySymbols?ye=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ye=function(e){return Object.getOwnPropertyNames(e)};function Zt(n){console&&console.warn&&console.warn(n)}var gt=Number.isNaN||function(e){return e!==e};function w(){w.init.call(this)}Ye.exports=w;Ye.exports.once=Qt;w.EventEmitter=w;w.prototype._events=void 0;w.prototype._eventsCount=0;w.prototype._maxListeners=void 0;var tt=10;function De(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 tt},set:function(n){if(typeof n!="number"||n<0||gt(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");tt=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||gt(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 mt(n){return n._maxListeners===void 0?w.defaultMaxListeners:n._maxListeners}w.prototype.getMaxListeners=function(){return mt(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")et(f,this,t);else for(var h=f.length,d=vt(f,h),i=0;i<h;++i)et(d[i],this,t);return!0};function pt(n,e,t,i){var r,s,o;if(De(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=mt(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 pt(this,e,t,!1)};w.prototype.on=w.prototype.addListener;w.prototype.prependListener=function(e,t){return pt(this,e,t,!0)};function Yt(){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 wt(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},r=Yt.bind(i);return r.listener=t,i.wrapFn=r,r}w.prototype.once=function(e,t){return De(t),this.on(e,wt(this,e,t)),this};w.prototype.prependOnceListener=function(e,t){return De(t),this.prependListener(e,wt(this,e,t)),this};w.prototype.removeListener=function(e,t){var i,r,s,o,a;if(De(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():qt(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 bt(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?zt(r):vt(r,r.length)}w.prototype.listeners=function(e){return bt(this,e,!0)};w.prototype.rawListeners=function(e){return bt(this,e,!1)};w.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):yt.call(n,e)};w.prototype.listenerCount=yt;function yt(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?ye(this._events):[]};function vt(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function qt(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function zt(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function Qt(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))}kt(n,e,s,{once:!0}),e!=="error"&&Ht(n,r,{once:!0})})}function Ht(n,e,t){typeof n.on=="function"&&kt(n,"error",e,t)}function kt(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 en=Ye.exports;class tn{constructor(){Qe(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 v=new tn,Nt=1e3,nn=60*Nt,rn=1*Nt;var H,G,ge,oe,Ae,It;class sn extends en.EventEmitter{constructor(t,i){super();A(this,Ae);A(this,H,null);A(this,G,!1);A(this,ge,!1);A(this,oe,null);this.meeting=t,this.options=i,He(this,Ae,It).call(this)}cleanup(){v.info("Cleaning up recording controller"),delete window.dyteRecording,delete window.realtimeKitRecording,this.meeting.removeAllListeners(),this.removeAllListeners(),l(this,oe)!==null&&clearInterval(l(this,oe))}getParticipantCount(){return this.meeting.getParticipantCount()}getWaitlistedCount(){return this.meeting.getWaitlistedCount()}scanMeetingState(){if(!this.options.autoStop)return;if(this.getParticipantCount()>0||this.getWaitlistedCount()>0){C(this,H,null),C(this,G,!1),window.triggerDyteRecording=!0,window.triggerRealtimeKitRecording=!0;return}if(l(this,H)===null){C(this,H,new Date);return}if(new Date().getTime()-l(this,H).getTime()>this.options.waitTimeMs){v.info("Setting triggerDyteRecording & triggerRealtimeKitRecording to false"),C(this,G,!0),window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1;return}C(this,G,!1),window.triggerDyteRecording=!0,window.triggerRealtimeKitRecording=!0}stopRecording(){if(this.options.autoStop)throw new Error("Cannot stop recording when autoStop is true");v.info("Stopping recording"),window.triggerDyteRecording&&(window.triggerDyteRecording=!1),window.triggerRealtimeKitRecording&&(window.triggerRealtimeKitRecording=!1)}get meetingJoined(){return l(this,ge)}}H=new WeakMap,G=new WeakMap,ge=new WeakMap,oe=new WeakMap,Ae=new WeakSet,It=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,G),isMeetingJoined:()=>this.meetingJoined,getMeeting:()=>this.meeting.getMeeting()},window.realtimeKitRecording={getParticipantCount:()=>this.getParticipantCount(),isMeetingEnded:()=>l(this,G),isMeetingJoined:()=>this.meetingJoined,getMeeting:()=>this.meeting.getMeeting()},this.meeting.handleParticipantJoin(()=>{v.info(`Participant joined. Total participants: ${this.getParticipantCount()}. Scanning meeting state`),this.scanMeetingState(),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleParticipantLeave(()=>{v.info(`Participant left. Remaining participants: ${this.getParticipantCount()}. Scanning meeting state`),this.scanMeetingState(),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleMeetingJoined(()=>{v.info("Meeting joined"),C(this,ge,!0),this.emit("participantCount",this.getParticipantCount())}),this.meeting.handleMeetingLeft(({state:t})=>{t!=="ended"&&t!=="kicked"||(v.info("Meeting ended"),this.emit("meetingEnded"),this.cleanup(),window.triggerDyteRecording=!1,window.triggerRealtimeKitRecording=!1)}),this.options.autoStop&&C(this,oe,setInterval(()=>{this.scanMeetingState()},this.options.scanInterval))};class on{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 Et(n){let e=typeof n;if(e=="object"){if(Array.isArray(n))return"array";if(n===null)return"null"}return e}function an(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}let W="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),xe=[];for(let n=0;n<W.length;n++)xe[W[n].charCodeAt(0)]=n;xe["-".charCodeAt(0)]=W.indexOf("+");xe["_".charCodeAt(0)]=W.indexOf("/");function cn(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=xe[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 un(n){let e="",t=0,i,r=0;for(let s=0;s<n.length;s++)switch(i=n[s],t){case 0:e+=W[i>>2],r=(i&3)<<4,t=1;break;case 1:e+=W[r|i>>4],r=(i&15)<<2,t=2;break;case 2:e+=W[r|i>>6],e+=W[i&63],t=0;break}return t&&(e+=W[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 O;(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"})(O||(O={}));function fn(){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 Ue(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 ve=65536*65536;function Tt(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>=ve&&(r=r+(i/ve|0),i=i%ve)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),[e,i,r]}function Pe(n,e){if(e>>>0<=2097151)return""+(ve*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,k){let m=d?String(d):"";return k?"0000000".slice(m.length)+m:m}return h(a,0)+h(o,a)+h(s,1)}function nt(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 hn(){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 y;function ln(){const n=new DataView(new ArrayBuffer(8));y=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}ln();function Rt(n){if(!n)throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support")}const Ot=/^-?[0-9]+$/,Te=4294967296,we=2147483648;class Lt{constructor(e,t){this.lo=e|0,this.hi=t|0}isZero(){return this.lo==0&&this.hi==0}toNumber(){let e=this.hi*Te+(this.lo>>>0);if(!Number.isSafeInteger(e))throw new Error("cannot convert to safe number");return e}}class M extends Lt{static from(e){if(y)switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=="")throw new Error("string is no integer");e=y.C(e);case"number":if(e===0)return this.ZERO;e=y.C(e);case"bigint":if(!e)return this.ZERO;if(e<y.UMIN)throw new Error("signed value for ulong");if(e>y.UMAX)throw new Error("ulong too large");return y.V.setBigUint64(0,e,!0),new M(y.V.getInt32(0,!0),y.V.getInt32(4,!0))}else switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=e.trim(),!Ot.test(e))throw new Error("string is no integer");let[t,i,r]=Tt(e);if(t)throw new Error("signed value for ulong");return new M(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 M(e,e/Te)}throw new Error("unknown value "+typeof e)}toString(){return y?this.toBigInt().toString():Pe(this.lo,this.hi)}toBigInt(){return Rt(y),y.V.setInt32(0,this.lo,!0),y.V.setInt32(4,this.hi,!0),y.V.getBigUint64(0,!0)}}M.ZERO=new M(0,0);class S extends Lt{static from(e){if(y)switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=="")throw new Error("string is no integer");e=y.C(e);case"number":if(e===0)return this.ZERO;e=y.C(e);case"bigint":if(!e)return this.ZERO;if(e<y.MIN)throw new Error("signed long too small");if(e>y.MAX)throw new Error("signed long too large");return y.V.setBigInt64(0,e,!0),new S(y.V.getInt32(0,!0),y.V.getInt32(4,!0))}else switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=e.trim(),!Ot.test(e))throw new Error("string is no integer");let[t,i,r]=Tt(e);if(t){if(r>we||r==we&&i!=0)throw new Error("signed long too small")}else if(r>=we)throw new Error("signed long too large");let s=new S(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 S(e,e/Te):new S(-e,-e/Te).negate()}throw new Error("unknown value "+typeof e)}isNegative(){return(this.hi&we)!==0}negate(){let e=~this.hi,t=this.lo;return t?t=~t+1:e+=1,new S(t,e)}toString(){if(y)return this.toBigInt().toString();if(this.isNegative()){let e=this.negate();return"-"+Pe(e.lo,e.hi)}return Pe(this.lo,this.hi)}toBigInt(){return Rt(y),y.V.setInt32(0,this.lo,!0),y.V.setInt32(4,this.hi,!0),y.V.getBigInt64(0,!0)}}S.ZERO=new S(0,0);const it={readUnknownField:!0,readerFactory:n=>new gn(n)};function dn(n){return n?Object.assign(Object.assign({},it),n):it}class gn{constructor(e,t){this.varint64=fn,this.uint32=hn,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=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 O.Varint:for(;this.buf[this.pos++]&128;);break;case O.Bit64:this.pos+=4;case O.Bit32:this.pos+=4;break;case O.LengthDelimited:let i=this.uint32();this.pos+=i;break;case O.StartGroup:let r;for(;(r=this.tag()[1])!==O.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 S(...this.varint64())}uint64(){return new M(...this.varint64())}sint64(){let[e,t]=this.varint64(),i=-(e&1);return e=(e>>>1|(t&1)<<31)^i,t=t>>>1^i,new S(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 M(this.sfixed32(),this.sfixed32())}sfixed64(){return new S(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 g(n,e){if(!n)throw new Error(e)}const mn=34028234663852886e22,pn=-34028234663852886e22,wn=4294967295,bn=2147483647,yn=-2147483648;function ue(n){if(typeof n!="number")throw new Error("invalid int 32: "+typeof n);if(!Number.isInteger(n)||n>bn||n<yn)throw new Error("invalid int 32: "+n)}function Re(n){if(typeof n!="number")throw new Error("invalid uint 32: "+typeof n);if(!Number.isInteger(n)||n>wn||n<0)throw new Error("invalid uint 32: "+n)}function qe(n){if(typeof n!="number")throw new Error("invalid float 32: "+typeof n);if(Number.isFinite(n)&&(n>mn||n<pn))throw new Error("invalid float 32: "+n)}const rt={writeUnknownFields:!0,writerFactory:()=>new kn};function vn(n){return n?Object.assign(Object.assign({},rt),n):rt}class kn{constructor(e){this.stack=[],this.textEncoder=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(Re(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return ue(e),nt(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){qe(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){Re(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){ue(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return ue(e),e=(e<<1^e>>31)>>>0,nt(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),i=new DataView(t.buffer),r=S.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=M.from(e);return i.setInt32(0,r.lo,!0),i.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=S.from(e);return Ue(t.lo,t.hi,this.buf),this}sint64(e){let t=S.from(e),i=t.hi>>31,r=t.lo<<1^i,s=(t.hi<<1|t.lo>>>31)^i;return Ue(r,s,this.buf),this}uint64(e){let t=M.from(e);return Ue(t.lo,t.hi,this.buf),this}}const st={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0},ot={ignoreUnknownFields:!1};function Nn(n){return n?Object.assign(Object.assign({},ot),n):ot}function In(n){return n?Object.assign(Object.assign({},st),n):st}const St=Symbol.for("protobuf-ts/message-type");function at(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 U;(function(n){n[n.BIGINT=0]="BIGINT",n[n.STRING=1]="STRING",n[n.NUMBER=2]="NUMBER"})(U||(U={}));var Oe;(function(n){n[n.NO=0]="NO",n[n.PACKED=1]="PACKED",n[n.UNPACKED=2]="UNPACKED"})(Oe||(Oe={}));function En(n){var e,t,i,r;return n.localName=(e=n.localName)!==null&&e!==void 0?e:at(n.name),n.jsonName=(t=n.jsonName)!==null&&t!==void 0?t:at(n.name),n.repeat=(i=n.repeat)!==null&&i!==void 0?i:Oe.NO,n.opt=(r=n.opt)!==null&&r!==void 0?r:n.repeat||n.oneof?!1:n.kind=="message",n}function Tn(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 Rn{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(!Tn(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 U.BIGINT:return r=="bigint";case U.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,U.STRING)}}}function _(n,e){switch(e){case U.BIGINT:return n.toBigInt();case U.NUMBER:return n.toNumber();default:return n.toString()}}class On{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=Et(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(an(o),a.name,o);const d=h[f];for(const[k,m]of Object.entries(o)){this.assert(m!==null,a.name+" map value",null);let D;switch(a.V.kind){case"message":D=a.V.T().internalJsonRead(m,i);break;case"enum":if(D=this.enum(a.V.T(),m,a.name,i.ignoreUnknownFields),D===!1)continue;break;case"scalar":D=this.scalar(m,a.V.T,a.V.L,a.name);break}this.assert(D!==void 0,a.name+" map value",m);let V=k;a.K==c.BOOL&&(V=V=="true"?!0:V=="false"?!1:V),V=this.scalar(V,a.K,U.STRING,a.name).toString(),d[V]=D}}else if(a.repeat){if(o===null)continue;this.assert(Array.isArray(o),a.name,o);const d=h[f];for(const k of o){this.assert(k!==null,a.name,null);let m;switch(a.kind){case"message":m=a.T().internalJsonRead(k,i);break;case"enum":if(m=this.enum(a.T(),k,a.name,i.ignoreUnknownFields),m===!1)continue;break;case"scalar":m=this.scalar(k,a.T,a.L,a.name);break}this.assert(m!==void 0,a.name,o),d.push(m)}}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"&&g(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 g(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>"u"&&r?!1:(g(typeof o=="number",`Unable to parse field ${this.info.typeName}#${i}, enum ${e[0]} has no value for "${t}".`),o)}g(!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&&qe(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?Re(a):ue(a),a;case c.INT64:case c.SFIXED64:case c.SINT64:if(e===null)return _(S.ZERO,i);if(typeof e!="number"&&typeof e!="string")break;return _(S.from(e),i);case c.FIXED64:case c.UINT64:if(e===null)return _(M.ZERO,i);if(typeof e!="number"&&typeof e!="string")break;return _(M.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 cn(e)}}catch(o){s=o.message}this.assert(!1,r+(s?" - "+s:""),e)}}class Ln{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);g(f!==void 0),i[t.useProtoFieldName?s.name:s.jsonName]=f}return i}field(e,t,i){let r;if(e.kind=="map"){g(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);g(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);g(d!==void 0),s[f.toString()]=d}break;case"enum":const a=e.V.T();for(const[f,h]of Object.entries(t)){g(h===void 0||typeof h=="number");const d=this.enum(a,h,e.name,!1,!0,i.enumAsInteger);g(d!==void 0),s[f.toString()]=d}break}(i.emitDefaultValues||Object.keys(s).length>0)&&(r=s)}else if(e.repeat){g(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);g(h!==void 0),s.push(h)}break;case"enum":const o=e.T();for(let f=0;f<t.length;f++){g(t[f]===void 0||typeof t[f]=="number");const h=this.enum(o,t[f],e.name,e.opt,!0,i.enumAsInteger);g(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);g(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){g(r);return}if(!(t===0&&!s&&!r))return g(typeof t=="number"),g(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){g(r);return}const o=s||r;switch(e){case c.INT32:case c.SFIXED32:case c.SINT32:return t===0?o?0:void 0:(ue(t),t);case c.FIXED32:case c.UINT32:return t===0?o?0:void 0:(Re(t),t);case c.FLOAT:qe(t);case c.DOUBLE:return t===0?o?0:void 0:(g(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:(g(typeof t=="string"),t);case c.BOOL:return t===!1?o?!1:void 0:(g(typeof t=="boolean"),t);case c.UINT64:case c.FIXED64:g(typeof t=="number"||typeof t=="string"||typeof t=="bigint");let a=M.from(t);return a.isZero()&&!o?void 0:a.toString();case c.INT64:case c.SFIXED64:case c.SINT64:g(typeof t=="number"||typeof t=="string"||typeof t=="bigint");let f=S.from(t);return f.isZero()&&!o?void 0:f.toString();case c.BYTES:return g(t instanceof Uint8Array),t.byteLength?un(t):o?"":void 0}}}function We(n,e=U.STRING){switch(n){case c.BOOL:return!1;case c.UINT64:case c.FIXED64:return _(M.ZERO,e);case c.INT64:case c.SFIXED64:case c.SINT64:return _(S.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 Sn{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 m=i.readUnknownField;if(m=="throw")throw new Error(`Unknown field ${o} (wire type ${a}) for ${this.info.typeName}`);let D=e.skip(a);m!==!1&&(m===!0?Ee.onRead:m)(this.info.typeName,t,o,a,D);continue}let h=t,d=f.repeat,k=f.localName;switch(f.oneof&&(h=h[f.oneof],h.oneofKind!==k&&(h=t[f.oneof]={oneofKind:k})),f.kind){case"scalar":case"enum":let m=f.kind=="enum"?c.INT32:f.T,D=f.kind=="scalar"?f.L:void 0;if(d){let pe=h[k];if(a==O.LengthDelimited&&m!=c.STRING&&m!=c.BYTES){let _e=e.uint32()+e.pos;for(;e.pos<_e;)pe.push(this.scalar(e,m,D))}else pe.push(this.scalar(e,m,D))}else h[k]=this.scalar(e,m,D);break;case"message":if(d){let pe=h[k],_e=f.T().internalBinaryRead(e,e.uint32(),i);pe.push(_e)}else h[k]=f.T().internalBinaryRead(e,e.uint32(),i,h[k]);break;case"map":let[V,Jt]=this.mapEntry(f,e,i);h[k][V]=Jt;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,U.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=We(e.K);o=e.K==c.BOOL?f.toString():f}if(a===void 0)switch(e.V.kind){case"scalar":a=We(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 _(e.int64(),i);case c.UINT64:return _(e.uint64(),i);case c.FIXED64:return _(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 _(e.sfixed64(),i);case c.SINT32:return e.sint32();case c.SINT64:return _(e.sint64(),i)}}}class Fn{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(g(Array.isArray(o)),f==Oe.PACKED)this.packed(t,d,s.no,o);else for(const k of o)this.scalar(t,d,s.no,k,!0);else o===void 0?g(s.opt):this.scalar(t,d,s.no,o,a||s.opt);break;case"message":if(f){g(Array.isArray(o));for(const k of o)this.message(t,i,s.T(),s.no,k)}else this.message(t,i,s.T(),s.no,o);break;case"map":g(typeof o=="object"&&o!==null);for(const[k,m]of Object.entries(o))this.mapEntry(t,i,s,k,m);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,O.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:g(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,O.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;g(t!==c.BYTES&&t!==c.STRING),e.tag(i,O.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=O.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=O.LengthDelimited,r="string";break;case c.BOOL:o=t===!1,r="bool";break;case c.UINT32:r="uint32";break;case c.DOUBLE:i=O.Bit64,r="double";break;case c.FLOAT:i=O.Bit32,r="float";break;case c.INT64:o=s||S.from(t).isZero(),r="int64";break;case c.UINT64:o=s||M.from(t).isZero(),r="uint64";break;case c.FIXED64:o=s||M.from(t).isZero(),i=O.Bit64,r="fixed64";break;case c.BYTES:o=s||!t.byteLength,i=O.LengthDelimited,r="bytes";break;case c.FIXED32:i=O.Bit32,r="fixed32";break;case c.SFIXED32:i=O.Bit32,r="sfixed32";break;case c.SFIXED64:o=s||S.from(t).isZero(),i=O.Bit64,r="sfixed64";break;case c.SINT32:r="sint32";break;case c.SINT64:o=s||S.from(t).isZero(),r="sint64";break}return[i,r,s||o]}}function Cn(n){const e=n.messagePrototype?Object.create(n.messagePrototype):Object.defineProperty({},St,{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]=We(t.T,t.L);break;case"enum":e[i]=0;break;case"map":e[i]={};break}}return e}function Ve(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 Mn(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?ct(a,s,o):Ft(a,s,o)))return!1;break;case"map":if(!(i.V.kind=="message"?ut(i.V.T(),be(s),be(o)):ct(i.V.kind=="enum"?c.INT32:i.V.T,be(s),be(o))))return!1;break;case"message":let f=i.T();if(!(i.repeat?ut(f,s,o):f.equals(s,o)))return!1;break}}return!0}const be=Object.values;function Ft(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 ct(n,e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!Ft(n,e[i],t[i]))return!1;return!0}function ut(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({})),An=Ct[St]={};class Dn{constructor(e,t,i){this.defaultCheckDepth=16,this.typeName=e,this.fields=t.map(En),this.options=i??{},An.value=this,this.messagePrototype=Object.create(null,Ct),this.refTypeCheck=new Rn(this),this.refJsonReader=new On(this),this.refJsonWriter=new Ln(this),this.refBinReader=new Sn(this),this.refBinWriter=new Fn(this)}create(e){let t=Cn(this);return e!==void 0&&Ve(this,t,e),t}clone(e){let t=this.create();return Ve(this,t,e),t}equals(e,t){return Mn(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){Ve(this,e,t)}fromBinary(e,t){let i=dn(t);return this.internalBinaryRead(i.readerFactory(e),e.byteLength,i)}fromJson(e,t){return this.internalJsonRead(e,Nn(t))}fromJsonString(e,t){let i=JSON.parse(e);return this.fromJson(i,t)}toJson(e,t){return this.internalJsonWrite(e,In(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=vn(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??this.create();return this.refJsonReader.read(e,r,t),r}throw new Error(`Unable to parse message ${this.typeName} from JSON ${Et(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??this.create();return this.refBinReader.read(e,s,i,t),s}}var xn=Object.defineProperty,Bn=(n,e,t)=>e in n?xn(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_n=(n,e,t)=>(Bn(n,typeof e!="symbol"?e+"":e,t),t),ze=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)},u=(n,e,t)=>(ze(n,e,"read from private field"),t?t.call(n):e.get(n)),N=(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),E=(n,e,t)=>(ze(n,e,"access private method"),t),Le={},Kn={get exports(){return Le},set exports(n){Le=n}},re=typeof Reflect=="object"?Reflect:null,ft=re&&typeof re.apply=="function"?re.apply:function(n,e,t){return Function.prototype.apply.call(n,e,t)},ke;re&&typeof re.ownKeys=="function"?ke=re.ownKeys:Object.getOwnPropertySymbols?ke=function(n){return Object.getOwnPropertyNames(n).concat(Object.getOwnPropertySymbols(n))}:ke=function(n){return Object.getOwnPropertyNames(n)};function Un(n){console&&console.warn&&console.warn(n)}var Mt=Number.isNaN||function(n){return n!==n};function b(){b.init.call(this)}Kn.exports=b;Le.once=$n;b.EventEmitter=b;b.prototype._events=void 0;b.prototype._eventsCount=0;b.prototype._maxListeners=void 0;var ht=10;function Be(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 ht},set:function(n){if(typeof n!="number"||n<0||Mt(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");ht=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||Mt(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 At(n){return n._maxListeners===void 0?b.defaultMaxListeners:n._maxListeners}b.prototype.getMaxListeners=function(){return At(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")ft(a,this,e);else for(var f=a.length,h=Kt(a,f),t=0;t<f;++t)ft(h[t],this,e);return!0};function Dt(n,e,t,i){var r,s,o;if(Be(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=At(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(n,e){return Dt(this,n,e,!1)};b.prototype.on=b.prototype.addListener;b.prototype.prependListener=function(n,e){return Dt(this,n,e,!0)};function Vn(){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=Vn.bind(i);return r.listener=t,i.wrapFn=r,r}b.prototype.once=function(n,e){return Be(e),this.on(n,xt(this,n,e)),this};b.prototype.prependOnceListener=function(n,e){return Be(e),this.prependListener(n,xt(this,n,e)),this};b.prototype.removeListener=function(n,e){var t,i,r,s,o;if(Be(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():Pn(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 Bt(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?Wn(r):Kt(r,r.length)}b.prototype.listeners=function(n){return Bt(this,n,!0)};b.prototype.rawListeners=function(n){return Bt(this,n,!1)};b.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):_t.call(n,e)};b.prototype.listenerCount=_t;function _t(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?ke(this._events):[]};function Kt(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function Pn(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function Wn(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function $n(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"&&jn(n,r,{once:!0})})}function jn(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)}class Jn extends Dn{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 lt=new Jn;class Vt{static encode(e){return lt.toBinary(e)}static decode(e){return lt.fromBinary(new Uint8Array(e))}}function Xn(n,e){return Math.floor(Math.random()*(e-n+1)+n)}var J;class Gn{constructor(e={}){_n(this,"opts"),N(this,J,void 0),this.opts={initialTimeout:e.initialTimeout||1e3,maxTimeout:e.maxTimeout||1e4,factor:e.factor||2},p(this,J,0)}async wait(){p(this,J,u(this,J)+1);const e=Xn(0,Math.min(this.opts.maxTimeout,this.opts.initialTimeout*2**u(this,J)));await new Promise(t=>{setTimeout(t,e)})}getAttempts(){return u(this,J)}reset(){p(this,J,0)}}J=new WeakMap;const j={debug:0,info:1,warn:2,error:3};var z,Q;class Zn{constructor(e){N(this,z,void 0),N(this,Q,void 0),p(this,z,console),p(this,Q,e)}debug(...e){j[u(this,Q)]>j.debug||u(this,z).debug("[Sockrates]:",...e)}info(...e){j[u(this,Q)]>j.info||u(this,z).info("[Sockrates]:",...e)}warn(...e){j[u(this,Q)]>j.warn||u(this,z).warn("[Sockrates]:",...e)}error(...e){j[u(this,Q)]>j.error||u(this,z).error("[Sockrates]:",...e)}}z=new WeakMap,Q=new WeakMap;var Pt=(n=>(n[n.CONNECTING=0]="CONNECTING",n[n.OPEN=1]="OPEN",n[n.CLOSING=2]="CLOSING",n[n.CLOSED=3]="CLOSED",n))(Pt||{});const Yn="2",qn="3";var R,te,I,L,X,F,$,q,B,ne,P,$e,Wt,ce,Ne,je,$t,Je,dt,Se,Xe,Ge,jt,fe,Ie,he,Fe,Ce,Ze,se,le,de,Me;class zn{constructor(e,t){N(this,$e),N(this,ce),N(this,je),N(this,Je),N(this,Se),N(this,Ge),N(this,fe),N(this,he),N(this,Ce),N(this,se),N(this,de),N(this,R,void 0),N(this,te,void 0),N(this,I,void 0),N(this,L,void 0),N(this,X,void 0),N(this,F,void 0),N(this,$,void 0),N(this,q,void 0),N(this,B,void 0),N(this,ne,void 0),N(this,P,void 0);var i,r,s,o,a,f,h,d,k;p(this,te,e),p(this,X,[]),p(this,F,new Le),p(this,$,!0),p(this,B,!1),p(this,I,t??{}),(i=u(this,I)).autoReconnect??(i.autoReconnect=!0),(r=u(this,I)).retryConnectionInterval??(r.retryConnectionInterval=1e3),(s=u(this,I)).pingTimeout??(s.pingTimeout=3e4),(o=u(this,I)).connectionTimeout??(o.connectionTimeout=5e3),(a=u(this,I)).debug??(a.debug=!0),(f=u(this,I)).maxReconnectionAttempts??(f.maxReconnectionAttempts=10),(h=u(this,I)).disconnectOnPingTimeout??(h.disconnectOnPingTimeout=!0),(d=u(this,I)).queueOnDisconnect??(d.queueOnDisconnect=!1),(k=u(this,I)).flushOnReconnect??(k.flushOnReconnect=!1),p(this,q,{code:void 0,reason:void 0}),p(this,L,u(this,I).logger??new Zn(u(this,I).debug?"debug":"info")),p(this,P,new Gn)}get readyState(){var e;return(e=u(this,R))==null?void 0:e.readyState}get url(){return u(this,te)}updateURL(e){p(this,te,e),E(this,Ge,jt).call(this)}get config(){return u(this,I)}get sendQueue(){return u(this,X)}flush(){if(!u(this,I).queueOnDisconnect)return!1;const e=[];return u(this,X).forEach(t=>{this.send(t.event,t.id,t.payload,t.metadata)||e.push(t)}),p(this,X,e),u(this,X)}async connect(e=!1){if(!e&&[0,1].includes(this.readyState)){u(this,L).debug("Websocket was already connecting or connected.");return}if(u(this,$)!==!1)return new Promise((t,i)=>{E(this,se,le).call(this),E(this,de,Me).call(this);try{p(this,R,new WebSocket(E(this,$e,Wt).call(this,u(this,te)))),u(this,R).binaryType="arraybuffer",u(this,L).debug("Connecting");const r=setTimeout(()=>{u(this,L).debug("Connection timeout. Closing socket"),p(this,$,!0),E(this,de,Me).call(this),u(this,R).close(3001,"Connection Timeout"),u(this,I).autoReconnect&&!u(this,B)&&(u(this,F).emit("reconnecting"),E(this,fe,Ie).call(this)),i(new Error("Connection timed out!"))},u(this,I).connectionTimeout);u(this,R).onopen=()=>{u(this,L).debug(`Ready State: ${Pt[u(this,R).readyState]}`),r&&clearTimeout(r),E(this,Ce,Ze).call(this),p(this,q,{code:void 0,reason:void 0}),u(this,F).emit("connected"),u(this,I).flushOnReconnect&&this.flush(),t()},u(this,R).onclose=s=>{try{r&&clearTimeout(r);const{code:o,reason:a}=s;i(a),u(this,L).debug("Socket closed. Close event:",{event:s}),u(this,L).debug(`Connection closed code: ${o}`),u(this,L).debug(`Connection closed reason: ${a}`),u(this,B)||E(this,Se,Xe).call(this,o,a)}catch(o){E(this,ce,Ne).call(this,o)}},u(this,R).onerror=s=>{E(this,ce,Ne).call(this,s)},u(this,R).onmessage=s=>E(this,je,$t).call(this,s)}catch(r){E(this,ce,Ne).call(this,r,i)}})}send(e,t,i,r){const s={event:e,id:t,payload:i,metadata:r};if(u(this,I).queueOnDisconnect&&(!u(this,R)||u(this,R).readyState!==1))return u(this,L).debug("Queuing message since socket is not connected!",s),u(this,X).push(s),!1;const o=Vt.encode(s);return E(this,he,Fe).call(this,o)}emit(e,t,i,r){return this.send(e,t,i,r)}sendRaw(e){return E(this,he,Fe).call(this,e)}receive(e,t){return u(this,F).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,F).on(e,t);return}this.receive(e,t)}removeAllListeners(){u(this,F).removeAllListeners()}removeReceiver(e,t){this.removeListener(e,t)}removeListener(e,t){u(this,F).removeListener(e.toString(),t)}removeReceivers(e){this.removeListeners(e)}removeListeners(e){u(this,F).listeners(e.toString()).map(t=>this.removeListener(e,t))}disconnect(){p(this,$,!1),E(this,se,le).call(this),this.removeAllListeners(),p(this,q,{code:1e3,reason:"Sockrates disconnect method called"}),u(this,R).close(1e3,"Sockrates disconnect method called.")}}R=new WeakMap,te=new WeakMap,I=new WeakMap,L=new WeakMap,X=new WeakMap,F=new WeakMap,$=new WeakMap,q=new WeakMap,B=new WeakMap,ne=new WeakMap,P=new WeakMap,$e=new WeakSet,Wt=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)://.")},ce=new WeakSet,Ne=function(n,e){u(this,L).error("Error:",{error:n}),u(this,F).emit("errored",{error:n}),e==null||e(n)},je=new WeakSet,$t=function(n){if(E(this,Ce,Ze).call(this),n.data===Yn){u(this,L).debug("Received ping from server"),E(this,he,Fe).call(this,qn);return}const e=Vt.decode(n.data),{id:t,payload:i}=e;u(this,L).debug("Received message",{event:e.event,messageID:t}),u(this,F).emit(e.event.toString(),{id:t,payload:i})},Je=new WeakSet,dt=function(){return u(this,R).readyState===1},Se=new WeakSet,Xe=function(n,e){p(this,q,{reason:e,code:n}),u(this,F).emit("disconnected",{code:n,reason:e})},Ge=new WeakSet,jt=function(){const{reason:n,code:e}=u(this,q);e&&e!==1e3&&u(this,$)&&u(this,I).autoReconnect&&!u(this,B)&&(u(this,L).debug(`Triggering reconnection due to ${n}.`),u(this,F).emit("reconnecting"),E(this,fe,Ie).call(this))},fe=new WeakSet,Ie=async function(n=!0){if(n&&u(this,B)){u(this,L).debug("Reconnect called when already in a reconnect loop. Ignoring.");return}if(u(this,B)||u(this,P).reset(),u(this,I).maxReconnectionAttempts!==null&&u(this,P).getAttempts()>=u(this,I).maxReconnectionAttempts){u(this,F).emit("failed"),p(this,B,!1);return}p(this,B,!0),E(this,de,Me).call(this),E(this,se,le).call(this);try{if(await u(this,P).wait(),u(this,$)===!1)return;if(u(this,L).debug(`Reconnection attempt ${u(this,P).getAttempts()}`),u(this,F).emit("reconnectAttempt",{attempt:u(this,P).getAttempts()}),await this.connect(),!E(this,Je,dt).call(this))throw Error("Reconnect Failed");p(this,B,!1),p(this,q,{code:void 0,reason:void 0}),u(this,F).emit("reconnected")}catch{u(this,L).debug("Failed to reconnect."),u(this,F).emit("reconnectFailure",{attempt:u(this,P).getAttempts()}),E(this,fe,Ie).call(this,!1)}},he=new WeakSet,Fe=function(n){try{return u(this,R).send(n),!0}catch(e){return u(this,L).error(e.message),!1}},Ce=new WeakSet,Ze=function(){this.config.disconnectOnPingTimeout&&(u(this,L).debug("Resetting ping timeout"),E(this,se,le).call(this),p(this,ne,setTimeout(()=>{var n;u(this,L).debug("Disconnecting the socket due to ping timeout"),p(this,$,!0);const e=3002,t="Ping timeout";(n=u(this,R))==null||n.close(e,t),E(this,Se,Xe).call(this,e,t)},u(this,I).pingTimeout)))},se=new WeakSet,le=function(){u(this,ne)&&(clearTimeout(u(this,ne)),p(this,ne,void 0))},de=new WeakSet,Me=function(){u(this,R)&&(u(this,R).onopen=void 0,u(this,R).onerror=void 0,u(this,R).onmessage=void 0,u(this,R).onclose=void 0)};class Qn{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}`)}}var Z,ee,me;class Hn{constructor(e,t=!1){A(this,Z,null);A(this,ee,!1);A(this,me,!1);this.wsUrl=e,this.devMode=t}get connected(){return l(this,ee)}async connect(e){let t;this.devMode?t=new Qn(this.wsUrl,{queueOnDisconnect:!0,flushOnReconnect:!0}):t=new zn(this.wsUrl,{queueOnDisconnect:!0,flushOnReconnect:!0}),e.participants.addListener("broadcastedMessage",i=>t.sendRaw(JSON.stringify(i))),v.info("Connecting to websocket"),t.on("connected",()=>{v.info("Connected to websocket")}),await t.connect(!0),C(this,Z,t),C(this,ee,!0)}disconnect(){l(this,Z)&&(l(this,Z).disconnect(),C(this,ee,!1))}startRecordingMessage(){if(l(this,me))throw new Error("Start recording message already sent");if(l(this,Z)&&l(this,ee))C(this,me,!0),l(this,Z).sendRaw(JSON.stringify({type:"StartRecording"}));else throw new Error("Not connected to websocket, make sure you have called init.")}}Z=new WeakMap,ee=new WeakMap,me=new WeakMap;class ei{constructor(){}checkIfSDKEnabled(){return v.info("Check if SDK enabled"),window.dyteRecordingSdk===!0||window.realtimeKitRecordingSdk===!0}checkIfRecordingTriggerAdded(){return v.info("Check if recording trigger added"),window.triggerDyteRecording===!0||window.triggerRealtimeKitRecording===!0}checkMeetingJoined(){var e;return v.info("Check if meeting joined getter available"),((e=window.realtimeKitRecording)==null?void 0:e.isMeetingJoined())!==!0}checkParticipantCount(){var e;return v.info("Check if participant count getter available"),((e=window.realtimeKitRecording)==null?void 0:e.getParticipantCount())!==void 0}pageLoadTests(){v.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(){v.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){v.error(e),e+="You can contact Dyte support for help",window.alert(e)}}var Y,T,x,K,ae;class ti{constructor(e){A(this,Y,void 0);A(this,T,void 0);A(this,x,void 0);A(this,K,void 0);A(this,ae,void 0);e.waitTimeMs&&!e.autoStop&&v.warn("You have passed both waitTimeMs and autoStop. waitTimeMs will be ignored"),C(this,T,{waitTimeMs:e.waitTimeMs??1*nn,websocketUrl:e.websocketUrl??"ws://localhost:8080/ws",autoStart:e.autoStart??!0,autoStop:e.autoStop??!0,devMode:window.navigator.webdriver==!1,scanInterval:e.scanInterval??rn}),window.dyteRecordingSdk=!0,window.realtimeKitRecordingSdk=!0,window.devMode=l(this,T).devMode,C(this,K,new ei),this.performOnPageLoadChecks()}async init(e){v.info("Initializing RealtimeKit Recording SDK");const t=new sn(new on(e),{autoStop:l(this,T).autoStop,waitTimeMs:l(this,T).waitTimeMs,scanInterval:l(this,T).scanInterval}),i=new Hn(l(this,T).websocketUrl,l(this,T).devMode);await i.connect(e),C(this,x,i),C(this,Y,t),this.sdkInitTests(),v.init(e),C(this,ae,e),l(this,T).autoStart&&await this.startRecording()}async startRecording(){var e,t;if((e=l(this,ae))!=null&&e.self.roomJoined){const i="Meeting already joined. Cannot start recording. SDK will call joinRoom automatically.";if(v.warn(i),l(this,T).devMode)throw new Error(i)}if(await((t=l(this,ae))==null?void 0:t.joinRoom()),v.info("Sending start recording request"),l(this,x))try{l(this,x).startRecordingMessage()}catch(i){const r=`Failed to start recording with error: ${i}`;if(v.error(r),l(this,T).devMode)throw new Error(r)}}stopRecording(){if(v.info("Stopping RealtimeKit Recording SDK"),l(this,Y))l(this,Y).stopRecording(),l(this,x)&&l(this,x).connected&&l(this,x).disconnect();else{const e="recording controller not initialized";if(v.error(e),l(this,T).devMode)throw new Error(e)}}async cleanup(){if(v.info("Cleaning up RealtimeKit Recording SDK"),delete window.devMode,delete window.realtimeKitRecordingSdk,delete window.dyteRecordingSdk,l(this,Y))try{l(this,Y).cleanup(),l(this,x)&&l(this,x).connected&&l(this,x).disconnect()}catch(e){const t=`Failed to cleanup with error: ${e}`;if(v.error(t),l(this,T).devMode)throw new Error(t)}else{const e="recording controller not initialized";if(v.error("recording controller not initialized"),l(this,T).devMode)throw new Error(e)}}performOnPageLoadChecks(){if(l(this,K))try{l(this,K).pageLoadTests()}catch(e){const t=`Failed to perform page load checks with error: ${e}`;if(typeof e=="string"&&l(this,T).devMode&&l(this,K).showAlert(e),l(this,T).devMode)throw new Error(t)}else{const e="SDK Checks controller not initialized";if(l(this,T).devMode)throw new Error(e)}}sdkInitTests(){if(l(this,K))try{l(this,K).sdkInitTests()}catch(e){const t=`Failed to perform sdk init checks with error: ${e}`;if(typeof e=="string"&&l(this,T).devMode&&l(this,K).showAlert(e),l(this,T).devMode)throw new Error(t)}else{const e="SDK Checks controller not initialized";if(l(this,T).devMode)throw new Error(e)}}}Y=new WeakMap,T=new WeakMap,x=new WeakMap,K=new WeakMap,ae=new WeakMap;exports.RealtimeKitRecording=ti;
|