@sawport/peers-caller 1.0.0-alpha.8 → 1.0.0-alpha.9
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/dist/core/CallRecorder.d.ts +2 -2
- package/dist/core/CallRecorder.d.ts.map +1 -1
- package/dist/core/CallSocket.d.ts +2 -2
- package/dist/core/CallSocket.d.ts.map +1 -1
- package/dist/core/PeersCaller.d.ts.map +1 -1
- package/dist/peers-caller.es.js +16 -11
- package/dist/peers-caller.es.js.map +1 -1
- package/dist/peers-caller.umd.js +2 -2
- package/dist/peers-caller.umd.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/peers-caller.umd.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
5
|
* @license MIT
|
|
6
|
-
*/(function(r){const e=Et,t=qt,s=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;r.Buffer=h,r.SlowBuffer=k,r.INSPECT_MAX_BYTES=50;const f=2147483647;r.kMaxLength=f;const{Uint8Array:l,ArrayBuffer:g,SharedArrayBuffer:u}=globalThis;h.TYPED_ARRAY_SUPPORT=c(),!h.TYPED_ARRAY_SUPPORT&&typeof console!="undefined"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function c(){try{const d=new l(1),n={foo:function(){return 42}};return Object.setPrototypeOf(n,l.prototype),Object.setPrototypeOf(d,n),d.foo()===42}catch(d){return!1}}Object.defineProperty(h.prototype,"parent",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.buffer}}),Object.defineProperty(h.prototype,"offset",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.byteOffset}});function v(d){if(d>f)throw new RangeError('The value "'+d+'" is invalid for option "size"');const n=new l(d);return Object.setPrototypeOf(n,h.prototype),n}function h(d,n,o){if(typeof d=="number"){if(typeof n=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return b(d)}return I(d,n,o)}h.poolSize=8192;function I(d,n,o){if(typeof d=="string")return N(d,n);if(g.isView(d))return m(d);if(d==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof d);if(Ne(d,g)||d&&Ne(d.buffer,g)||typeof u!="undefined"&&(Ne(d,u)||d&&Ne(d.buffer,u)))return R(d,n,o);if(typeof d=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const _=d.valueOf&&d.valueOf();if(_!=null&&_!==d)return h.from(_,n,o);const O=A(d);if(O)return O;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof d[Symbol.toPrimitive]=="function")return h.from(d[Symbol.toPrimitive]("string"),n,o);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof d)}h.from=function(d,n,o){return I(d,n,o)},Object.setPrototypeOf(h.prototype,l.prototype),Object.setPrototypeOf(h,l);function B(d){if(typeof d!="number")throw new TypeError('"size" argument must be of type number');if(d<0)throw new RangeError('The value "'+d+'" is invalid for option "size"')}function x(d,n,o){return B(d),d<=0?v(d):n!==void 0?typeof o=="string"?v(d).fill(n,o):v(d).fill(n):v(d)}h.alloc=function(d,n,o){return x(d,n,o)};function b(d){return B(d),v(d<0?0:P(d)|0)}h.allocUnsafe=function(d){return b(d)},h.allocUnsafeSlow=function(d){return b(d)};function N(d,n){if((typeof n!="string"||n==="")&&(n="utf8"),!h.isEncoding(n))throw new TypeError("Unknown encoding: "+n);const o=S(d,n)|0;let _=v(o);const O=_.write(d,n);return O!==o&&(_=_.slice(0,O)),_}function T(d){const n=d.length<0?0:P(d.length)|0,o=v(n);for(let _=0;_<n;_+=1)o[_]=d[_]&255;return o}function m(d){if(Ne(d,l)){const n=new l(d);return R(n.buffer,n.byteOffset,n.byteLength)}return T(d)}function R(d,n,o){if(n<0||d.byteLength<n)throw new RangeError('"offset" is outside of buffer bounds');if(d.byteLength<n+(o||0))throw new RangeError('"length" is outside of buffer bounds');let _;return n===void 0&&o===void 0?_=new l(d):o===void 0?_=new l(d,n):_=new l(d,n,o),Object.setPrototypeOf(_,h.prototype),_}function A(d){if(h.isBuffer(d)){const n=P(d.length)|0,o=v(n);return o.length===0||d.copy(o,0,0,n),o}if(d.length!==void 0)return typeof d.length!="number"||We(d.length)?v(0):T(d);if(d.type==="Buffer"&&Array.isArray(d.data))return T(d.data)}function P(d){if(d>=f)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f.toString(16)+" bytes");return d|0}function k(d){return+d!=d&&(d=0),h.alloc(+d)}h.isBuffer=function(n){return n!=null&&n._isBuffer===!0&&n!==h.prototype},h.compare=function(n,o){if(Ne(n,l)&&(n=h.from(n,n.offset,n.byteLength)),Ne(o,l)&&(o=h.from(o,o.offset,o.byteLength)),!h.isBuffer(n)||!h.isBuffer(o))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(n===o)return 0;let _=n.length,O=o.length;for(let j=0,Y=Math.min(_,O);j<Y;++j)if(n[j]!==o[j]){_=n[j],O=o[j];break}return _<O?-1:O<_?1:0},h.isEncoding=function(n){switch(String(n).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},h.concat=function(n,o){if(!Array.isArray(n))throw new TypeError('"list" argument must be an Array of Buffers');if(n.length===0)return h.alloc(0);let _;if(o===void 0)for(o=0,_=0;_<n.length;++_)o+=n[_].length;const O=h.allocUnsafe(o);let j=0;for(_=0;_<n.length;++_){let Y=n[_];if(Ne(Y,l))j+Y.length>O.length?(h.isBuffer(Y)||(Y=h.from(Y)),Y.copy(O,j)):l.prototype.set.call(O,Y,j);else if(h.isBuffer(Y))Y.copy(O,j);else throw new TypeError('"list" argument must be an Array of Buffers');j+=Y.length}return O};function S(d,n){if(h.isBuffer(d))return d.length;if(g.isView(d)||Ne(d,g))return d.byteLength;if(typeof d!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof d);const o=d.length,_=arguments.length>2&&arguments[2]===!0;if(!_&&o===0)return 0;let O=!1;for(;;)switch(n){case"ascii":case"latin1":case"binary":return o;case"utf8":case"utf-8":return Fe(d).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return o*2;case"hex":return o>>>1;case"base64":return we(d).length;default:if(O)return _?-1:Fe(d).length;n=(""+n).toLowerCase(),O=!0}}h.byteLength=S;function C(d,n,o){let _=!1;if((n===void 0||n<0)&&(n=0),n>this.length||((o===void 0||o>this.length)&&(o=this.length),o<=0)||(o>>>=0,n>>>=0,o<=n))return"";for(d||(d="utf8");;)switch(d){case"hex":return $(this,n,o);case"utf8":case"utf-8":return ke(this,n,o);case"ascii":return Oe(this,n,o);case"latin1":case"binary":return qe(this,n,o);case"base64":return Pe(this,n,o);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return V(this,n,o);default:if(_)throw new TypeError("Unknown encoding: "+d);d=(d+"").toLowerCase(),_=!0}}h.prototype._isBuffer=!0;function M(d,n,o){const _=d[n];d[n]=d[o],d[o]=_}h.prototype.swap16=function(){const n=this.length;if(n%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let o=0;o<n;o+=2)M(this,o,o+1);return this},h.prototype.swap32=function(){const n=this.length;if(n%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let o=0;o<n;o+=4)M(this,o,o+3),M(this,o+1,o+2);return this},h.prototype.swap64=function(){const n=this.length;if(n%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let o=0;o<n;o+=8)M(this,o,o+7),M(this,o+1,o+6),M(this,o+2,o+5),M(this,o+3,o+4);return this},h.prototype.toString=function(){const n=this.length;return n===0?"":arguments.length===0?ke(this,0,n):C.apply(this,arguments)},h.prototype.toLocaleString=h.prototype.toString,h.prototype.equals=function(n){if(!h.isBuffer(n))throw new TypeError("Argument must be a Buffer");return this===n?!0:h.compare(this,n)===0},h.prototype.inspect=function(){let n="";const o=r.INSPECT_MAX_BYTES;return n=this.toString("hex",0,o).replace(/(.{2})/g,"$1 ").trim(),this.length>o&&(n+=" ... "),"<Buffer "+n+">"},s&&(h.prototype[s]=h.prototype.inspect),h.prototype.compare=function(n,o,_,O,j){if(Ne(n,l)&&(n=h.from(n,n.offset,n.byteLength)),!h.isBuffer(n))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof n);if(o===void 0&&(o=0),_===void 0&&(_=n?n.length:0),O===void 0&&(O=0),j===void 0&&(j=this.length),o<0||_>n.length||O<0||j>this.length)throw new RangeError("out of range index");if(O>=j&&o>=_)return 0;if(O>=j)return-1;if(o>=_)return 1;if(o>>>=0,_>>>=0,O>>>=0,j>>>=0,this===n)return 0;let Y=j-O,ce=_-o;const be=Math.min(Y,ce),Se=this.slice(O,j),Ce=n.slice(o,_);for(let pe=0;pe<be;++pe)if(Se[pe]!==Ce[pe]){Y=Se[pe],ce=Ce[pe];break}return Y<ce?-1:ce<Y?1:0};function W(d,n,o,_,O){if(d.length===0)return-1;if(typeof o=="string"?(_=o,o=0):o>2147483647?o=2147483647:o<-2147483648&&(o=-2147483648),o=+o,We(o)&&(o=O?0:d.length-1),o<0&&(o=d.length+o),o>=d.length){if(O)return-1;o=d.length-1}else if(o<0)if(O)o=0;else return-1;if(typeof n=="string"&&(n=h.from(n,_)),h.isBuffer(n))return n.length===0?-1:X(d,n,o,_,O);if(typeof n=="number")return n=n&255,typeof l.prototype.indexOf=="function"?O?l.prototype.indexOf.call(d,n,o):l.prototype.lastIndexOf.call(d,n,o):X(d,[n],o,_,O);throw new TypeError("val must be string, number or Buffer")}function X(d,n,o,_,O){let j=1,Y=d.length,ce=n.length;if(_!==void 0&&(_=String(_).toLowerCase(),_==="ucs2"||_==="ucs-2"||_==="utf16le"||_==="utf-16le")){if(d.length<2||n.length<2)return-1;j=2,Y/=2,ce/=2,o/=2}function be(Ce,pe){return j===1?Ce[pe]:Ce.readUInt16BE(pe*j)}let Se;if(O){let Ce=-1;for(Se=o;Se<Y;Se++)if(be(d,Se)===be(n,Ce===-1?0:Se-Ce)){if(Ce===-1&&(Ce=Se),Se-Ce+1===ce)return Ce*j}else Ce!==-1&&(Se-=Se-Ce),Ce=-1}else for(o+ce>Y&&(o=Y-ce),Se=o;Se>=0;Se--){let Ce=!0;for(let pe=0;pe<ce;pe++)if(be(d,Se+pe)!==be(n,pe)){Ce=!1;break}if(Ce)return Se}return-1}h.prototype.includes=function(n,o,_){return this.indexOf(n,o,_)!==-1},h.prototype.indexOf=function(n,o,_){return W(this,n,o,_,!0)},h.prototype.lastIndexOf=function(n,o,_){return W(this,n,o,_,!1)};function re(d,n,o,_){o=Number(o)||0;const O=d.length-o;_?(_=Number(_),_>O&&(_=O)):_=O;const j=n.length;_>j/2&&(_=j/2);let Y;for(Y=0;Y<_;++Y){const ce=parseInt(n.substr(Y*2,2),16);if(We(ce))return Y;d[o+Y]=ce}return Y}function U(d,n,o,_){return $e(Fe(n,d.length-o),d,o,_)}function he(d,n,o,_){return $e(Ue(n),d,o,_)}function de(d,n,o,_){return $e(we(n),d,o,_)}function me(d,n,o,_){return $e(ye(n,d.length-o),d,o,_)}h.prototype.write=function(n,o,_,O){if(o===void 0)O="utf8",_=this.length,o=0;else if(_===void 0&&typeof o=="string")O=o,_=this.length,o=0;else if(isFinite(o))o=o>>>0,isFinite(_)?(_=_>>>0,O===void 0&&(O="utf8")):(O=_,_=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const j=this.length-o;if((_===void 0||_>j)&&(_=j),n.length>0&&(_<0||o<0)||o>this.length)throw new RangeError("Attempt to write outside buffer bounds");O||(O="utf8");let Y=!1;for(;;)switch(O){case"hex":return re(this,n,o,_);case"utf8":case"utf-8":return U(this,n,o,_);case"ascii":case"latin1":case"binary":return he(this,n,o,_);case"base64":return de(this,n,o,_);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return me(this,n,o,_);default:if(Y)throw new TypeError("Unknown encoding: "+O);O=(""+O).toLowerCase(),Y=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Pe(d,n,o){return n===0&&o===d.length?e.fromByteArray(d):e.fromByteArray(d.slice(n,o))}function ke(d,n,o){o=Math.min(d.length,o);const _=[];let O=n;for(;O<o;){const j=d[O];let Y=null,ce=j>239?4:j>223?3:j>191?2:1;if(O+ce<=o){let be,Se,Ce,pe;switch(ce){case 1:j<128&&(Y=j);break;case 2:be=d[O+1],(be&192)===128&&(pe=(j&31)<<6|be&63,pe>127&&(Y=pe));break;case 3:be=d[O+1],Se=d[O+2],(be&192)===128&&(Se&192)===128&&(pe=(j&15)<<12|(be&63)<<6|Se&63,pe>2047&&(pe<55296||pe>57343)&&(Y=pe));break;case 4:be=d[O+1],Se=d[O+2],Ce=d[O+3],(be&192)===128&&(Se&192)===128&&(Ce&192)===128&&(pe=(j&15)<<18|(be&63)<<12|(Se&63)<<6|Ce&63,pe>65535&&pe<1114112&&(Y=pe))}}Y===null?(Y=65533,ce=1):Y>65535&&(Y-=65536,_.push(Y>>>10&1023|55296),Y=56320|Y&1023),_.push(Y),O+=ce}return _e(_)}const Ee=4096;function _e(d){const n=d.length;if(n<=Ee)return String.fromCharCode.apply(String,d);let o="",_=0;for(;_<n;)o+=String.fromCharCode.apply(String,d.slice(_,_+=Ee));return o}function Oe(d,n,o){let _="";o=Math.min(d.length,o);for(let O=n;O<o;++O)_+=String.fromCharCode(d[O]&127);return _}function qe(d,n,o){let _="";o=Math.min(d.length,o);for(let O=n;O<o;++O)_+=String.fromCharCode(d[O]);return _}function $(d,n,o){const _=d.length;(!n||n<0)&&(n=0),(!o||o<0||o>_)&&(o=_);let O="";for(let j=n;j<o;++j)O+=Ve[d[j]];return O}function V(d,n,o){const _=d.slice(n,o);let O="";for(let j=0;j<_.length-1;j+=2)O+=String.fromCharCode(_[j]+_[j+1]*256);return O}h.prototype.slice=function(n,o){const _=this.length;n=~~n,o=o===void 0?_:~~o,n<0?(n+=_,n<0&&(n=0)):n>_&&(n=_),o<0?(o+=_,o<0&&(o=0)):o>_&&(o=_),o<n&&(o=n);const O=this.subarray(n,o);return Object.setPrototypeOf(O,h.prototype),O};function J(d,n,o){if(d%1!==0||d<0)throw new RangeError("offset is not uint");if(d+n>o)throw new RangeError("Trying to access beyond buffer length")}h.prototype.readUintLE=h.prototype.readUIntLE=function(n,o,_){n=n>>>0,o=o>>>0,_||J(n,o,this.length);let O=this[n],j=1,Y=0;for(;++Y<o&&(j*=256);)O+=this[n+Y]*j;return O},h.prototype.readUintBE=h.prototype.readUIntBE=function(n,o,_){n=n>>>0,o=o>>>0,_||J(n,o,this.length);let O=this[n+--o],j=1;for(;o>0&&(j*=256);)O+=this[n+--o]*j;return O},h.prototype.readUint8=h.prototype.readUInt8=function(n,o){return n=n>>>0,o||J(n,1,this.length),this[n]},h.prototype.readUint16LE=h.prototype.readUInt16LE=function(n,o){return n=n>>>0,o||J(n,2,this.length),this[n]|this[n+1]<<8},h.prototype.readUint16BE=h.prototype.readUInt16BE=function(n,o){return n=n>>>0,o||J(n,2,this.length),this[n]<<8|this[n+1]},h.prototype.readUint32LE=h.prototype.readUInt32LE=function(n,o){return n=n>>>0,o||J(n,4,this.length),(this[n]|this[n+1]<<8|this[n+2]<<16)+this[n+3]*16777216},h.prototype.readUint32BE=h.prototype.readUInt32BE=function(n,o){return n=n>>>0,o||J(n,4,this.length),this[n]*16777216+(this[n+1]<<16|this[n+2]<<8|this[n+3])},h.prototype.readBigUInt64LE=Me(function(n){n=n>>>0,ie(n,"offset");const o=this[n],_=this[n+7];(o===void 0||_===void 0)&&se(n,this.length-8);const O=o+this[++n]*oe(2,8)+this[++n]*oe(2,16)+this[++n]*oe(2,24),j=this[++n]+this[++n]*oe(2,8)+this[++n]*oe(2,16)+_*oe(2,24);return BigInt(O)+(BigInt(j)<<BigInt(32))}),h.prototype.readBigUInt64BE=Me(function(n){n=n>>>0,ie(n,"offset");const o=this[n],_=this[n+7];(o===void 0||_===void 0)&&se(n,this.length-8);const O=o*oe(2,24)+this[++n]*oe(2,16)+this[++n]*oe(2,8)+this[++n],j=this[++n]*oe(2,24)+this[++n]*oe(2,16)+this[++n]*oe(2,8)+_;return(BigInt(O)<<BigInt(32))+BigInt(j)}),h.prototype.readIntLE=function(n,o,_){n=n>>>0,o=o>>>0,_||J(n,o,this.length);let O=this[n],j=1,Y=0;for(;++Y<o&&(j*=256);)O+=this[n+Y]*j;return j*=128,O>=j&&(O-=Math.pow(2,8*o)),O},h.prototype.readIntBE=function(n,o,_){n=n>>>0,o=o>>>0,_||J(n,o,this.length);let O=o,j=1,Y=this[n+--O];for(;O>0&&(j*=256);)Y+=this[n+--O]*j;return j*=128,Y>=j&&(Y-=Math.pow(2,8*o)),Y},h.prototype.readInt8=function(n,o){return n=n>>>0,o||J(n,1,this.length),this[n]&128?(255-this[n]+1)*-1:this[n]},h.prototype.readInt16LE=function(n,o){n=n>>>0,o||J(n,2,this.length);const _=this[n]|this[n+1]<<8;return _&32768?_|4294901760:_},h.prototype.readInt16BE=function(n,o){n=n>>>0,o||J(n,2,this.length);const _=this[n+1]|this[n]<<8;return _&32768?_|4294901760:_},h.prototype.readInt32LE=function(n,o){return n=n>>>0,o||J(n,4,this.length),this[n]|this[n+1]<<8|this[n+2]<<16|this[n+3]<<24},h.prototype.readInt32BE=function(n,o){return n=n>>>0,o||J(n,4,this.length),this[n]<<24|this[n+1]<<16|this[n+2]<<8|this[n+3]},h.prototype.readBigInt64LE=Me(function(n){n=n>>>0,ie(n,"offset");const o=this[n],_=this[n+7];(o===void 0||_===void 0)&&se(n,this.length-8);const O=this[n+4]+this[n+5]*oe(2,8)+this[n+6]*oe(2,16)+(_<<24);return(BigInt(O)<<BigInt(32))+BigInt(o+this[++n]*oe(2,8)+this[++n]*oe(2,16)+this[++n]*oe(2,24))}),h.prototype.readBigInt64BE=Me(function(n){n=n>>>0,ie(n,"offset");const o=this[n],_=this[n+7];(o===void 0||_===void 0)&&se(n,this.length-8);const O=(o<<24)+this[++n]*oe(2,16)+this[++n]*oe(2,8)+this[++n];return(BigInt(O)<<BigInt(32))+BigInt(this[++n]*oe(2,24)+this[++n]*oe(2,16)+this[++n]*oe(2,8)+_)}),h.prototype.readFloatLE=function(n,o){return n=n>>>0,o||J(n,4,this.length),t.read(this,n,!0,23,4)},h.prototype.readFloatBE=function(n,o){return n=n>>>0,o||J(n,4,this.length),t.read(this,n,!1,23,4)},h.prototype.readDoubleLE=function(n,o){return n=n>>>0,o||J(n,8,this.length),t.read(this,n,!0,52,8)},h.prototype.readDoubleBE=function(n,o){return n=n>>>0,o||J(n,8,this.length),t.read(this,n,!1,52,8)};function ne(d,n,o,_,O,j){if(!h.isBuffer(d))throw new TypeError('"buffer" argument must be a Buffer instance');if(n>O||n<j)throw new RangeError('"value" argument is out of bounds');if(o+_>d.length)throw new RangeError("Index out of range")}h.prototype.writeUintLE=h.prototype.writeUIntLE=function(n,o,_,O){if(n=+n,o=o>>>0,_=_>>>0,!O){const ce=Math.pow(2,8*_)-1;ne(this,n,o,_,ce,0)}let j=1,Y=0;for(this[o]=n&255;++Y<_&&(j*=256);)this[o+Y]=n/j&255;return o+_},h.prototype.writeUintBE=h.prototype.writeUIntBE=function(n,o,_,O){if(n=+n,o=o>>>0,_=_>>>0,!O){const ce=Math.pow(2,8*_)-1;ne(this,n,o,_,ce,0)}let j=_-1,Y=1;for(this[o+j]=n&255;--j>=0&&(Y*=256);)this[o+j]=n/Y&255;return o+_},h.prototype.writeUint8=h.prototype.writeUInt8=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,1,255,0),this[o]=n&255,o+1},h.prototype.writeUint16LE=h.prototype.writeUInt16LE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,2,65535,0),this[o]=n&255,this[o+1]=n>>>8,o+2},h.prototype.writeUint16BE=h.prototype.writeUInt16BE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,2,65535,0),this[o]=n>>>8,this[o+1]=n&255,o+2},h.prototype.writeUint32LE=h.prototype.writeUInt32LE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,4,4294967295,0),this[o+3]=n>>>24,this[o+2]=n>>>16,this[o+1]=n>>>8,this[o]=n&255,o+4},h.prototype.writeUint32BE=h.prototype.writeUInt32BE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,4,4294967295,0),this[o]=n>>>24,this[o+1]=n>>>16,this[o+2]=n>>>8,this[o+3]=n&255,o+4};function D(d,n,o,_,O){le(n,_,O,d,o,7);let j=Number(n&BigInt(4294967295));d[o++]=j,j=j>>8,d[o++]=j,j=j>>8,d[o++]=j,j=j>>8,d[o++]=j;let Y=Number(n>>BigInt(32)&BigInt(4294967295));return d[o++]=Y,Y=Y>>8,d[o++]=Y,Y=Y>>8,d[o++]=Y,Y=Y>>8,d[o++]=Y,o}function F(d,n,o,_,O){le(n,_,O,d,o,7);let j=Number(n&BigInt(4294967295));d[o+7]=j,j=j>>8,d[o+6]=j,j=j>>8,d[o+5]=j,j=j>>8,d[o+4]=j;let Y=Number(n>>BigInt(32)&BigInt(4294967295));return d[o+3]=Y,Y=Y>>8,d[o+2]=Y,Y=Y>>8,d[o+1]=Y,Y=Y>>8,d[o]=Y,o+8}h.prototype.writeBigUInt64LE=Me(function(n,o=0){return D(this,n,o,BigInt(0),BigInt("0xffffffffffffffff"))}),h.prototype.writeBigUInt64BE=Me(function(n,o=0){return F(this,n,o,BigInt(0),BigInt("0xffffffffffffffff"))}),h.prototype.writeIntLE=function(n,o,_,O){if(n=+n,o=o>>>0,!O){const be=Math.pow(2,8*_-1);ne(this,n,o,_,be-1,-be)}let j=0,Y=1,ce=0;for(this[o]=n&255;++j<_&&(Y*=256);)n<0&&ce===0&&this[o+j-1]!==0&&(ce=1),this[o+j]=(n/Y>>0)-ce&255;return o+_},h.prototype.writeIntBE=function(n,o,_,O){if(n=+n,o=o>>>0,!O){const be=Math.pow(2,8*_-1);ne(this,n,o,_,be-1,-be)}let j=_-1,Y=1,ce=0;for(this[o+j]=n&255;--j>=0&&(Y*=256);)n<0&&ce===0&&this[o+j+1]!==0&&(ce=1),this[o+j]=(n/Y>>0)-ce&255;return o+_},h.prototype.writeInt8=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,1,127,-128),n<0&&(n=255+n+1),this[o]=n&255,o+1},h.prototype.writeInt16LE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,2,32767,-32768),this[o]=n&255,this[o+1]=n>>>8,o+2},h.prototype.writeInt16BE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,2,32767,-32768),this[o]=n>>>8,this[o+1]=n&255,o+2},h.prototype.writeInt32LE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,4,2147483647,-2147483648),this[o]=n&255,this[o+1]=n>>>8,this[o+2]=n>>>16,this[o+3]=n>>>24,o+4},h.prototype.writeInt32BE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,4,2147483647,-2147483648),n<0&&(n=4294967295+n+1),this[o]=n>>>24,this[o+1]=n>>>16,this[o+2]=n>>>8,this[o+3]=n&255,o+4},h.prototype.writeBigInt64LE=Me(function(n,o=0){return D(this,n,o,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),h.prototype.writeBigInt64BE=Me(function(n,o=0){return F(this,n,o,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function G(d,n,o,_,O,j){if(o+_>d.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("Index out of range")}function Z(d,n,o,_,O){return n=+n,o=o>>>0,O||G(d,n,o,4),t.write(d,n,o,_,23,4),o+4}h.prototype.writeFloatLE=function(n,o,_){return Z(this,n,o,!0,_)},h.prototype.writeFloatBE=function(n,o,_){return Z(this,n,o,!1,_)};function Q(d,n,o,_,O){return n=+n,o=o>>>0,O||G(d,n,o,8),t.write(d,n,o,_,52,8),o+8}h.prototype.writeDoubleLE=function(n,o,_){return Q(this,n,o,!0,_)},h.prototype.writeDoubleBE=function(n,o,_){return Q(this,n,o,!1,_)},h.prototype.copy=function(n,o,_,O){if(!h.isBuffer(n))throw new TypeError("argument should be a Buffer");if(_||(_=0),!O&&O!==0&&(O=this.length),o>=n.length&&(o=n.length),o||(o=0),O>0&&O<_&&(O=_),O===_||n.length===0||this.length===0)return 0;if(o<0)throw new RangeError("targetStart out of bounds");if(_<0||_>=this.length)throw new RangeError("Index out of range");if(O<0)throw new RangeError("sourceEnd out of bounds");O>this.length&&(O=this.length),n.length-o<O-_&&(O=n.length-o+_);const j=O-_;return this===n&&typeof l.prototype.copyWithin=="function"?this.copyWithin(o,_,O):l.prototype.set.call(n,this.subarray(_,O),o),j},h.prototype.fill=function(n,o,_,O){if(typeof n=="string"){if(typeof o=="string"?(O=o,o=0,_=this.length):typeof _=="string"&&(O=_,_=this.length),O!==void 0&&typeof O!="string")throw new TypeError("encoding must be a string");if(typeof O=="string"&&!h.isEncoding(O))throw new TypeError("Unknown encoding: "+O);if(n.length===1){const Y=n.charCodeAt(0);(O==="utf8"&&Y<128||O==="latin1")&&(n=Y)}}else typeof n=="number"?n=n&255:typeof n=="boolean"&&(n=Number(n));if(o<0||this.length<o||this.length<_)throw new RangeError("Out of range index");if(_<=o)return this;o=o>>>0,_=_===void 0?this.length:_>>>0,n||(n=0);let j;if(typeof n=="number")for(j=o;j<_;++j)this[j]=n;else{const Y=h.isBuffer(n)?n:h.from(n,O),ce=Y.length;if(ce===0)throw new TypeError('The value "'+n+'" is invalid for argument "value"');for(j=0;j<_-o;++j)this[j+o]=Y[j%ce]}return this};const y={};function w(d,n,o){y[d]=class extends o{constructor(){super(),Object.defineProperty(this,"message",{value:n.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${d}]`,this.stack,delete this.name}get code(){return d}set code(O){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:O,writable:!0})}toString(){return`${this.name} [${d}]: ${this.message}`}}}w("ERR_BUFFER_OUT_OF_BOUNDS",function(d){return d?`${d} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),w("ERR_INVALID_ARG_TYPE",function(d,n){return`The "${d}" argument must be of type number. Received type ${typeof n}`},TypeError),w("ERR_OUT_OF_RANGE",function(d,n,o){let _=`The value of "${d}" is out of range.`,O=o;return Number.isInteger(o)&&Math.abs(o)>oe(2,32)?O=z(String(o)):typeof o=="bigint"&&(O=String(o),(o>oe(BigInt(2),BigInt(32))||o<-oe(BigInt(2),BigInt(32)))&&(O=z(O)),O+="n"),_+=` It must be ${n}. Received ${O}`,_},RangeError);function z(d){let n="",o=d.length;const _=d[0]==="-"?1:0;for(;o>=_+4;o-=3)n=`_${d.slice(o-3,o)}${n}`;return`${d.slice(0,o)}${n}`}function ee(d,n,o){ie(n,"offset"),(d[n]===void 0||d[n+o]===void 0)&&se(n,d.length-(o+1))}function le(d,n,o,_,O,j){if(d>o||d<n){const Y=typeof n=="bigint"?"n":"";let ce;throw n===0||n===BigInt(0)?ce=`>= 0${Y} and < 2${Y} ** ${(j+1)*8}${Y}`:ce=`>= -(2${Y} ** ${(j+1)*8-1}${Y}) and < 2 ** ${(j+1)*8-1}${Y}`,new y.ERR_OUT_OF_RANGE("value",ce,d)}ee(_,O,j)}function ie(d,n){if(typeof d!="number")throw new y.ERR_INVALID_ARG_TYPE(n,"number",d)}function se(d,n,o){throw Math.floor(d)!==d?(ie(d,o),new y.ERR_OUT_OF_RANGE("offset","an integer",d)):n<0?new y.ERR_BUFFER_OUT_OF_BOUNDS:new y.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${n}`,d)}const De=/[^+/0-9A-Za-z-_]/g;function H(d){if(d=d.split("=")[0],d=d.trim().replace(De,""),d.length<2)return"";for(;d.length%4!==0;)d=d+"=";return d}function Fe(d,n){n=n||1/0;let o;const _=d.length;let O=null;const j=[];for(let Y=0;Y<_;++Y){if(o=d.charCodeAt(Y),o>55295&&o<57344){if(!O){if(o>56319){(n-=3)>-1&&j.push(239,191,189);continue}else if(Y+1===_){(n-=3)>-1&&j.push(239,191,189);continue}O=o;continue}if(o<56320){(n-=3)>-1&&j.push(239,191,189),O=o;continue}o=(O-55296<<10|o-56320)+65536}else O&&(n-=3)>-1&&j.push(239,191,189);if(O=null,o<128){if((n-=1)<0)break;j.push(o)}else if(o<2048){if((n-=2)<0)break;j.push(o>>6|192,o&63|128)}else if(o<65536){if((n-=3)<0)break;j.push(o>>12|224,o>>6&63|128,o&63|128)}else if(o<1114112){if((n-=4)<0)break;j.push(o>>18|240,o>>12&63|128,o>>6&63|128,o&63|128)}else throw new Error("Invalid code point")}return j}function Ue(d){const n=[];for(let o=0;o<d.length;++o)n.push(d.charCodeAt(o)&255);return n}function ye(d,n){let o,_,O;const j=[];for(let Y=0;Y<d.length&&!((n-=2)<0);++Y)o=d.charCodeAt(Y),_=o>>8,O=o%256,j.push(O),j.push(_);return j}function we(d){return e.toByteArray(H(d))}function $e(d,n,o,_){let O;for(O=0;O<_&&!(O+o>=n.length||O>=d.length);++O)n[O+o]=d[O];return O}function Ne(d,n){return d instanceof n||d!=null&&d.constructor!=null&&d.constructor.name!=null&&d.constructor.name===n.name}function We(d){return d!==d}const Ve=function(){const d="0123456789abcdef",n=new Array(256);for(let o=0;o<16;++o){const _=o*16;for(let O=0;O<16;++O)n[_+O]=d[o]+d[O]}return n}();function Me(d){return typeof BigInt=="undefined"?tt:d}function tt(){throw new Error("BigInt not supported")}})(Fn);const ua=Fn.Buffer;if(typeof ae=="undefined"?globalThis.process={env:{},browser:!0,version:"v18.0.0",platform:"browser",arch:"x64",versions:{node:"18.0.0"},nextTick:(r,...e)=>{if(typeof r!="function")throw new TypeError("nextTick callback must be a function");if(typeof MessageChannel!="undefined"){const t=new MessageChannel;t.port2.onmessage=()=>{try{r(...e)}catch(s){setTimeout(()=>{throw s},0)}},t.port1.postMessage(null)}else setTimeout(()=>{try{r(...e)}catch(t){setTimeout(()=>{throw t},0)}},0)},cwd:()=>"/",chdir:()=>{},umask:()=>0}:typeof ae.nextTick=="undefined"&&(ae.nextTick=(r,...e)=>{if(typeof r!="function")throw new TypeError("nextTick callback must be a function");if(typeof MessageChannel!="undefined"){const t=new MessageChannel;t.port2.onmessage=()=>{try{r(...e)}catch(s){setTimeout(()=>{throw s},0)}},t.port1.postMessage(null)}else setTimeout(()=>{try{r(...e)}catch(t){setTimeout(()=>{throw t},0)}},0)}),typeof globalThis=="undefined"&&(globalThis.global=globalThis),typeof ua=="undefined"){let r=null;try{typeof require!="undefined"&&(r=require("buffer").Buffer)}catch(e){}r?globalThis.Buffer=r:globalThis.Buffer={isBuffer:e=>!1,from:e=>new Uint8Array(e),alloc:e=>new Uint8Array(e),allocUnsafe:e=>new Uint8Array(e)}}typeof setImmediate=="undefined"&&(globalThis.setImmediate=(r,...e)=>setTimeout(()=>r(...e),0)),typeof clearImmediate=="undefined"&&(globalThis.clearImmediate=r=>{clearTimeout(r)});var fa=Object.defineProperty,ha=(r,e,t)=>e in r?fa(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,it=(r,e,t)=>ha(r,typeof e!="symbol"?e+"":e,t),Ke=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class $n{constructor(e,t,s="/apis/video-call"){it(this,"socket",null),it(this,"serverUrl"),it(this,"socketPath"),it(this,"token"),it(this,"connected",!1),it(this,"reconnectAttempts",0),it(this,"maxReconnectAttempts",5),this.serverUrl=e,this.token=t,this.socketPath=s}connect(){return Ke(this,null,function*(){return this.socket&&this.socket.connected?Promise.resolve():(this.socket&&(this.socket.removeAllListeners(),this.socket.disconnect(),this.socket=null),new Promise((e,t)=>{try{this.socket=ge.io(this.serverUrl,{path:this.socketPath,transports:["websocket","polling"],timeout:1e4,forceNew:!0,auth:{token:this.token}}),this.socket.on("connect",()=>{this.connected=!0,this.reconnectAttempts=0,console.log("[CallSocket] Connected to signaling server"),e()}),this.socket.on("disconnect",s=>{this.connected=!1,console.log("[CallSocket] Disconnected:",s),this.handleDisconnection(s)}),this.socket.on("connect_error",s=>{console.error("[CallSocket] Connection error:",s),this.reconnectAttempts++,this.reconnectAttempts>=this.maxReconnectAttempts&&t(new Error(`Failed to connect after ${this.maxReconnectAttempts} attempts`))})}catch(s){t(s)}}))})}disconnect(){this.socket&&(this.socket.removeAllListeners(),this.socket.disconnect(),this.socket=null,this.connected=!1)}isConnected(){var e;return this.connected&&((e=this.socket)==null?void 0:e.connected)===!0}emit(e,t){var s;if(!this.isConnected())throw new Error("Socket not connected");console.log(`[CallSocket] Emitting ${e}:`,t),(s=this.socket)==null||s.emit(e,t,f=>{f!=null&&f.error&&console.error(`[CallSocket] Error in ${e}:`,f.error)})}emitWithResponse(e,t,s=1e4){return Ke(this,null,function*(){if(!this.isConnected())throw new Error("Socket not connected");return console.log(`[CallSocket] Emitting ${e} with response:`,t),new Promise((f,l)=>{var g;const u=setTimeout(()=>{l(new Error(`Timeout waiting for response to ${e}`))},s);console.log(`[CallSocket] about to emit: ${e}...`),(g=this.socket)==null||g.emit(e,t,c=>{clearTimeout(u),c!=null&&c.error?(console.error(`[CallSocket] Error in ${e}:`,c.error),l(new Error(c.error))):(console.log(`[CallSocket] Response for ${e}:`,c),f(c))})})})}on(e,t){if(!this.socket)throw new Error("Socket not connected");this.socket.on(e,t)}off(e,t){this.socket&&(t?this.socket.off(e,t):this.socket.removeAllListeners(e))}startCall(e){return Ke(this,null,function*(){return this.emitWithResponse("call.start",{roomId:e})})}joinRoom(e){return Ke(this,null,function*(){return this.emitWithResponse("call.join",{roomId:e})})}leaveCall(e){return Ke(this,null,function*(){return this.emitWithResponse("call.leave",{roomId:e})})}sendOffer(e,t,s){this.emit("call.offer",{to:e,offer:t,roomId:s})}sendAnswer(e,t,s){this.emit("call.answer",{to:e,answer:t,roomId:s})}sendCandidate(e,t,s){this.emit("call.candidate",{to:e,candidate:t,roomId:s})}sendStateUpdate(e,t,s){this.emit("call.state",{to:e,state:t,roomId:s})}endCall(e,t,s){this.emit("call.end",{roomId:s,targetUserId:e})}endCallForAll(e){return Ke(this,null,function*(){this.emit("call.end",{roomId:e})})}startRecording(e,t){return Ke(this,null,function*(){return this.emitWithResponse("call.recording.start",{roomId:e,recordingId:t})})}sendRecordingChunk(e,t,s){this.emit("call.recording.chunk",{roomId:e,recordingId:t,chunk:s})}endRecording(e,t){return Ke(this,null,function*(){return this.emitWithResponse("call.recording.end",{roomId:e,recordingId:t})})}sendTranscript(e,t){this.emit("call.transcript",{roomId:e,transcript:t,timestamp:Date.now()})}checkCallStatus(e){return Ke(this,null,function*(){return this.emitWithResponse("call.status",{roomId:e})})}getIceServers(e){return Ke(this,null,function*(){return this.emitWithResponse("call.ice-servers",{roomId:e})})}handleDisconnection(e){["transport close","transport error","io server disconnect"].includes(e)&&this.reconnectAttempts<this.maxReconnectAttempts&&setTimeout(()=>{this.connected||(console.log(`[CallSocket] Attempting to reconnect... (${this.reconnectAttempts+1}/${this.maxReconnectAttempts})`),this.connect().catch(console.error))},Math.pow(2,this.reconnectAttempts)*1e3)}getConnectionInfo(){var e,t;return{connected:this.connected,socketId:(e=this.socket)==null?void 0:e.id,transport:(t=this.socket)==null?void 0:t.io.engine.transport.name,reconnectAttempts:this.reconnectAttempts}}}var da=Object.defineProperty,pa=(r,e,t)=>e in r?da(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,gt=(r,e,t)=>pa(r,typeof e!="symbol"?e+"":e,t),Ct=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class jn{constructor(e={video:!0,audio:!0}){gt(this,"cameraStream",null),gt(this,"screenStream",null),gt(this,"videoElement",null),gt(this,"constraints"),gt(this,"isScreenShare",!1),this.constraints=e}initialize(){return Ct(this,null,function*(){try{return console.log("[CallMediaStream] Initializing media stream with constraints:",this.constraints),this.cameraStream=yield navigator.mediaDevices.getUserMedia(this.constraints),console.log("[CallMediaStream] Media stream initialized successfully"),this.cameraStream}catch(e){throw console.error("[CallMediaStream] Failed to initialize media stream:",e),this.handleMediaError(e)}})}startScreenShare(){return Ct(this,arguments,function*(e={video:!0,audio:!1}){try{return console.log("[CallMediaStream] Starting screen share"),this.screenStream=yield navigator.mediaDevices.getDisplayMedia({video:e.video,audio:e.audio}),this.isScreenShare=!0,this.screenStream.getVideoTracks()[0].addEventListener("ended",()=>{console.log("[CallMediaStream] Screen share ended by user"),this.stopScreenShare()}),console.log("[CallMediaStream] Screen share started successfully"),this.screenStream}catch(t){throw console.error("[CallMediaStream] Failed to start screen share:",t),this.handleMediaError(t)}})}stopScreenShare(){return Ct(this,null,function*(){try{if(console.log("[CallMediaStream] Stopping screen share"),this.screenStream&&this.isScreenShare&&(this.screenStream.getTracks().forEach(e=>e.stop()),this.screenStream=null),!this.cameraStream)this.cameraStream=yield this.initialize();else{const e=this.cameraStream.getVideoTracks();(e.length===0||e[0].readyState==="ended")&&(console.log("[CallMediaStream] Camera stream is inactive, reinitializing"),this.cameraStream=yield this.initialize())}return this.isScreenShare=!1,console.log("[CallMediaStream] Reverted to camera stream"),this.cameraStream}catch(e){throw console.error("[CallMediaStream] Failed to stop screen share:",e),this.handleMediaError(e)}})}toggleAudio(e){const t=this.getCurrentStream();if(!t){console.warn("[CallMediaStream] No stream available for audio toggle");return}t.getAudioTracks().forEach(f=>{f.enabled=e}),console.log(`[CallMediaStream] Audio ${e?"enabled":"disabled"}`)}toggleVideo(e){const t=this.getCurrentStream();if(!t){console.warn("[CallMediaStream] No stream available for video toggle");return}t.getVideoTracks().forEach(f=>{f.enabled=e}),console.log(`[CallMediaStream] Video ${e?"enabled":"disabled"}`)}createVideoElement(){const e=document.createElement("video");e.autoplay=!0,e.playsInline=!0,e.muted=!0;const t=this.getCurrentStream();return t&&(e.srcObject=t),this.videoElement=e,e}attachToVideoElement(e){const t=this.getCurrentStream();t&&(e.srcObject=t,this.videoElement=e)}replaceStream(e){const t=this.getCurrentStream();t&&t.getTracks().forEach(s=>s.stop()),this.isScreenShare?this.screenStream=e:this.cameraStream=e,this.videoElement&&(this.videoElement.srcObject=e),console.log("[CallMediaStream] Stream replaced successfully")}getCurrentStream(){return this.isScreenShare?this.screenStream:this.cameraStream}getStream(){return this.getCurrentStream()}getCameraStream(){return this.cameraStream}getScreenStream(){return this.screenStream}getVideoElement(){return this.videoElement}getIsScreenShare(){return this.isScreenShare}isAudioEnabled(){const e=this.getCurrentStream();if(!e)return!1;const t=e.getAudioTracks();return t.length>0&&t[0].enabled}isVideoEnabled(){const e=this.getCurrentStream();if(!e)return!1;const t=e.getVideoTracks();return t.length>0&&t[0].enabled}getStreamInfo(){const e=this.getCurrentStream();if(!e)return null;const t=e.getVideoTracks(),s=e.getAudioTracks();return{id:e.id,videoTracks:t.length,audioTracks:s.length,isScreenShare:this.isScreenShare,videoEnabled:t.length>0?t[0].enabled:!1,audioEnabled:s.length>0?s[0].enabled:!1,videoConstraints:t.length>0?t[0].getSettings():null,audioConstraints:s.length>0?s[0].getSettings():null,hasCameraStream:!!this.cameraStream,hasScreenStream:!!this.screenStream}}getVideoTrack(){const e=this.getCurrentStream();if(!e)return null;const t=e.getVideoTracks();return t.length>0?t[0]:null}getAudioTrack(){const e=this.getCurrentStream();if(!e)return null;const t=e.getAudioTracks();return t.length>0?t[0]:null}getCameraVideoTrack(){if(!this.cameraStream)return null;const e=this.cameraStream.getVideoTracks();return e.length>0?e[0]:null}getScreenVideoTrack(){if(!this.screenStream)return null;const e=this.screenStream.getVideoTracks();return e.length>0?e[0]:null}cleanup(){console.log("[CallMediaStream] Cleaning up media stream"),this.cameraStream&&(this.cameraStream.getTracks().forEach(e=>{e.stop()}),this.cameraStream=null),this.screenStream&&(this.screenStream.getTracks().forEach(e=>{e.stop()}),this.screenStream=null),this.videoElement&&(this.videoElement.srcObject=null,this.videoElement=null),this.isScreenShare=!1}handleMediaError(e){let t="Unknown media error";return e.name==="NotAllowedError"?t="Permission denied. Please allow camera and microphone access.":e.name==="NotFoundError"?t="No camera or microphone found. Please check your devices.":e.name==="NotReadableError"?t="Camera or microphone is already in use by another application.":e.name==="OverconstrainedError"?t="Camera or microphone does not support the requested constraints.":e.name==="SecurityError"?t="Media access blocked due to security restrictions.":e.name==="AbortError"&&(t="Media access was aborted."),new Error(`${t} (${e.name})`)}static getAvailableDevices(){return Ct(this,null,function*(){try{const e=yield navigator.mediaDevices.enumerateDevices();return{videoDevices:e.filter(t=>t.kind==="videoinput"),audioDevices:e.filter(t=>t.kind==="audioinput")}}catch(e){throw console.error("[CallMediaStream] Failed to get available devices:",e),e}})}static checkBrowserSupport(){return{getUserMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia),getDisplayMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia),webRTC:!!window.RTCPeerConnection}}}function xt(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Rt={exports:{}},Wt,qn;function ga(){if(qn)return Wt;qn=1;var r=1e3,e=r*60,t=e*60,s=t*24,f=s*7,l=s*365.25;Wt=function(h,I){I=I||{};var B=typeof h;if(B==="string"&&h.length>0)return g(h);if(B==="number"&&isFinite(h))return I.long?c(h):u(h);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(h))};function g(h){if(h=String(h),!(h.length>100)){var I=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(h);if(I){var B=parseFloat(I[1]),x=(I[2]||"ms").toLowerCase();switch(x){case"years":case"year":case"yrs":case"yr":case"y":return B*l;case"weeks":case"week":case"w":return B*f;case"days":case"day":case"d":return B*s;case"hours":case"hour":case"hrs":case"hr":case"h":return B*t;case"minutes":case"minute":case"mins":case"min":case"m":return B*e;case"seconds":case"second":case"secs":case"sec":case"s":return B*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return B;default:return}}}}function u(h){var I=Math.abs(h);return I>=s?Math.round(h/s)+"d":I>=t?Math.round(h/t)+"h":I>=e?Math.round(h/e)+"m":I>=r?Math.round(h/r)+"s":h+"ms"}function c(h){var I=Math.abs(h);return I>=s?v(h,I,s,"day"):I>=t?v(h,I,t,"hour"):I>=e?v(h,I,e,"minute"):I>=r?v(h,I,r,"second"):h+" ms"}function v(h,I,B,x){var b=I>=B*1.5;return Math.round(h/B)+" "+x+(b?"s":"")}return Wt}var Gt,xn;function ya(){if(xn)return Gt;xn=1;function r(e){s.debug=s,s.default=s,s.coerce=v,s.disable=u,s.enable=l,s.enabled=c,s.humanize=ga(),s.destroy=h,Object.keys(e).forEach(I=>{s[I]=e[I]}),s.names=[],s.skips=[],s.formatters={};function t(I){let B=0;for(let x=0;x<I.length;x++)B=(B<<5)-B+I.charCodeAt(x),B|=0;return s.colors[Math.abs(B)%s.colors.length]}s.selectColor=t;function s(I){let B,x=null,b,N;function T(...m){if(!T.enabled)return;const R=T,A=Number(new Date),P=A-(B||A);R.diff=P,R.prev=B,R.curr=A,B=A,m[0]=s.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let k=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(C,M)=>{if(C==="%%")return"%";k++;const W=s.formatters[M];if(typeof W=="function"){const X=m[k];C=W.call(R,X),m.splice(k,1),k--}return C}),s.formatArgs.call(R,m),(R.log||s.log).apply(R,m)}return T.namespace=I,T.useColors=s.useColors(),T.color=s.selectColor(I),T.extend=f,T.destroy=s.destroy,Object.defineProperty(T,"enabled",{enumerable:!0,configurable:!1,get:()=>x!==null?x:(b!==s.namespaces&&(b=s.namespaces,N=s.enabled(I)),N),set:m=>{x=m}}),typeof s.init=="function"&&s.init(T),T}function f(I,B){const x=s(this.namespace+(typeof B=="undefined"?":":B)+I);return x.log=this.log,x}function l(I){s.save(I),s.namespaces=I,s.names=[],s.skips=[];const B=(typeof I=="string"?I:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const x of B)x[0]==="-"?s.skips.push(x.slice(1)):s.names.push(x)}function g(I,B){let x=0,b=0,N=-1,T=0;for(;x<I.length;)if(b<B.length&&(B[b]===I[x]||B[b]==="*"))B[b]==="*"?(N=b,T=x,b++):(x++,b++);else if(N!==-1)b=N+1,T++,x=T;else return!1;for(;b<B.length&&B[b]==="*";)b++;return b===B.length}function u(){const I=[...s.names,...s.skips.map(B=>"-"+B)].join(",");return s.enable(""),I}function c(I){for(const B of s.skips)if(g(I,B))return!1;for(const B of s.names)if(g(I,B))return!0;return!1}function v(I){return I instanceof Error?I.stack||I.message:I}function h(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return s.enable(s.load()),s}return Gt=r,Gt}var Wn;function ma(){return Wn||(Wn=1,function(r,e){e.formatArgs=s,e.save=f,e.load=l,e.useColors=t,e.storage=g(),e.destroy=(()=>{let c=!1;return()=>{c||(c=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function t(){if(typeof window!="undefined"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let c;return typeof document!="undefined"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window!="undefined"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator!="undefined"&&navigator.userAgent&&(c=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(c[1],10)>=31||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function s(c){if(c[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+c[0]+(this.useColors?"%c ":" ")+"+"+r.exports.humanize(this.diff),!this.useColors)return;const v="color: "+this.color;c.splice(1,0,v,"color: inherit");let h=0,I=0;c[0].replace(/%[a-zA-Z%]/g,B=>{B!=="%%"&&(h++,B==="%c"&&(I=h))}),c.splice(I,0,v)}e.log=console.debug||console.log||(()=>{});function f(c){try{c?e.storage.setItem("debug",c):e.storage.removeItem("debug")}catch(v){}}function l(){let c;try{c=e.storage.getItem("debug")||e.storage.getItem("DEBUG")}catch(v){}return!c&&typeof ae!="undefined"&&"env"in ae&&(c=ae.env.DEBUG),c}function g(){try{return localStorage}catch(c){}}r.exports=ya()(e);const{formatters:u}=r.exports;u.j=function(c){try{return JSON.stringify(c)}catch(v){return"[UnexpectedJSONParseError]: "+v.message}}}(Rt,Rt.exports)),Rt.exports}var Vt,Gn;function va(){return Gn||(Gn=1,Vt=function(){if(typeof globalThis=="undefined")return null;var e={RTCPeerConnection:globalThis.RTCPeerConnection||globalThis.mozRTCPeerConnection||globalThis.webkitRTCPeerConnection,RTCSessionDescription:globalThis.RTCSessionDescription||globalThis.mozRTCSessionDescription||globalThis.webkitRTCSessionDescription,RTCIceCandidate:globalThis.RTCIceCandidate||globalThis.mozRTCIceCandidate||globalThis.webkitRTCIceCandidate};return e.RTCPeerConnection?e:null}),Vt}var Pt={exports:{}},Tt={exports:{}},zt={},Vn;function yt(){return Vn||(Vn=1,function(r){Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e={},t={};t.byteLength=h,t.toByteArray=B,t.fromByteArray=N;for(var s=[],f=[],l=typeof Uint8Array!="undefined"?Uint8Array:Array,g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,c=g.length;u<c;++u)s[u]=g[u],f[g.charCodeAt(u)]=u;f[45]=62,f[95]=63;function v(R){var A=R.length;if(A%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var P=R.indexOf("=");P===-1&&(P=A);var k=P===A?0:4-P%4;return[P,k]}function h(R){var A=v(R),P=A[0],k=A[1];return(P+k)*3/4-k}function I(R,A,P){return(A+P)*3/4-P}function B(R){var A,P=v(R),k=P[0],S=P[1],C=new l(I(R,k,S)),M=0,W=S>0?k-4:k,X;for(X=0;X<W;X+=4)A=f[R.charCodeAt(X)]<<18|f[R.charCodeAt(X+1)]<<12|f[R.charCodeAt(X+2)]<<6|f[R.charCodeAt(X+3)],C[M++]=A>>16&255,C[M++]=A>>8&255,C[M++]=A&255;return S===2&&(A=f[R.charCodeAt(X)]<<2|f[R.charCodeAt(X+1)]>>4,C[M++]=A&255),S===1&&(A=f[R.charCodeAt(X)]<<10|f[R.charCodeAt(X+1)]<<4|f[R.charCodeAt(X+2)]>>2,C[M++]=A>>8&255,C[M++]=A&255),C}function x(R){return s[R>>18&63]+s[R>>12&63]+s[R>>6&63]+s[R&63]}function b(R,A,P){for(var k,S=[],C=A;C<P;C+=3)k=(R[C]<<16&16711680)+(R[C+1]<<8&65280)+(R[C+2]&255),S.push(x(k));return S.join("")}function N(R){for(var A,P=R.length,k=P%3,S=[],C=16383,M=0,W=P-k;M<W;M+=C)S.push(b(R,M,M+C>W?W:M+C));return k===1?(A=R[P-1],S.push(s[A>>2]+s[A<<4&63]+"==")):k===2&&(A=(R[P-2]<<8)+R[P-1],S.push(s[A>>10]+s[A>>4&63]+s[A<<2&63]+"=")),S.join("")}var T={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */T.read=function(R,A,P,k,S){var C,M,W=S*8-k-1,X=(1<<W)-1,re=X>>1,U=-7,he=P?S-1:0,de=P?-1:1,me=R[A+he];for(he+=de,C=me&(1<<-U)-1,me>>=-U,U+=W;U>0;C=C*256+R[A+he],he+=de,U-=8);for(M=C&(1<<-U)-1,C>>=-U,U+=k;U>0;M=M*256+R[A+he],he+=de,U-=8);if(C===0)C=1-re;else{if(C===X)return M?NaN:(me?-1:1)*(1/0);M=M+Math.pow(2,k),C=C-re}return(me?-1:1)*M*Math.pow(2,C-k)},T.write=function(R,A,P,k,S,C){var M,W,X,re=C*8-S-1,U=(1<<re)-1,he=U>>1,de=S===23?Math.pow(2,-24)-Math.pow(2,-77):0,me=k?0:C-1,Pe=k?1:-1,ke=A<0||A===0&&1/A<0?1:0;for(A=Math.abs(A),isNaN(A)||A===1/0?(W=isNaN(A)?1:0,M=U):(M=Math.floor(Math.log(A)/Math.LN2),A*(X=Math.pow(2,-M))<1&&(M--,X*=2),M+he>=1?A+=de/X:A+=de*Math.pow(2,1-he),A*X>=2&&(M++,X/=2),M+he>=U?(W=0,M=U):M+he>=1?(W=(A*X-1)*Math.pow(2,S),M=M+he):(W=A*Math.pow(2,he-1)*Math.pow(2,S),M=0));S>=8;R[P+me]=W&255,me+=Pe,W/=256,S-=8);for(M=M<<S|W,re+=S;re>0;R[P+me]=M&255,me+=Pe,M/=256,re-=8);R[P+me-Pe]|=ke*128};/*!
|
|
6
|
+
*/(function(r){const e=Et,t=qt,s=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;r.Buffer=h,r.SlowBuffer=k,r.INSPECT_MAX_BYTES=50;const f=2147483647;r.kMaxLength=f;const{Uint8Array:l,ArrayBuffer:g,SharedArrayBuffer:u}=globalThis;h.TYPED_ARRAY_SUPPORT=c(),!h.TYPED_ARRAY_SUPPORT&&typeof console!="undefined"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function c(){try{const d=new l(1),n={foo:function(){return 42}};return Object.setPrototypeOf(n,l.prototype),Object.setPrototypeOf(d,n),d.foo()===42}catch(d){return!1}}Object.defineProperty(h.prototype,"parent",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.buffer}}),Object.defineProperty(h.prototype,"offset",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.byteOffset}});function v(d){if(d>f)throw new RangeError('The value "'+d+'" is invalid for option "size"');const n=new l(d);return Object.setPrototypeOf(n,h.prototype),n}function h(d,n,o){if(typeof d=="number"){if(typeof n=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return b(d)}return I(d,n,o)}h.poolSize=8192;function I(d,n,o){if(typeof d=="string")return N(d,n);if(g.isView(d))return m(d);if(d==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof d);if(Ne(d,g)||d&&Ne(d.buffer,g)||typeof u!="undefined"&&(Ne(d,u)||d&&Ne(d.buffer,u)))return R(d,n,o);if(typeof d=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const _=d.valueOf&&d.valueOf();if(_!=null&&_!==d)return h.from(_,n,o);const O=A(d);if(O)return O;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof d[Symbol.toPrimitive]=="function")return h.from(d[Symbol.toPrimitive]("string"),n,o);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof d)}h.from=function(d,n,o){return I(d,n,o)},Object.setPrototypeOf(h.prototype,l.prototype),Object.setPrototypeOf(h,l);function B(d){if(typeof d!="number")throw new TypeError('"size" argument must be of type number');if(d<0)throw new RangeError('The value "'+d+'" is invalid for option "size"')}function x(d,n,o){return B(d),d<=0?v(d):n!==void 0?typeof o=="string"?v(d).fill(n,o):v(d).fill(n):v(d)}h.alloc=function(d,n,o){return x(d,n,o)};function b(d){return B(d),v(d<0?0:P(d)|0)}h.allocUnsafe=function(d){return b(d)},h.allocUnsafeSlow=function(d){return b(d)};function N(d,n){if((typeof n!="string"||n==="")&&(n="utf8"),!h.isEncoding(n))throw new TypeError("Unknown encoding: "+n);const o=S(d,n)|0;let _=v(o);const O=_.write(d,n);return O!==o&&(_=_.slice(0,O)),_}function T(d){const n=d.length<0?0:P(d.length)|0,o=v(n);for(let _=0;_<n;_+=1)o[_]=d[_]&255;return o}function m(d){if(Ne(d,l)){const n=new l(d);return R(n.buffer,n.byteOffset,n.byteLength)}return T(d)}function R(d,n,o){if(n<0||d.byteLength<n)throw new RangeError('"offset" is outside of buffer bounds');if(d.byteLength<n+(o||0))throw new RangeError('"length" is outside of buffer bounds');let _;return n===void 0&&o===void 0?_=new l(d):o===void 0?_=new l(d,n):_=new l(d,n,o),Object.setPrototypeOf(_,h.prototype),_}function A(d){if(h.isBuffer(d)){const n=P(d.length)|0,o=v(n);return o.length===0||d.copy(o,0,0,n),o}if(d.length!==void 0)return typeof d.length!="number"||We(d.length)?v(0):T(d);if(d.type==="Buffer"&&Array.isArray(d.data))return T(d.data)}function P(d){if(d>=f)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f.toString(16)+" bytes");return d|0}function k(d){return+d!=d&&(d=0),h.alloc(+d)}h.isBuffer=function(n){return n!=null&&n._isBuffer===!0&&n!==h.prototype},h.compare=function(n,o){if(Ne(n,l)&&(n=h.from(n,n.offset,n.byteLength)),Ne(o,l)&&(o=h.from(o,o.offset,o.byteLength)),!h.isBuffer(n)||!h.isBuffer(o))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(n===o)return 0;let _=n.length,O=o.length;for(let j=0,Y=Math.min(_,O);j<Y;++j)if(n[j]!==o[j]){_=n[j],O=o[j];break}return _<O?-1:O<_?1:0},h.isEncoding=function(n){switch(String(n).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},h.concat=function(n,o){if(!Array.isArray(n))throw new TypeError('"list" argument must be an Array of Buffers');if(n.length===0)return h.alloc(0);let _;if(o===void 0)for(o=0,_=0;_<n.length;++_)o+=n[_].length;const O=h.allocUnsafe(o);let j=0;for(_=0;_<n.length;++_){let Y=n[_];if(Ne(Y,l))j+Y.length>O.length?(h.isBuffer(Y)||(Y=h.from(Y)),Y.copy(O,j)):l.prototype.set.call(O,Y,j);else if(h.isBuffer(Y))Y.copy(O,j);else throw new TypeError('"list" argument must be an Array of Buffers');j+=Y.length}return O};function S(d,n){if(h.isBuffer(d))return d.length;if(g.isView(d)||Ne(d,g))return d.byteLength;if(typeof d!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof d);const o=d.length,_=arguments.length>2&&arguments[2]===!0;if(!_&&o===0)return 0;let O=!1;for(;;)switch(n){case"ascii":case"latin1":case"binary":return o;case"utf8":case"utf-8":return Fe(d).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return o*2;case"hex":return o>>>1;case"base64":return we(d).length;default:if(O)return _?-1:Fe(d).length;n=(""+n).toLowerCase(),O=!0}}h.byteLength=S;function C(d,n,o){let _=!1;if((n===void 0||n<0)&&(n=0),n>this.length||((o===void 0||o>this.length)&&(o=this.length),o<=0)||(o>>>=0,n>>>=0,o<=n))return"";for(d||(d="utf8");;)switch(d){case"hex":return $(this,n,o);case"utf8":case"utf-8":return ke(this,n,o);case"ascii":return Oe(this,n,o);case"latin1":case"binary":return qe(this,n,o);case"base64":return Pe(this,n,o);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return V(this,n,o);default:if(_)throw new TypeError("Unknown encoding: "+d);d=(d+"").toLowerCase(),_=!0}}h.prototype._isBuffer=!0;function M(d,n,o){const _=d[n];d[n]=d[o],d[o]=_}h.prototype.swap16=function(){const n=this.length;if(n%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let o=0;o<n;o+=2)M(this,o,o+1);return this},h.prototype.swap32=function(){const n=this.length;if(n%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let o=0;o<n;o+=4)M(this,o,o+3),M(this,o+1,o+2);return this},h.prototype.swap64=function(){const n=this.length;if(n%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let o=0;o<n;o+=8)M(this,o,o+7),M(this,o+1,o+6),M(this,o+2,o+5),M(this,o+3,o+4);return this},h.prototype.toString=function(){const n=this.length;return n===0?"":arguments.length===0?ke(this,0,n):C.apply(this,arguments)},h.prototype.toLocaleString=h.prototype.toString,h.prototype.equals=function(n){if(!h.isBuffer(n))throw new TypeError("Argument must be a Buffer");return this===n?!0:h.compare(this,n)===0},h.prototype.inspect=function(){let n="";const o=r.INSPECT_MAX_BYTES;return n=this.toString("hex",0,o).replace(/(.{2})/g,"$1 ").trim(),this.length>o&&(n+=" ... "),"<Buffer "+n+">"},s&&(h.prototype[s]=h.prototype.inspect),h.prototype.compare=function(n,o,_,O,j){if(Ne(n,l)&&(n=h.from(n,n.offset,n.byteLength)),!h.isBuffer(n))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof n);if(o===void 0&&(o=0),_===void 0&&(_=n?n.length:0),O===void 0&&(O=0),j===void 0&&(j=this.length),o<0||_>n.length||O<0||j>this.length)throw new RangeError("out of range index");if(O>=j&&o>=_)return 0;if(O>=j)return-1;if(o>=_)return 1;if(o>>>=0,_>>>=0,O>>>=0,j>>>=0,this===n)return 0;let Y=j-O,ce=_-o;const be=Math.min(Y,ce),Se=this.slice(O,j),Ce=n.slice(o,_);for(let pe=0;pe<be;++pe)if(Se[pe]!==Ce[pe]){Y=Se[pe],ce=Ce[pe];break}return Y<ce?-1:ce<Y?1:0};function W(d,n,o,_,O){if(d.length===0)return-1;if(typeof o=="string"?(_=o,o=0):o>2147483647?o=2147483647:o<-2147483648&&(o=-2147483648),o=+o,We(o)&&(o=O?0:d.length-1),o<0&&(o=d.length+o),o>=d.length){if(O)return-1;o=d.length-1}else if(o<0)if(O)o=0;else return-1;if(typeof n=="string"&&(n=h.from(n,_)),h.isBuffer(n))return n.length===0?-1:X(d,n,o,_,O);if(typeof n=="number")return n=n&255,typeof l.prototype.indexOf=="function"?O?l.prototype.indexOf.call(d,n,o):l.prototype.lastIndexOf.call(d,n,o):X(d,[n],o,_,O);throw new TypeError("val must be string, number or Buffer")}function X(d,n,o,_,O){let j=1,Y=d.length,ce=n.length;if(_!==void 0&&(_=String(_).toLowerCase(),_==="ucs2"||_==="ucs-2"||_==="utf16le"||_==="utf-16le")){if(d.length<2||n.length<2)return-1;j=2,Y/=2,ce/=2,o/=2}function be(Ce,pe){return j===1?Ce[pe]:Ce.readUInt16BE(pe*j)}let Se;if(O){let Ce=-1;for(Se=o;Se<Y;Se++)if(be(d,Se)===be(n,Ce===-1?0:Se-Ce)){if(Ce===-1&&(Ce=Se),Se-Ce+1===ce)return Ce*j}else Ce!==-1&&(Se-=Se-Ce),Ce=-1}else for(o+ce>Y&&(o=Y-ce),Se=o;Se>=0;Se--){let Ce=!0;for(let pe=0;pe<ce;pe++)if(be(d,Se+pe)!==be(n,pe)){Ce=!1;break}if(Ce)return Se}return-1}h.prototype.includes=function(n,o,_){return this.indexOf(n,o,_)!==-1},h.prototype.indexOf=function(n,o,_){return W(this,n,o,_,!0)},h.prototype.lastIndexOf=function(n,o,_){return W(this,n,o,_,!1)};function re(d,n,o,_){o=Number(o)||0;const O=d.length-o;_?(_=Number(_),_>O&&(_=O)):_=O;const j=n.length;_>j/2&&(_=j/2);let Y;for(Y=0;Y<_;++Y){const ce=parseInt(n.substr(Y*2,2),16);if(We(ce))return Y;d[o+Y]=ce}return Y}function U(d,n,o,_){return $e(Fe(n,d.length-o),d,o,_)}function he(d,n,o,_){return $e(Ue(n),d,o,_)}function de(d,n,o,_){return $e(we(n),d,o,_)}function me(d,n,o,_){return $e(ye(n,d.length-o),d,o,_)}h.prototype.write=function(n,o,_,O){if(o===void 0)O="utf8",_=this.length,o=0;else if(_===void 0&&typeof o=="string")O=o,_=this.length,o=0;else if(isFinite(o))o=o>>>0,isFinite(_)?(_=_>>>0,O===void 0&&(O="utf8")):(O=_,_=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const j=this.length-o;if((_===void 0||_>j)&&(_=j),n.length>0&&(_<0||o<0)||o>this.length)throw new RangeError("Attempt to write outside buffer bounds");O||(O="utf8");let Y=!1;for(;;)switch(O){case"hex":return re(this,n,o,_);case"utf8":case"utf-8":return U(this,n,o,_);case"ascii":case"latin1":case"binary":return he(this,n,o,_);case"base64":return de(this,n,o,_);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return me(this,n,o,_);default:if(Y)throw new TypeError("Unknown encoding: "+O);O=(""+O).toLowerCase(),Y=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Pe(d,n,o){return n===0&&o===d.length?e.fromByteArray(d):e.fromByteArray(d.slice(n,o))}function ke(d,n,o){o=Math.min(d.length,o);const _=[];let O=n;for(;O<o;){const j=d[O];let Y=null,ce=j>239?4:j>223?3:j>191?2:1;if(O+ce<=o){let be,Se,Ce,pe;switch(ce){case 1:j<128&&(Y=j);break;case 2:be=d[O+1],(be&192)===128&&(pe=(j&31)<<6|be&63,pe>127&&(Y=pe));break;case 3:be=d[O+1],Se=d[O+2],(be&192)===128&&(Se&192)===128&&(pe=(j&15)<<12|(be&63)<<6|Se&63,pe>2047&&(pe<55296||pe>57343)&&(Y=pe));break;case 4:be=d[O+1],Se=d[O+2],Ce=d[O+3],(be&192)===128&&(Se&192)===128&&(Ce&192)===128&&(pe=(j&15)<<18|(be&63)<<12|(Se&63)<<6|Ce&63,pe>65535&&pe<1114112&&(Y=pe))}}Y===null?(Y=65533,ce=1):Y>65535&&(Y-=65536,_.push(Y>>>10&1023|55296),Y=56320|Y&1023),_.push(Y),O+=ce}return _e(_)}const Ee=4096;function _e(d){const n=d.length;if(n<=Ee)return String.fromCharCode.apply(String,d);let o="",_=0;for(;_<n;)o+=String.fromCharCode.apply(String,d.slice(_,_+=Ee));return o}function Oe(d,n,o){let _="";o=Math.min(d.length,o);for(let O=n;O<o;++O)_+=String.fromCharCode(d[O]&127);return _}function qe(d,n,o){let _="";o=Math.min(d.length,o);for(let O=n;O<o;++O)_+=String.fromCharCode(d[O]);return _}function $(d,n,o){const _=d.length;(!n||n<0)&&(n=0),(!o||o<0||o>_)&&(o=_);let O="";for(let j=n;j<o;++j)O+=Ve[d[j]];return O}function V(d,n,o){const _=d.slice(n,o);let O="";for(let j=0;j<_.length-1;j+=2)O+=String.fromCharCode(_[j]+_[j+1]*256);return O}h.prototype.slice=function(n,o){const _=this.length;n=~~n,o=o===void 0?_:~~o,n<0?(n+=_,n<0&&(n=0)):n>_&&(n=_),o<0?(o+=_,o<0&&(o=0)):o>_&&(o=_),o<n&&(o=n);const O=this.subarray(n,o);return Object.setPrototypeOf(O,h.prototype),O};function J(d,n,o){if(d%1!==0||d<0)throw new RangeError("offset is not uint");if(d+n>o)throw new RangeError("Trying to access beyond buffer length")}h.prototype.readUintLE=h.prototype.readUIntLE=function(n,o,_){n=n>>>0,o=o>>>0,_||J(n,o,this.length);let O=this[n],j=1,Y=0;for(;++Y<o&&(j*=256);)O+=this[n+Y]*j;return O},h.prototype.readUintBE=h.prototype.readUIntBE=function(n,o,_){n=n>>>0,o=o>>>0,_||J(n,o,this.length);let O=this[n+--o],j=1;for(;o>0&&(j*=256);)O+=this[n+--o]*j;return O},h.prototype.readUint8=h.prototype.readUInt8=function(n,o){return n=n>>>0,o||J(n,1,this.length),this[n]},h.prototype.readUint16LE=h.prototype.readUInt16LE=function(n,o){return n=n>>>0,o||J(n,2,this.length),this[n]|this[n+1]<<8},h.prototype.readUint16BE=h.prototype.readUInt16BE=function(n,o){return n=n>>>0,o||J(n,2,this.length),this[n]<<8|this[n+1]},h.prototype.readUint32LE=h.prototype.readUInt32LE=function(n,o){return n=n>>>0,o||J(n,4,this.length),(this[n]|this[n+1]<<8|this[n+2]<<16)+this[n+3]*16777216},h.prototype.readUint32BE=h.prototype.readUInt32BE=function(n,o){return n=n>>>0,o||J(n,4,this.length),this[n]*16777216+(this[n+1]<<16|this[n+2]<<8|this[n+3])},h.prototype.readBigUInt64LE=Me(function(n){n=n>>>0,ie(n,"offset");const o=this[n],_=this[n+7];(o===void 0||_===void 0)&&se(n,this.length-8);const O=o+this[++n]*oe(2,8)+this[++n]*oe(2,16)+this[++n]*oe(2,24),j=this[++n]+this[++n]*oe(2,8)+this[++n]*oe(2,16)+_*oe(2,24);return BigInt(O)+(BigInt(j)<<BigInt(32))}),h.prototype.readBigUInt64BE=Me(function(n){n=n>>>0,ie(n,"offset");const o=this[n],_=this[n+7];(o===void 0||_===void 0)&&se(n,this.length-8);const O=o*oe(2,24)+this[++n]*oe(2,16)+this[++n]*oe(2,8)+this[++n],j=this[++n]*oe(2,24)+this[++n]*oe(2,16)+this[++n]*oe(2,8)+_;return(BigInt(O)<<BigInt(32))+BigInt(j)}),h.prototype.readIntLE=function(n,o,_){n=n>>>0,o=o>>>0,_||J(n,o,this.length);let O=this[n],j=1,Y=0;for(;++Y<o&&(j*=256);)O+=this[n+Y]*j;return j*=128,O>=j&&(O-=Math.pow(2,8*o)),O},h.prototype.readIntBE=function(n,o,_){n=n>>>0,o=o>>>0,_||J(n,o,this.length);let O=o,j=1,Y=this[n+--O];for(;O>0&&(j*=256);)Y+=this[n+--O]*j;return j*=128,Y>=j&&(Y-=Math.pow(2,8*o)),Y},h.prototype.readInt8=function(n,o){return n=n>>>0,o||J(n,1,this.length),this[n]&128?(255-this[n]+1)*-1:this[n]},h.prototype.readInt16LE=function(n,o){n=n>>>0,o||J(n,2,this.length);const _=this[n]|this[n+1]<<8;return _&32768?_|4294901760:_},h.prototype.readInt16BE=function(n,o){n=n>>>0,o||J(n,2,this.length);const _=this[n+1]|this[n]<<8;return _&32768?_|4294901760:_},h.prototype.readInt32LE=function(n,o){return n=n>>>0,o||J(n,4,this.length),this[n]|this[n+1]<<8|this[n+2]<<16|this[n+3]<<24},h.prototype.readInt32BE=function(n,o){return n=n>>>0,o||J(n,4,this.length),this[n]<<24|this[n+1]<<16|this[n+2]<<8|this[n+3]},h.prototype.readBigInt64LE=Me(function(n){n=n>>>0,ie(n,"offset");const o=this[n],_=this[n+7];(o===void 0||_===void 0)&&se(n,this.length-8);const O=this[n+4]+this[n+5]*oe(2,8)+this[n+6]*oe(2,16)+(_<<24);return(BigInt(O)<<BigInt(32))+BigInt(o+this[++n]*oe(2,8)+this[++n]*oe(2,16)+this[++n]*oe(2,24))}),h.prototype.readBigInt64BE=Me(function(n){n=n>>>0,ie(n,"offset");const o=this[n],_=this[n+7];(o===void 0||_===void 0)&&se(n,this.length-8);const O=(o<<24)+this[++n]*oe(2,16)+this[++n]*oe(2,8)+this[++n];return(BigInt(O)<<BigInt(32))+BigInt(this[++n]*oe(2,24)+this[++n]*oe(2,16)+this[++n]*oe(2,8)+_)}),h.prototype.readFloatLE=function(n,o){return n=n>>>0,o||J(n,4,this.length),t.read(this,n,!0,23,4)},h.prototype.readFloatBE=function(n,o){return n=n>>>0,o||J(n,4,this.length),t.read(this,n,!1,23,4)},h.prototype.readDoubleLE=function(n,o){return n=n>>>0,o||J(n,8,this.length),t.read(this,n,!0,52,8)},h.prototype.readDoubleBE=function(n,o){return n=n>>>0,o||J(n,8,this.length),t.read(this,n,!1,52,8)};function ne(d,n,o,_,O,j){if(!h.isBuffer(d))throw new TypeError('"buffer" argument must be a Buffer instance');if(n>O||n<j)throw new RangeError('"value" argument is out of bounds');if(o+_>d.length)throw new RangeError("Index out of range")}h.prototype.writeUintLE=h.prototype.writeUIntLE=function(n,o,_,O){if(n=+n,o=o>>>0,_=_>>>0,!O){const ce=Math.pow(2,8*_)-1;ne(this,n,o,_,ce,0)}let j=1,Y=0;for(this[o]=n&255;++Y<_&&(j*=256);)this[o+Y]=n/j&255;return o+_},h.prototype.writeUintBE=h.prototype.writeUIntBE=function(n,o,_,O){if(n=+n,o=o>>>0,_=_>>>0,!O){const ce=Math.pow(2,8*_)-1;ne(this,n,o,_,ce,0)}let j=_-1,Y=1;for(this[o+j]=n&255;--j>=0&&(Y*=256);)this[o+j]=n/Y&255;return o+_},h.prototype.writeUint8=h.prototype.writeUInt8=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,1,255,0),this[o]=n&255,o+1},h.prototype.writeUint16LE=h.prototype.writeUInt16LE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,2,65535,0),this[o]=n&255,this[o+1]=n>>>8,o+2},h.prototype.writeUint16BE=h.prototype.writeUInt16BE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,2,65535,0),this[o]=n>>>8,this[o+1]=n&255,o+2},h.prototype.writeUint32LE=h.prototype.writeUInt32LE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,4,4294967295,0),this[o+3]=n>>>24,this[o+2]=n>>>16,this[o+1]=n>>>8,this[o]=n&255,o+4},h.prototype.writeUint32BE=h.prototype.writeUInt32BE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,4,4294967295,0),this[o]=n>>>24,this[o+1]=n>>>16,this[o+2]=n>>>8,this[o+3]=n&255,o+4};function D(d,n,o,_,O){le(n,_,O,d,o,7);let j=Number(n&BigInt(4294967295));d[o++]=j,j=j>>8,d[o++]=j,j=j>>8,d[o++]=j,j=j>>8,d[o++]=j;let Y=Number(n>>BigInt(32)&BigInt(4294967295));return d[o++]=Y,Y=Y>>8,d[o++]=Y,Y=Y>>8,d[o++]=Y,Y=Y>>8,d[o++]=Y,o}function F(d,n,o,_,O){le(n,_,O,d,o,7);let j=Number(n&BigInt(4294967295));d[o+7]=j,j=j>>8,d[o+6]=j,j=j>>8,d[o+5]=j,j=j>>8,d[o+4]=j;let Y=Number(n>>BigInt(32)&BigInt(4294967295));return d[o+3]=Y,Y=Y>>8,d[o+2]=Y,Y=Y>>8,d[o+1]=Y,Y=Y>>8,d[o]=Y,o+8}h.prototype.writeBigUInt64LE=Me(function(n,o=0){return D(this,n,o,BigInt(0),BigInt("0xffffffffffffffff"))}),h.prototype.writeBigUInt64BE=Me(function(n,o=0){return F(this,n,o,BigInt(0),BigInt("0xffffffffffffffff"))}),h.prototype.writeIntLE=function(n,o,_,O){if(n=+n,o=o>>>0,!O){const be=Math.pow(2,8*_-1);ne(this,n,o,_,be-1,-be)}let j=0,Y=1,ce=0;for(this[o]=n&255;++j<_&&(Y*=256);)n<0&&ce===0&&this[o+j-1]!==0&&(ce=1),this[o+j]=(n/Y>>0)-ce&255;return o+_},h.prototype.writeIntBE=function(n,o,_,O){if(n=+n,o=o>>>0,!O){const be=Math.pow(2,8*_-1);ne(this,n,o,_,be-1,-be)}let j=_-1,Y=1,ce=0;for(this[o+j]=n&255;--j>=0&&(Y*=256);)n<0&&ce===0&&this[o+j+1]!==0&&(ce=1),this[o+j]=(n/Y>>0)-ce&255;return o+_},h.prototype.writeInt8=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,1,127,-128),n<0&&(n=255+n+1),this[o]=n&255,o+1},h.prototype.writeInt16LE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,2,32767,-32768),this[o]=n&255,this[o+1]=n>>>8,o+2},h.prototype.writeInt16BE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,2,32767,-32768),this[o]=n>>>8,this[o+1]=n&255,o+2},h.prototype.writeInt32LE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,4,2147483647,-2147483648),this[o]=n&255,this[o+1]=n>>>8,this[o+2]=n>>>16,this[o+3]=n>>>24,o+4},h.prototype.writeInt32BE=function(n,o,_){return n=+n,o=o>>>0,_||ne(this,n,o,4,2147483647,-2147483648),n<0&&(n=4294967295+n+1),this[o]=n>>>24,this[o+1]=n>>>16,this[o+2]=n>>>8,this[o+3]=n&255,o+4},h.prototype.writeBigInt64LE=Me(function(n,o=0){return D(this,n,o,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),h.prototype.writeBigInt64BE=Me(function(n,o=0){return F(this,n,o,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function G(d,n,o,_,O,j){if(o+_>d.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("Index out of range")}function Z(d,n,o,_,O){return n=+n,o=o>>>0,O||G(d,n,o,4),t.write(d,n,o,_,23,4),o+4}h.prototype.writeFloatLE=function(n,o,_){return Z(this,n,o,!0,_)},h.prototype.writeFloatBE=function(n,o,_){return Z(this,n,o,!1,_)};function Q(d,n,o,_,O){return n=+n,o=o>>>0,O||G(d,n,o,8),t.write(d,n,o,_,52,8),o+8}h.prototype.writeDoubleLE=function(n,o,_){return Q(this,n,o,!0,_)},h.prototype.writeDoubleBE=function(n,o,_){return Q(this,n,o,!1,_)},h.prototype.copy=function(n,o,_,O){if(!h.isBuffer(n))throw new TypeError("argument should be a Buffer");if(_||(_=0),!O&&O!==0&&(O=this.length),o>=n.length&&(o=n.length),o||(o=0),O>0&&O<_&&(O=_),O===_||n.length===0||this.length===0)return 0;if(o<0)throw new RangeError("targetStart out of bounds");if(_<0||_>=this.length)throw new RangeError("Index out of range");if(O<0)throw new RangeError("sourceEnd out of bounds");O>this.length&&(O=this.length),n.length-o<O-_&&(O=n.length-o+_);const j=O-_;return this===n&&typeof l.prototype.copyWithin=="function"?this.copyWithin(o,_,O):l.prototype.set.call(n,this.subarray(_,O),o),j},h.prototype.fill=function(n,o,_,O){if(typeof n=="string"){if(typeof o=="string"?(O=o,o=0,_=this.length):typeof _=="string"&&(O=_,_=this.length),O!==void 0&&typeof O!="string")throw new TypeError("encoding must be a string");if(typeof O=="string"&&!h.isEncoding(O))throw new TypeError("Unknown encoding: "+O);if(n.length===1){const Y=n.charCodeAt(0);(O==="utf8"&&Y<128||O==="latin1")&&(n=Y)}}else typeof n=="number"?n=n&255:typeof n=="boolean"&&(n=Number(n));if(o<0||this.length<o||this.length<_)throw new RangeError("Out of range index");if(_<=o)return this;o=o>>>0,_=_===void 0?this.length:_>>>0,n||(n=0);let j;if(typeof n=="number")for(j=o;j<_;++j)this[j]=n;else{const Y=h.isBuffer(n)?n:h.from(n,O),ce=Y.length;if(ce===0)throw new TypeError('The value "'+n+'" is invalid for argument "value"');for(j=0;j<_-o;++j)this[j+o]=Y[j%ce]}return this};const y={};function w(d,n,o){y[d]=class extends o{constructor(){super(),Object.defineProperty(this,"message",{value:n.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${d}]`,this.stack,delete this.name}get code(){return d}set code(O){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:O,writable:!0})}toString(){return`${this.name} [${d}]: ${this.message}`}}}w("ERR_BUFFER_OUT_OF_BOUNDS",function(d){return d?`${d} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),w("ERR_INVALID_ARG_TYPE",function(d,n){return`The "${d}" argument must be of type number. Received type ${typeof n}`},TypeError),w("ERR_OUT_OF_RANGE",function(d,n,o){let _=`The value of "${d}" is out of range.`,O=o;return Number.isInteger(o)&&Math.abs(o)>oe(2,32)?O=z(String(o)):typeof o=="bigint"&&(O=String(o),(o>oe(BigInt(2),BigInt(32))||o<-oe(BigInt(2),BigInt(32)))&&(O=z(O)),O+="n"),_+=` It must be ${n}. Received ${O}`,_},RangeError);function z(d){let n="",o=d.length;const _=d[0]==="-"?1:0;for(;o>=_+4;o-=3)n=`_${d.slice(o-3,o)}${n}`;return`${d.slice(0,o)}${n}`}function ee(d,n,o){ie(n,"offset"),(d[n]===void 0||d[n+o]===void 0)&&se(n,d.length-(o+1))}function le(d,n,o,_,O,j){if(d>o||d<n){const Y=typeof n=="bigint"?"n":"";let ce;throw n===0||n===BigInt(0)?ce=`>= 0${Y} and < 2${Y} ** ${(j+1)*8}${Y}`:ce=`>= -(2${Y} ** ${(j+1)*8-1}${Y}) and < 2 ** ${(j+1)*8-1}${Y}`,new y.ERR_OUT_OF_RANGE("value",ce,d)}ee(_,O,j)}function ie(d,n){if(typeof d!="number")throw new y.ERR_INVALID_ARG_TYPE(n,"number",d)}function se(d,n,o){throw Math.floor(d)!==d?(ie(d,o),new y.ERR_OUT_OF_RANGE("offset","an integer",d)):n<0?new y.ERR_BUFFER_OUT_OF_BOUNDS:new y.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${n}`,d)}const De=/[^+/0-9A-Za-z-_]/g;function H(d){if(d=d.split("=")[0],d=d.trim().replace(De,""),d.length<2)return"";for(;d.length%4!==0;)d=d+"=";return d}function Fe(d,n){n=n||1/0;let o;const _=d.length;let O=null;const j=[];for(let Y=0;Y<_;++Y){if(o=d.charCodeAt(Y),o>55295&&o<57344){if(!O){if(o>56319){(n-=3)>-1&&j.push(239,191,189);continue}else if(Y+1===_){(n-=3)>-1&&j.push(239,191,189);continue}O=o;continue}if(o<56320){(n-=3)>-1&&j.push(239,191,189),O=o;continue}o=(O-55296<<10|o-56320)+65536}else O&&(n-=3)>-1&&j.push(239,191,189);if(O=null,o<128){if((n-=1)<0)break;j.push(o)}else if(o<2048){if((n-=2)<0)break;j.push(o>>6|192,o&63|128)}else if(o<65536){if((n-=3)<0)break;j.push(o>>12|224,o>>6&63|128,o&63|128)}else if(o<1114112){if((n-=4)<0)break;j.push(o>>18|240,o>>12&63|128,o>>6&63|128,o&63|128)}else throw new Error("Invalid code point")}return j}function Ue(d){const n=[];for(let o=0;o<d.length;++o)n.push(d.charCodeAt(o)&255);return n}function ye(d,n){let o,_,O;const j=[];for(let Y=0;Y<d.length&&!((n-=2)<0);++Y)o=d.charCodeAt(Y),_=o>>8,O=o%256,j.push(O),j.push(_);return j}function we(d){return e.toByteArray(H(d))}function $e(d,n,o,_){let O;for(O=0;O<_&&!(O+o>=n.length||O>=d.length);++O)n[O+o]=d[O];return O}function Ne(d,n){return d instanceof n||d!=null&&d.constructor!=null&&d.constructor.name!=null&&d.constructor.name===n.name}function We(d){return d!==d}const Ve=function(){const d="0123456789abcdef",n=new Array(256);for(let o=0;o<16;++o){const _=o*16;for(let O=0;O<16;++O)n[_+O]=d[o]+d[O]}return n}();function Me(d){return typeof BigInt=="undefined"?tt:d}function tt(){throw new Error("BigInt not supported")}})(Fn);const ua=Fn.Buffer;if(typeof ae=="undefined"?globalThis.process={env:{},browser:!0,version:"v18.0.0",platform:"browser",arch:"x64",versions:{node:"18.0.0"},nextTick:(r,...e)=>{if(typeof r!="function")throw new TypeError("nextTick callback must be a function");if(typeof MessageChannel!="undefined"){const t=new MessageChannel;t.port2.onmessage=()=>{try{r(...e)}catch(s){setTimeout(()=>{throw s},0)}},t.port1.postMessage(null)}else setTimeout(()=>{try{r(...e)}catch(t){setTimeout(()=>{throw t},0)}},0)},cwd:()=>"/",chdir:()=>{},umask:()=>0}:typeof ae.nextTick=="undefined"&&(ae.nextTick=(r,...e)=>{if(typeof r!="function")throw new TypeError("nextTick callback must be a function");if(typeof MessageChannel!="undefined"){const t=new MessageChannel;t.port2.onmessage=()=>{try{r(...e)}catch(s){setTimeout(()=>{throw s},0)}},t.port1.postMessage(null)}else setTimeout(()=>{try{r(...e)}catch(t){setTimeout(()=>{throw t},0)}},0)}),typeof globalThis=="undefined"&&(globalThis.global=globalThis),typeof ua=="undefined"){let r=null;try{typeof require!="undefined"&&(r=require("buffer").Buffer)}catch(e){}r?globalThis.Buffer=r:globalThis.Buffer={isBuffer:e=>!1,from:e=>new Uint8Array(e),alloc:e=>new Uint8Array(e),allocUnsafe:e=>new Uint8Array(e)}}typeof setImmediate=="undefined"&&(globalThis.setImmediate=(r,...e)=>setTimeout(()=>r(...e),0)),typeof clearImmediate=="undefined"&&(globalThis.clearImmediate=r=>{clearTimeout(r)});var fa=Object.defineProperty,ha=(r,e,t)=>e in r?fa(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,it=(r,e,t)=>ha(r,typeof e!="symbol"?e+"":e,t),Ke=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class $n{constructor(e,t,s="/apis/video-call"){it(this,"socket",null),it(this,"serverUrl"),it(this,"socketPath"),it(this,"token"),it(this,"connected",!1),it(this,"reconnectAttempts",0),it(this,"maxReconnectAttempts",5),this.serverUrl=e,this.token=t,this.socketPath=s}connect(){return Ke(this,null,function*(){return this.socket&&this.socket.connected?Promise.resolve():(this.socket&&(this.socket.removeAllListeners(),this.socket.disconnect(),this.socket=null),new Promise((e,t)=>{try{this.socket=ge.io(this.serverUrl,{path:this.socketPath,transports:["websocket","polling"],timeout:1e4,forceNew:!0,auth:{token:this.token}}),this.socket.on("connect",()=>{this.connected=!0,this.reconnectAttempts=0,console.log("[CallSocket] Connected to signaling server"),e()}),this.socket.on("disconnect",s=>{this.connected=!1,console.log("[CallSocket] Disconnected:",s),this.handleDisconnection(s)}),this.socket.on("connect_error",s=>{console.error("[CallSocket] Connection error:",s),this.reconnectAttempts++,this.reconnectAttempts>=this.maxReconnectAttempts&&t(new Error(`Failed to connect after ${this.maxReconnectAttempts} attempts`))})}catch(s){t(s)}}))})}disconnect(){this.socket&&(this.socket.removeAllListeners(),this.socket.disconnect(),this.socket=null,this.connected=!1)}isConnected(){var e;return this.connected&&((e=this.socket)==null?void 0:e.connected)===!0}emit(e,t){var s;if(!this.isConnected())throw new Error("Socket not connected");console.log(`[CallSocket] Emitting ${e}:`,t),(s=this.socket)==null||s.emit(e,t,f=>{f!=null&&f.error&&console.error(`[CallSocket] Error in ${e}:`,f.error)})}emitWithResponse(e,t,s=1e4){return Ke(this,null,function*(){if(!this.isConnected())throw new Error("Socket not connected");return console.log(`[CallSocket] Emitting ${e} with response:`,t),new Promise((f,l)=>{var g;const u=setTimeout(()=>{l(new Error(`Timeout waiting for response to ${e}`))},s);console.log(`[CallSocket] about to emit: ${e}...`),(g=this.socket)==null||g.emit(e,t,c=>{clearTimeout(u),c!=null&&c.error?(console.error(`[CallSocket] Error in ${e}:`,c.error),l(new Error(c.error))):(console.log(`[CallSocket] Response for ${e}:`,c),f(c))})})})}on(e,t){if(!this.socket)throw new Error("Socket not connected");this.socket.on(e,t)}off(e,t){this.socket&&(t?this.socket.off(e,t):this.socket.removeAllListeners(e))}startCall(e){return Ke(this,null,function*(){return this.emitWithResponse("call.start",{roomId:e})})}joinRoom(e){return Ke(this,null,function*(){return this.emitWithResponse("call.join",{roomId:e})})}leaveCall(e){return Ke(this,null,function*(){return this.emitWithResponse("call.leave",{roomId:e})})}sendOffer(e,t,s){this.emit("call.offer",{to:e,offer:t,roomId:s})}sendAnswer(e,t,s){this.emit("call.answer",{to:e,answer:t,roomId:s})}sendCandidate(e,t,s){this.emit("call.candidate",{to:e,candidate:t,roomId:s})}sendStateUpdate(e,t,s){this.emit("call.state",{to:e,state:t,roomId:s})}endCall(e,t,s){this.emit("call.end",{roomId:s,targetUserId:e})}endCallForAll(e){return Ke(this,null,function*(){this.emit("call.end",{roomId:e})})}startRecording(e,t){return Ke(this,null,function*(){return this.emitWithResponse("call.recording.start",{roomId:e,recordingId:t})})}sendRecordingChunk(e,t,s){this.emit("call.recording.chunk",{roomId:e,recordingId:t,chunk:s})}endRecording(e,t,s){return Ke(this,null,function*(){return this.emitWithResponse("call.recording.end",{roomId:e,recordingId:t,transcripts:s})})}sendTranscript(e,t){this.emit("call.transcript",{roomId:e,transcript:t,timestamp:Date.now()})}checkCallStatus(e){return Ke(this,null,function*(){return this.emitWithResponse("call.status",{roomId:e})})}getIceServers(e){return Ke(this,null,function*(){return this.emitWithResponse("call.ice-servers",{roomId:e})})}handleDisconnection(e){["transport close","transport error","io server disconnect"].includes(e)&&this.reconnectAttempts<this.maxReconnectAttempts&&setTimeout(()=>{this.connected||(console.log(`[CallSocket] Attempting to reconnect... (${this.reconnectAttempts+1}/${this.maxReconnectAttempts})`),this.connect().catch(console.error))},Math.pow(2,this.reconnectAttempts)*1e3)}getConnectionInfo(){var e,t;return{connected:this.connected,socketId:(e=this.socket)==null?void 0:e.id,transport:(t=this.socket)==null?void 0:t.io.engine.transport.name,reconnectAttempts:this.reconnectAttempts}}}var da=Object.defineProperty,pa=(r,e,t)=>e in r?da(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,gt=(r,e,t)=>pa(r,typeof e!="symbol"?e+"":e,t),Ct=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class jn{constructor(e={video:!0,audio:!0}){gt(this,"cameraStream",null),gt(this,"screenStream",null),gt(this,"videoElement",null),gt(this,"constraints"),gt(this,"isScreenShare",!1),this.constraints=e}initialize(){return Ct(this,null,function*(){try{return console.log("[CallMediaStream] Initializing media stream with constraints:",this.constraints),this.cameraStream=yield navigator.mediaDevices.getUserMedia(this.constraints),console.log("[CallMediaStream] Media stream initialized successfully"),this.cameraStream}catch(e){throw console.error("[CallMediaStream] Failed to initialize media stream:",e),this.handleMediaError(e)}})}startScreenShare(){return Ct(this,arguments,function*(e={video:!0,audio:!1}){try{return console.log("[CallMediaStream] Starting screen share"),this.screenStream=yield navigator.mediaDevices.getDisplayMedia({video:e.video,audio:e.audio}),this.isScreenShare=!0,this.screenStream.getVideoTracks()[0].addEventListener("ended",()=>{console.log("[CallMediaStream] Screen share ended by user"),this.stopScreenShare()}),console.log("[CallMediaStream] Screen share started successfully"),this.screenStream}catch(t){throw console.error("[CallMediaStream] Failed to start screen share:",t),this.handleMediaError(t)}})}stopScreenShare(){return Ct(this,null,function*(){try{if(console.log("[CallMediaStream] Stopping screen share"),this.screenStream&&this.isScreenShare&&(this.screenStream.getTracks().forEach(e=>e.stop()),this.screenStream=null),!this.cameraStream)this.cameraStream=yield this.initialize();else{const e=this.cameraStream.getVideoTracks();(e.length===0||e[0].readyState==="ended")&&(console.log("[CallMediaStream] Camera stream is inactive, reinitializing"),this.cameraStream=yield this.initialize())}return this.isScreenShare=!1,console.log("[CallMediaStream] Reverted to camera stream"),this.cameraStream}catch(e){throw console.error("[CallMediaStream] Failed to stop screen share:",e),this.handleMediaError(e)}})}toggleAudio(e){const t=this.getCurrentStream();if(!t){console.warn("[CallMediaStream] No stream available for audio toggle");return}t.getAudioTracks().forEach(f=>{f.enabled=e}),console.log(`[CallMediaStream] Audio ${e?"enabled":"disabled"}`)}toggleVideo(e){const t=this.getCurrentStream();if(!t){console.warn("[CallMediaStream] No stream available for video toggle");return}t.getVideoTracks().forEach(f=>{f.enabled=e}),console.log(`[CallMediaStream] Video ${e?"enabled":"disabled"}`)}createVideoElement(){const e=document.createElement("video");e.autoplay=!0,e.playsInline=!0,e.muted=!0;const t=this.getCurrentStream();return t&&(e.srcObject=t),this.videoElement=e,e}attachToVideoElement(e){const t=this.getCurrentStream();t&&(e.srcObject=t,this.videoElement=e)}replaceStream(e){const t=this.getCurrentStream();t&&t.getTracks().forEach(s=>s.stop()),this.isScreenShare?this.screenStream=e:this.cameraStream=e,this.videoElement&&(this.videoElement.srcObject=e),console.log("[CallMediaStream] Stream replaced successfully")}getCurrentStream(){return this.isScreenShare?this.screenStream:this.cameraStream}getStream(){return this.getCurrentStream()}getCameraStream(){return this.cameraStream}getScreenStream(){return this.screenStream}getVideoElement(){return this.videoElement}getIsScreenShare(){return this.isScreenShare}isAudioEnabled(){const e=this.getCurrentStream();if(!e)return!1;const t=e.getAudioTracks();return t.length>0&&t[0].enabled}isVideoEnabled(){const e=this.getCurrentStream();if(!e)return!1;const t=e.getVideoTracks();return t.length>0&&t[0].enabled}getStreamInfo(){const e=this.getCurrentStream();if(!e)return null;const t=e.getVideoTracks(),s=e.getAudioTracks();return{id:e.id,videoTracks:t.length,audioTracks:s.length,isScreenShare:this.isScreenShare,videoEnabled:t.length>0?t[0].enabled:!1,audioEnabled:s.length>0?s[0].enabled:!1,videoConstraints:t.length>0?t[0].getSettings():null,audioConstraints:s.length>0?s[0].getSettings():null,hasCameraStream:!!this.cameraStream,hasScreenStream:!!this.screenStream}}getVideoTrack(){const e=this.getCurrentStream();if(!e)return null;const t=e.getVideoTracks();return t.length>0?t[0]:null}getAudioTrack(){const e=this.getCurrentStream();if(!e)return null;const t=e.getAudioTracks();return t.length>0?t[0]:null}getCameraVideoTrack(){if(!this.cameraStream)return null;const e=this.cameraStream.getVideoTracks();return e.length>0?e[0]:null}getScreenVideoTrack(){if(!this.screenStream)return null;const e=this.screenStream.getVideoTracks();return e.length>0?e[0]:null}cleanup(){console.log("[CallMediaStream] Cleaning up media stream"),this.cameraStream&&(this.cameraStream.getTracks().forEach(e=>{e.stop()}),this.cameraStream=null),this.screenStream&&(this.screenStream.getTracks().forEach(e=>{e.stop()}),this.screenStream=null),this.videoElement&&(this.videoElement.srcObject=null,this.videoElement=null),this.isScreenShare=!1}handleMediaError(e){let t="Unknown media error";return e.name==="NotAllowedError"?t="Permission denied. Please allow camera and microphone access.":e.name==="NotFoundError"?t="No camera or microphone found. Please check your devices.":e.name==="NotReadableError"?t="Camera or microphone is already in use by another application.":e.name==="OverconstrainedError"?t="Camera or microphone does not support the requested constraints.":e.name==="SecurityError"?t="Media access blocked due to security restrictions.":e.name==="AbortError"&&(t="Media access was aborted."),new Error(`${t} (${e.name})`)}static getAvailableDevices(){return Ct(this,null,function*(){try{const e=yield navigator.mediaDevices.enumerateDevices();return{videoDevices:e.filter(t=>t.kind==="videoinput"),audioDevices:e.filter(t=>t.kind==="audioinput")}}catch(e){throw console.error("[CallMediaStream] Failed to get available devices:",e),e}})}static checkBrowserSupport(){return{getUserMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia),getDisplayMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia),webRTC:!!window.RTCPeerConnection}}}function xt(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Rt={exports:{}},Wt,qn;function ga(){if(qn)return Wt;qn=1;var r=1e3,e=r*60,t=e*60,s=t*24,f=s*7,l=s*365.25;Wt=function(h,I){I=I||{};var B=typeof h;if(B==="string"&&h.length>0)return g(h);if(B==="number"&&isFinite(h))return I.long?c(h):u(h);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(h))};function g(h){if(h=String(h),!(h.length>100)){var I=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(h);if(I){var B=parseFloat(I[1]),x=(I[2]||"ms").toLowerCase();switch(x){case"years":case"year":case"yrs":case"yr":case"y":return B*l;case"weeks":case"week":case"w":return B*f;case"days":case"day":case"d":return B*s;case"hours":case"hour":case"hrs":case"hr":case"h":return B*t;case"minutes":case"minute":case"mins":case"min":case"m":return B*e;case"seconds":case"second":case"secs":case"sec":case"s":return B*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return B;default:return}}}}function u(h){var I=Math.abs(h);return I>=s?Math.round(h/s)+"d":I>=t?Math.round(h/t)+"h":I>=e?Math.round(h/e)+"m":I>=r?Math.round(h/r)+"s":h+"ms"}function c(h){var I=Math.abs(h);return I>=s?v(h,I,s,"day"):I>=t?v(h,I,t,"hour"):I>=e?v(h,I,e,"minute"):I>=r?v(h,I,r,"second"):h+" ms"}function v(h,I,B,x){var b=I>=B*1.5;return Math.round(h/B)+" "+x+(b?"s":"")}return Wt}var Gt,xn;function ya(){if(xn)return Gt;xn=1;function r(e){s.debug=s,s.default=s,s.coerce=v,s.disable=u,s.enable=l,s.enabled=c,s.humanize=ga(),s.destroy=h,Object.keys(e).forEach(I=>{s[I]=e[I]}),s.names=[],s.skips=[],s.formatters={};function t(I){let B=0;for(let x=0;x<I.length;x++)B=(B<<5)-B+I.charCodeAt(x),B|=0;return s.colors[Math.abs(B)%s.colors.length]}s.selectColor=t;function s(I){let B,x=null,b,N;function T(...m){if(!T.enabled)return;const R=T,A=Number(new Date),P=A-(B||A);R.diff=P,R.prev=B,R.curr=A,B=A,m[0]=s.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let k=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(C,M)=>{if(C==="%%")return"%";k++;const W=s.formatters[M];if(typeof W=="function"){const X=m[k];C=W.call(R,X),m.splice(k,1),k--}return C}),s.formatArgs.call(R,m),(R.log||s.log).apply(R,m)}return T.namespace=I,T.useColors=s.useColors(),T.color=s.selectColor(I),T.extend=f,T.destroy=s.destroy,Object.defineProperty(T,"enabled",{enumerable:!0,configurable:!1,get:()=>x!==null?x:(b!==s.namespaces&&(b=s.namespaces,N=s.enabled(I)),N),set:m=>{x=m}}),typeof s.init=="function"&&s.init(T),T}function f(I,B){const x=s(this.namespace+(typeof B=="undefined"?":":B)+I);return x.log=this.log,x}function l(I){s.save(I),s.namespaces=I,s.names=[],s.skips=[];const B=(typeof I=="string"?I:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const x of B)x[0]==="-"?s.skips.push(x.slice(1)):s.names.push(x)}function g(I,B){let x=0,b=0,N=-1,T=0;for(;x<I.length;)if(b<B.length&&(B[b]===I[x]||B[b]==="*"))B[b]==="*"?(N=b,T=x,b++):(x++,b++);else if(N!==-1)b=N+1,T++,x=T;else return!1;for(;b<B.length&&B[b]==="*";)b++;return b===B.length}function u(){const I=[...s.names,...s.skips.map(B=>"-"+B)].join(",");return s.enable(""),I}function c(I){for(const B of s.skips)if(g(I,B))return!1;for(const B of s.names)if(g(I,B))return!0;return!1}function v(I){return I instanceof Error?I.stack||I.message:I}function h(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return s.enable(s.load()),s}return Gt=r,Gt}var Wn;function ma(){return Wn||(Wn=1,function(r,e){e.formatArgs=s,e.save=f,e.load=l,e.useColors=t,e.storage=g(),e.destroy=(()=>{let c=!1;return()=>{c||(c=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function t(){if(typeof window!="undefined"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let c;return typeof document!="undefined"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window!="undefined"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator!="undefined"&&navigator.userAgent&&(c=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(c[1],10)>=31||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function s(c){if(c[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+c[0]+(this.useColors?"%c ":" ")+"+"+r.exports.humanize(this.diff),!this.useColors)return;const v="color: "+this.color;c.splice(1,0,v,"color: inherit");let h=0,I=0;c[0].replace(/%[a-zA-Z%]/g,B=>{B!=="%%"&&(h++,B==="%c"&&(I=h))}),c.splice(I,0,v)}e.log=console.debug||console.log||(()=>{});function f(c){try{c?e.storage.setItem("debug",c):e.storage.removeItem("debug")}catch(v){}}function l(){let c;try{c=e.storage.getItem("debug")||e.storage.getItem("DEBUG")}catch(v){}return!c&&typeof ae!="undefined"&&"env"in ae&&(c=ae.env.DEBUG),c}function g(){try{return localStorage}catch(c){}}r.exports=ya()(e);const{formatters:u}=r.exports;u.j=function(c){try{return JSON.stringify(c)}catch(v){return"[UnexpectedJSONParseError]: "+v.message}}}(Rt,Rt.exports)),Rt.exports}var Vt,Gn;function va(){return Gn||(Gn=1,Vt=function(){if(typeof globalThis=="undefined")return null;var e={RTCPeerConnection:globalThis.RTCPeerConnection||globalThis.mozRTCPeerConnection||globalThis.webkitRTCPeerConnection,RTCSessionDescription:globalThis.RTCSessionDescription||globalThis.mozRTCSessionDescription||globalThis.webkitRTCSessionDescription,RTCIceCandidate:globalThis.RTCIceCandidate||globalThis.mozRTCIceCandidate||globalThis.webkitRTCIceCandidate};return e.RTCPeerConnection?e:null}),Vt}var Pt={exports:{}},Tt={exports:{}},zt={},Vn;function yt(){return Vn||(Vn=1,function(r){Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e={},t={};t.byteLength=h,t.toByteArray=B,t.fromByteArray=N;for(var s=[],f=[],l=typeof Uint8Array!="undefined"?Uint8Array:Array,g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,c=g.length;u<c;++u)s[u]=g[u],f[g.charCodeAt(u)]=u;f[45]=62,f[95]=63;function v(R){var A=R.length;if(A%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var P=R.indexOf("=");P===-1&&(P=A);var k=P===A?0:4-P%4;return[P,k]}function h(R){var A=v(R),P=A[0],k=A[1];return(P+k)*3/4-k}function I(R,A,P){return(A+P)*3/4-P}function B(R){var A,P=v(R),k=P[0],S=P[1],C=new l(I(R,k,S)),M=0,W=S>0?k-4:k,X;for(X=0;X<W;X+=4)A=f[R.charCodeAt(X)]<<18|f[R.charCodeAt(X+1)]<<12|f[R.charCodeAt(X+2)]<<6|f[R.charCodeAt(X+3)],C[M++]=A>>16&255,C[M++]=A>>8&255,C[M++]=A&255;return S===2&&(A=f[R.charCodeAt(X)]<<2|f[R.charCodeAt(X+1)]>>4,C[M++]=A&255),S===1&&(A=f[R.charCodeAt(X)]<<10|f[R.charCodeAt(X+1)]<<4|f[R.charCodeAt(X+2)]>>2,C[M++]=A>>8&255,C[M++]=A&255),C}function x(R){return s[R>>18&63]+s[R>>12&63]+s[R>>6&63]+s[R&63]}function b(R,A,P){for(var k,S=[],C=A;C<P;C+=3)k=(R[C]<<16&16711680)+(R[C+1]<<8&65280)+(R[C+2]&255),S.push(x(k));return S.join("")}function N(R){for(var A,P=R.length,k=P%3,S=[],C=16383,M=0,W=P-k;M<W;M+=C)S.push(b(R,M,M+C>W?W:M+C));return k===1?(A=R[P-1],S.push(s[A>>2]+s[A<<4&63]+"==")):k===2&&(A=(R[P-2]<<8)+R[P-1],S.push(s[A>>10]+s[A>>4&63]+s[A<<2&63]+"=")),S.join("")}var T={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */T.read=function(R,A,P,k,S){var C,M,W=S*8-k-1,X=(1<<W)-1,re=X>>1,U=-7,he=P?S-1:0,de=P?-1:1,me=R[A+he];for(he+=de,C=me&(1<<-U)-1,me>>=-U,U+=W;U>0;C=C*256+R[A+he],he+=de,U-=8);for(M=C&(1<<-U)-1,C>>=-U,U+=k;U>0;M=M*256+R[A+he],he+=de,U-=8);if(C===0)C=1-re;else{if(C===X)return M?NaN:(me?-1:1)*(1/0);M=M+Math.pow(2,k),C=C-re}return(me?-1:1)*M*Math.pow(2,C-k)},T.write=function(R,A,P,k,S,C){var M,W,X,re=C*8-S-1,U=(1<<re)-1,he=U>>1,de=S===23?Math.pow(2,-24)-Math.pow(2,-77):0,me=k?0:C-1,Pe=k?1:-1,ke=A<0||A===0&&1/A<0?1:0;for(A=Math.abs(A),isNaN(A)||A===1/0?(W=isNaN(A)?1:0,M=U):(M=Math.floor(Math.log(A)/Math.LN2),A*(X=Math.pow(2,-M))<1&&(M--,X*=2),M+he>=1?A+=de/X:A+=de*Math.pow(2,1-he),A*X>=2&&(M++,X/=2),M+he>=U?(W=0,M=U):M+he>=1?(W=(A*X-1)*Math.pow(2,S),M=M+he):(W=A*Math.pow(2,he-1)*Math.pow(2,S),M=0));S>=8;R[P+me]=W&255,me+=Pe,W/=256,S-=8);for(M=M<<S|W,re+=S;re>0;R[P+me]=M&255,me+=Pe,M/=256,re-=8);R[P+me-Pe]|=ke*128};/*!
|
|
7
7
|
* The buffer module from node.js, for the browser.
|
|
8
8
|
*
|
|
9
9
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
@@ -23,5 +23,5 @@ Use Chrome, Firefox or Internet Explorer 11`)}var s=Hn().Buffer,f=globalThis.cry
|
|
|
23
23
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
24
24
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
25
25
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
|
26
|
-
`);const P=A.state[u];if(P==null)return;JSON.stringify(f.getState())!==JSON.stringify(P)&&x(P);return}f.dispatchFromDevtools&&typeof f.dispatch=="function"&&f.dispatch(A)});case"DISPATCH":switch(m.payload.type){case"RESET":return x(b),u===void 0?h==null?void 0:h.init(f.getState()):h==null?void 0:h.init(Mt(c.name));case"COMMIT":if(u===void 0){h==null||h.init(f.getState());return}return h==null?void 0:h.init(Mt(c.name));case"ROLLBACK":return bn(m.state,A=>{if(u===void 0){x(A),h==null||h.init(f.getState());return}x(A[u]),h==null||h.init(Mt(c.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return bn(m.state,A=>{if(u===void 0){x(A);return}JSON.stringify(f.getState())!==JSON.stringify(A[u])&&x(A[u])});case"IMPORT_STATE":{const{nextLiftedState:A}=m.payload,P=(R=A.computedStates.slice(-1)[0])==null?void 0:R.state;if(!P)return;x(u===void 0?P:P[u]),h==null||h.send(null,A);return}case"PAUSE_RECORDING":return B=!B}return}}),b},bn=(r,e)=>{let t;try{t=JSON.parse(r)}catch(s){console.error("[zustand devtools middleware] Could not parse the received json",s)}t!==void 0&&e(t)};var vs=Object.defineProperty,ws=Object.defineProperties,bs=Object.getOwnPropertyDescriptors,Lt=Object.getOwnPropertySymbols,Fo=Object.prototype.hasOwnProperty,Uo=Object.prototype.propertyIsEnumerable,$o=(r,e,t)=>e in r?vs(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,at=(r,e)=>{for(var t in e||(e={}))Fo.call(e,t)&&$o(r,t,e[t]);if(Lt)for(var t of Lt(e))Uo.call(e,t)&&$o(r,t,e[t]);return r},Sn=(r,e)=>ws(r,bs(e)),Ss=r=>typeof r=="symbol"?r:r+"",_s=(r,e)=>{var t={};for(var s in r)Fo.call(r,s)&&e.indexOf(s)<0&&(t[s]=r[s]);if(r!=null&&Lt)for(var s of Lt(r))e.indexOf(s)<0&&Uo.call(r,s)&&(t[s]=r[s]);return t};const jo={roomId:"",participants:{},localParticipant:null,isCalling:!1,isRecording:!1,recordLoading:!1,callStatus:"idle",error:null,callStatusInfo:null,callStatusLoading:!1,callStatusError:null},je=Ie.create()(ms(r=>Sn(at({},jo),{setRoomId:e=>r({roomId:e},!1,"setRoomId"),setLocalParticipant:e=>r({localParticipant:e},!1,"setLocalParticipant"),addParticipant:e=>r(t=>({participants:Sn(at({},t.participants),{[e.userId]:e})}),!1,"addParticipant"),removeParticipant:e=>r(t=>{const s=t.participants,{[e]:f}=s;return{participants:_s(s,[Ss(e)])}},!1,"removeParticipant"),updateParticipant:(e,t)=>r(s=>({participants:Sn(at({},s.participants),{[e]:s.participants[e]?at(at({},s.participants[e]),t):at({userId:e,videoOn:!0,audioOn:!0,screenSharing:!1},t)})}),!1,"updateParticipant"),clearParticipants:()=>r({participants:{}},!1,"clearParticipants"),setCallStatus:e=>r({callStatus:e},!1,"setCallStatus"),setIsCalling:e=>r({isCalling:e},!1,"setIsCalling"),setIsRecording:e=>r({isRecording:e},!1,"setIsRecording"),setRecordLoading:e=>r({recordLoading:e},!1,"setRecordLoading"),setError:(e,t)=>r({error:t||e},!1,"setError"),clearError:()=>r({error:null},!1,"clearError"),setCallStatusInfo:e=>r({callStatusInfo:e},!1,"setCallStatusInfo"),setCallStatusLoading:e=>r({callStatusLoading:e},!1,"setCallStatusLoading"),setCallStatusError:e=>r({callStatusError:e},!1,"setCallStatusError"),resetCall:()=>r(at({},jo),!1,"resetCall")}),{name:"peers-caller-store",enabled:ae.env.NODE_ENV==="development"})),Es=r=>r.participants,qo=r=>Object.keys(r.participants).length,Cs=r=>r.localParticipant,Rs=r=>r.callStatus,Ps=r=>r.callStatus==="connected",Ts=r=>r.error,As=r=>r.callStatusInfo,Is=r=>r.callStatusLoading,Bs=r=>r.callStatusError,ks=r=>{var e;return((e=r.callStatusInfo)==null?void 0:e.canJoin)||!1},Os=r=>{var e;return((e=r.callStatusInfo)==null?void 0:e.hasActiveCall)||!1},xo=r=>je.getState().participants[r],Ms=r=>{const e=xo(r);return!!(e!=null&&e.stream)},Ls=()=>{const r=je.getState();return Object.values(r.participants)},Ns=(r=4)=>qo(je.getState())<r;var Ds=Object.defineProperty,Fs=(r,e,t)=>e in r?Ds(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Us=(r,e,t)=>Fs(r,e+"",t);class Wo{constructor(e){if(Us(this,"store"),e&&typeof e.getState=="function")this.store=e;else{const t=e;this.store={getState:()=>t}}}get state(){return this.store.getState()}}var $s=Object.defineProperty,js=Object.defineProperties,qs=Object.getOwnPropertyDescriptors,Go=Object.getOwnPropertySymbols,xs=Object.prototype.hasOwnProperty,Ws=Object.prototype.propertyIsEnumerable,_n=(r,e,t)=>e in r?$s(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,En=(r,e)=>{for(var t in e||(e={}))xs.call(e,t)&&_n(r,t,e[t]);if(Go)for(var t of Go(e))Ws.call(e,t)&&_n(r,t,e[t]);return r},Gs=(r,e)=>js(r,qs(e)),dt=(r,e,t)=>_n(r,typeof e!="symbol"?e+"":e,t),Nt=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class Cn extends Wo{constructor(e,t={},s=!1){super(je),dt(this,"userId"),dt(this,"mediaStream",null),dt(this,"peerConnections",new Map),dt(this,"remoteStreams",new Map),dt(this,"isLocalParticipant",!1),dt(this,"callbacks"),this.userId=e,this.callbacks=t,this.isLocalParticipant=s;const f={userId:e,videoOn:!0,audioOn:!0,screenSharing:!1};this.isLocalParticipant&&this.state.setLocalParticipant(f),this.state.addParticipant(f)}initialize(e){return Nt(this,null,function*(){var t,s;try{console.log(`[CallParticipant] Initializing participant ${this.userId}`),this.mediaStream=new jn(e);const l={stream:yield this.mediaStream.initialize(),videoElement:this.mediaStream.createVideoElement()};this.updateState(l),console.log(`[CallParticipant] Participant ${this.userId} initialized successfully`)}catch(f){throw console.error(`[CallParticipant] Failed to initialize participant ${this.userId}:`,f),(s=(t=this.callbacks).onError)==null||s.call(t,f),f}})}createPeerConnection(e,t,s){return Nt(this,null,function*(){var f,l;try{if(console.log(`[CallParticipant] Creating peer connection from ${this.userId} to ${e}`),this.peerConnections.has(e)){console.warn(`[CallParticipant] Peer connection to ${e} already exists`);return}const g={onSignal:c=>{var v,h;console.log(`[CallParticipant] Signal from ${this.userId} to ${e}:`,c.type),(h=(v=this.callbacks).onSignal)==null||h.call(v,this.userId,e,c)},onConnect:()=>{var c,v;console.log(`[CallParticipant] ${this.userId} connected to ${e}`),(v=(c=this.callbacks).onPeerConnected)==null||v.call(c,e)},onStream:c=>{var v,h;console.log(`[CallParticipant] Stream received from ${e} by ${this.userId}`),this.remoteStreams.set(e,c),this.state.updateParticipant(e,{stream:c}),(h=(v=this.callbacks).onStreamReceived)==null||h.call(v,e,c)},onClose:()=>{var c,v;console.log(`[CallParticipant] Connection closed between ${this.userId} and ${e}`),this.remoteStreams.delete(e),this.state.updateParticipant(e,{stream:void 0}),(v=(c=this.callbacks).onPeerDisconnected)==null||v.call(c,e)},onError:c=>{var v,h;console.error(`[CallParticipant] Peer connection error between ${this.userId} and ${e}:`,c),(h=(v=this.callbacks).onError)==null||h.call(v,c)}},u=new No(e,Gs(En({},t),{initiator:s}),g);yield u.createConnection(this.getCurrentStream()),this.peerConnections.set(e,u)}catch(g){throw console.error(`[CallParticipant] Failed to create peer connection from ${this.userId} to ${e}:`,g),(l=(f=this.callbacks).onError)==null||l.call(f,g),g}})}getPeerConnection(e){return this.peerConnections.get(e)}signalToPeer(e,t){const s=this.peerConnections.get(e);s?s.signal(t):console.warn(`[CallParticipant] No peer connection found for ${e}`)}toggleAudio(e){this.mediaStream&&(this.mediaStream.toggleAudio(e),this.updateState({audioOn:e}))}toggleVideo(e){this.mediaStream&&(this.mediaStream.toggleVideo(e),this.updateState({videoOn:e}))}startScreenShare(){return Nt(this,null,function*(){var e,t;try{if(!this.mediaStream)throw new Error("Media stream not initialized");console.log(`[CallParticipant] Starting screen share for ${this.userId}`);const s=yield this.mediaStream.startScreenShare(),f=this.mediaStream.getScreenVideoTrack(),l=this.mediaStream.getCameraVideoTrack();if(!f)throw new Error("Failed to get screen video track");for(const[g,u]of this.peerConnections)l?(u.replaceTrack(l,f),console.log(`[CallParticipant] Screen video track replaced for connection with ${g}`)):console.warn(`[CallParticipant] No camera video track to replace for ${g}`);this.updateState({screenSharing:!0,stream:s}),console.log(`[CallParticipant] Screen sharing started for ${this.userId}`)}catch(s){throw console.error(`[CallParticipant] Failed to start screen share for ${this.userId}:`,s),(t=(e=this.callbacks).onError)==null||t.call(e,s),s}})}stopScreenShare(){return Nt(this,null,function*(){var e,t;try{if(!this.mediaStream)throw new Error("Media stream not initialized");console.log(`[CallParticipant] Stopping screen share for ${this.userId}`);const s=this.mediaStream.getScreenVideoTrack();console.log("[CallParticipant] Screen video track found:",!!s);const f=yield this.mediaStream.stopScreenShare(),l=this.mediaStream.getCameraVideoTrack();if(console.log("[CallParticipant] Camera stream:",!!f),console.log("[CallParticipant] Camera video track:",!!l),!l)throw new Error("Failed to get camera video track");for(const[g,u]of this.peerConnections)try{s&&l?(u.replaceTrack(s,l),console.log(`[CallParticipant] Camera video track restored for connection with ${g}`)):(console.log(`[CallParticipant] Updating entire stream for connection with ${g}`),u.addStream(f))}catch(c){console.warn(`[CallParticipant] Failed to replace track for ${g}, trying stream replacement:`,c)}if(this.updateState({screenSharing:!1,stream:f}),this.isLocalParticipant&&this.mediaStream){const g=this.mediaStream.getVideoElement();g&&(g.srcObject=f,console.log(`[CallParticipant] Updated local video element for ${this.userId}`))}console.log(`[CallParticipant] Screen sharing stopped for ${this.userId}`)}catch(s){throw console.error(`[CallParticipant] Failed to stop screen share for ${this.userId}:`,s),(t=(e=this.callbacks).onError)==null||t.call(e,s),s}})}getState(){const e=this.state;return this.isLocalParticipant?e.localParticipant||{userId:this.userId,videoOn:!0,audioOn:!0,screenSharing:!1}:e.participants[this.userId]||{userId:this.userId,videoOn:!0,audioOn:!0,screenSharing:!1}}getUserId(){return this.userId}getMediaStream(){return this.mediaStream}getCurrentStream(){return this.getState().stream}getVideoElement(){return this.getState().videoElement}getRemoteStream(e){return this.remoteStreams.get(e)}getAllRemoteStreams(){return new Map(this.remoteStreams)}getAllPeerConnections(){return new Map(this.peerConnections)}getConnectionStatus(){const e={};for(const[t,s]of this.peerConnections)e[t]=s.isConnected();return e}removePeerConnection(e){const t=this.peerConnections.get(e);t&&(t.destroy(),this.peerConnections.delete(e),this.remoteStreams.delete(e),this.state.updateParticipant(e,{stream:void 0}),console.log(`[CallParticipant] Removed peer connection from ${this.userId} to ${e}`))}updateState(e){var t,s;const f=this.getState();if(Object.keys(e).some(g=>f[g]!==e[g])){const g=En(En({},f),e);this.isLocalParticipant&&this.state.setLocalParticipant(g),this.state.updateParticipant(this.userId,e),(s=(t=this.callbacks).onStateChanged)==null||s.call(t,this.userId,e)}}getDebugInfo(){var e;return{userId:this.userId,state:this.getState(),peerConnections:Array.from(this.peerConnections.keys()),remoteStreams:Array.from(this.remoteStreams.keys()),connectionStatus:this.getConnectionStatus(),mediaStreamInfo:(e=this.mediaStream)==null?void 0:e.getStreamInfo()}}cleanup(){console.log(`[CallParticipant] Cleaning up participant ${this.userId}`),this.state.removeParticipant(this.userId);for(const e of this.peerConnections.values())e.destroy();this.peerConnections.clear(),this.remoteStreams.clear(),this.mediaStream&&(this.mediaStream.cleanup(),this.mediaStream=null),console.log(`[CallParticipant] Participant ${this.userId} cleanup completed`)}}var Rn={exports:{}},Vo;function Vs(){return Vo||(Vo=1,function(r){function e(t,s){var f="Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45";(function(S){typeof RecordRTC=="undefined"&&S&&typeof window=="undefined"&&typeof globalThis!="undefined"&&(globalThis.navigator={userAgent:f,getUserMedia:function(){}},globalThis.console||(globalThis.console={}),(typeof globalThis.console.log=="undefined"||typeof globalThis.console.error=="undefined")&&(globalThis.console.error=globalThis.console.log=globalThis.console.log||function(){console.log(arguments)}),typeof document=="undefined"&&(S.document={documentElement:{appendChild:function(){return""}}},document.createElement=document.captureStream=document.mozCaptureStream=function(){var C={getContext:function(){return C},play:function(){},pause:function(){},drawImage:function(){},toDataURL:function(){return""},style:{}};return C},S.HTMLVideoElement=function(){}),typeof location=="undefined"&&(S.location={protocol:"file:",href:"",hash:""}),typeof screen=="undefined"&&(S.screen={width:0,height:0}),typeof I=="undefined"&&(S.URL={createObjectURL:function(){return""},revokeObjectURL:function(){return""}}),S.window=globalThis)})(typeof globalThis!="undefined"?globalThis:null),s=s||"multi-streams-mixer";var l=[],g=!1,u=document.createElement("canvas"),c=u.getContext("2d");u.style.opacity=0,u.style.position="absolute",u.style.zIndex=-1,u.style.top="-1000em",u.style.left="-1000em",u.className=s,(document.body||document.documentElement).appendChild(u),this.disableLogs=!1,this.frameInterval=10,this.width=360,this.height=240,this.useGainNode=!0;var v=this,h=window.AudioContext;typeof h=="undefined"&&(typeof webkitAudioContext!="undefined"&&(h=webkitAudioContext),typeof mozAudioContext!="undefined"&&(h=mozAudioContext));var I=window.URL;typeof I=="undefined"&&typeof webkitURL!="undefined"&&(I=webkitURL),typeof navigator!="undefined"&&typeof navigator.getUserMedia=="undefined"&&(typeof navigator.webkitGetUserMedia!="undefined"&&(navigator.getUserMedia=navigator.webkitGetUserMedia),typeof navigator.mozGetUserMedia!="undefined"&&(navigator.getUserMedia=navigator.mozGetUserMedia));var B=window.MediaStream;typeof B=="undefined"&&typeof webkitMediaStream!="undefined"&&(B=webkitMediaStream),typeof B!="undefined"&&typeof B.prototype.stop=="undefined"&&(B.prototype.stop=function(){this.getTracks().forEach(function(S){S.stop()})});var x={};typeof h!="undefined"?x.AudioContext=h:typeof webkitAudioContext!="undefined"&&(x.AudioContext=webkitAudioContext);function b(S,C){"srcObject"in C?C.srcObject=S:"mozSrcObject"in C?C.mozSrcObject=S:C.srcObject=S}this.startDrawingFrames=function(){N()};function N(){if(!g){var S=l.length,C=!1,M=[];if(l.forEach(function(X){X.stream||(X.stream={}),X.stream.fullcanvas?C=X:M.push(X)}),C)u.width=C.stream.width,u.height=C.stream.height;else if(M.length){u.width=S>1?M[0].width*2:M[0].width;var W=1;(S===3||S===4)&&(W=2),(S===5||S===6)&&(W=3),(S===7||S===8)&&(W=4),(S===9||S===10)&&(W=5),u.height=M[0].height*W}else u.width=v.width||360,u.height=v.height||240;C&&C instanceof HTMLVideoElement&&T(C),M.forEach(function(X,re){T(X,re)}),setTimeout(N,v.frameInterval)}}function T(S,C){if(!g){var M=0,W=0,X=S.width,re=S.height;C===1&&(M=S.width),C===2&&(W=S.height),C===3&&(M=S.width,W=S.height),C===4&&(W=S.height*2),C===5&&(M=S.width,W=S.height*2),C===6&&(W=S.height*3),C===7&&(M=S.width,W=S.height*3),typeof S.stream.left!="undefined"&&(M=S.stream.left),typeof S.stream.top!="undefined"&&(W=S.stream.top),typeof S.stream.width!="undefined"&&(X=S.stream.width),typeof S.stream.height!="undefined"&&(re=S.stream.height),c.drawImage(S,M,W,X,re),typeof S.stream.onRender=="function"&&S.stream.onRender(c,M,W,X,re,C)}}function m(){g=!1;var S=R(),C=A();return C&&C.getTracks().filter(function(M){return M.kind==="audio"}).forEach(function(M){S.addTrack(M)}),t.forEach(function(M){M.fullcanvas}),S}function R(){k();var S;"captureStream"in u?S=u.captureStream():"mozCaptureStream"in u?S=u.mozCaptureStream():v.disableLogs||console.error("Upgrade to latest Chrome or otherwise enable this flag: chrome://flags/#enable-experimental-web-platform-features");var C=new B;return S.getTracks().filter(function(M){return M.kind==="video"}).forEach(function(M){C.addTrack(M)}),u.stream=C,C}function A(){x.AudioContextConstructor||(x.AudioContextConstructor=new x.AudioContext),v.audioContext=x.AudioContextConstructor,v.audioSources=[],v.useGainNode===!0&&(v.gainNode=v.audioContext.createGain(),v.gainNode.connect(v.audioContext.destination),v.gainNode.gain.value=0);var S=0;if(t.forEach(function(C){if(C.getTracks().filter(function(W){return W.kind==="audio"}).length){S++;var M=v.audioContext.createMediaStreamSource(C);v.useGainNode===!0&&M.connect(v.gainNode),v.audioSources.push(M)}}),!!S)return v.audioDestination=v.audioContext.createMediaStreamDestination(),v.audioSources.forEach(function(C){C.connect(v.audioDestination)}),v.audioDestination.stream}function P(S){var C=document.createElement("video");return b(S,C),C.className=s,C.muted=!0,C.volume=0,C.width=S.width||v.width||360,C.height=S.height||v.height||240,C.play(),C}this.appendStreams=function(S){if(!S)throw"First parameter is required.";S instanceof Array||(S=[S]),S.forEach(function(C){var M=new B;if(C.getTracks().filter(function(re){return re.kind==="video"}).length){var W=P(C);W.stream=C,l.push(W),M.addTrack(C.getTracks().filter(function(re){return re.kind==="video"})[0])}if(C.getTracks().filter(function(re){return re.kind==="audio"}).length){var X=v.audioContext.createMediaStreamSource(C);v.audioDestination=v.audioContext.createMediaStreamDestination(),X.connect(v.audioDestination),M.addTrack(v.audioDestination.stream.getTracks().filter(function(re){return re.kind==="audio"})[0])}t.push(M)})},this.releaseStreams=function(){l=[],g=!0,v.gainNode&&(v.gainNode.disconnect(),v.gainNode=null),v.audioSources.length&&(v.audioSources.forEach(function(S){S.disconnect()}),v.audioSources=[]),v.audioDestination&&(v.audioDestination.disconnect(),v.audioDestination=null),v.audioContext&&v.audioContext.close(),v.audioContext=null,c.clearRect(0,0,u.width,u.height),u.stream&&(u.stream.stop(),u.stream=null)},this.resetVideoStreams=function(S){S&&!(S instanceof Array)&&(S=[S]),k(S)};function k(S){l=[],S=S||t,S.forEach(function(C){if(C.getTracks().filter(function(W){return W.kind==="video"}).length){var M=P(C);M.stream=C,l.push(M)}})}this.name="MultiStreamsMixer",this.toString=function(){return this.name},this.getMixedStream=m}typeof RecordRTC=="undefined"&&(r.exports=e)}(Rn)),Rn.exports}var zs=Vs();const Hs=xt(zs);var Js=Ht();const Ys=xt(Js);class Ks extends Ys{constructor(t,s=navigator.language){super();ze(this,"track",null);ze(this,"trackId",null);ze(this,"recognition",null);ze(this,"recognizing",!1);ze(this,"transcripts",[]);ze(this,"startTime",0);ze(this,"endTime",0);ze(this,"currentStamp",0);ze(this,"start",()=>(this.recognition.start(),this.recognition.stream=this.track,this.recognizing=!0,this.startTime=performance.now(),this));ze(this,"stop",()=>(this.recognition.stop(),this.recognizing=!1,this.endTime=performance.now(),this));("webkitSpeechRecognition"in window||"SpeechRecognition"in window)&&(this.recognition=new(window.SpeechRecognition||window.webkitSpeechRecognition),this.recognition.continuous=!0,this.recognition.interimResults=!0,this.recognition.lang=s,this.track=t,this.recognition.onstart=this.emit("start"),this.recognition.onend=()=>this.emit("end"),this.recognition.onresult=f=>{const{results:l,resultIndex:g}=f;let u="";if(l[g].isFinal&&l[g][0].transcript){const c={sentence:l[g][0].transcript,confidence:l[g][0].confidence,timeStamp:this.currentStamp,endTimeStamp:new Date().getTime()};this.transcripts.push(c),this.emit("sentence",c)}else this.currentStamp=new Date().getTime(),u+=l[g][0].transcript,this.emit("interim",{sentence:u,timeStamp:this.currentStamp});this.emit("result",f)})}}var Xs=Object.defineProperty,zo=Object.getOwnPropertySymbols,Zs=Object.prototype.hasOwnProperty,Qs=Object.prototype.propertyIsEnumerable,Pn=(r,e,t)=>e in r?Xs(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,el=(r,e)=>{for(var t in e||(e={}))Zs.call(e,t)&&Pn(r,t,e[t]);if(zo)for(var t of zo(e))Qs.call(e,t)&&Pn(r,t,e[t]);return r},pt=(r,e,t)=>Pn(r,typeof e!="symbol"?e+"":e,t),Tn=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class Ho{constructor(e={},t={}){pt(this,"mixer",null),pt(this,"recorder",null),pt(this,"localTranscriber",null),pt(this,"isRecording",!1),pt(this,"config"),pt(this,"callbacks"),this.config=el({mimeType:"video/webm;codecs=vp8,opus",videoBitsPerSecond:1e6,audioBitsPerSecond:128e3,interval:1e3},e),this.callbacks=t}startRecording(e,t){return Tn(this,null,function*(){var s,f,l,g;try{if(console.log("[CallRecorder] Starting recording with",e.length,"streams"),this.isRecording)throw new Error("Recording already in progress");if(!t)throw new Error("Recording data is required");this.mixer=new Hs(e),this.mixer.frameInterval=1,this.mixer.startDrawingFrames();const u=e[0];u&&u.getAudioTracks().length>0&&(this.localTranscriber=new Ks(u)),MediaRecorder.isTypeSupported(this.config.mimeType)||(console.warn("[CallRecorder] Preferred mime type not supported, falling back to default"),this.config.mimeType="video/webm");const c=this.mixer.getMixedStream();this.recorder=new MediaRecorder(c,{mimeType:this.config.mimeType,videoBitsPerSecond:this.config.videoBitsPerSecond,audioBitsPerSecond:this.config.audioBitsPerSecond}),this.setupRecorderEventHandlers(t),this.recorder.start(this.config.interval),this.isRecording=!0,this.localTranscriber&&this.localTranscriber.start(),(f=(s=this.callbacks).onRecordingStarted)==null||f.call(s,t),console.log("[CallRecorder] Recording started successfully")}catch(u){throw console.error("[CallRecorder] Failed to start recording:",u),(g=(l=this.callbacks).onError)==null||g.call(l,u),u}})}stopRecording(){return Tn(this,null,function*(){var e,t;try{if(console.log("[CallRecorder] Stopping recording"),!this.isRecording||!this.recorder)return console.warn("[CallRecorder] No active recording to stop"),[];this.recorder.stop(),this.isRecording=!1;let s=[];return this.localTranscriber&&(this.localTranscriber.stop(),s=this.localTranscriber.transcripts||[]),this.mixer&&this.mixer.releaseStreams(),console.log("[CallRecorder] Recording stopped successfully"),s}catch(s){return console.error("[CallRecorder] Failed to stop recording:",s),(t=(e=this.callbacks).onError)==null||t.call(e,s),[]}})}resetVideoStreams(e){this.mixer&&(this.mixer.resetVideoStreams(e),console.log("[CallRecorder] Video streams reset"))}setupRecorderEventHandlers(e){this.recorder&&(this.recorder.ondataavailable=t=>{var s,f;t.data&&t.data.size>0&&((f=(s=this.callbacks).onRecordingChunk)==null||f.call(s,t.data,e))},this.recorder.onstart=()=>{console.log("[CallRecorder] MediaRecorder started")},this.recorder.onstop=()=>{var t,s;console.log("[CallRecorder] MediaRecorder stopped"),(s=(t=this.callbacks).onRecordingStopped)==null||s.call(t,e)},this.recorder.onerror=t=>{var s,f;console.error("[CallRecorder] MediaRecorder error:",t),(f=(s=this.callbacks).onError)==null||f.call(s,new Error(`Recording error: ${t}`))})}getRecordingState(){var e,t;return{isRecording:this.isRecording,isTranscribing:this.localTranscriber!==null,transcriptCount:((t=(e=this.localTranscriber)==null?void 0:e.transcripts)==null?void 0:t.length)||0}}getTranscripts(){var e;return((e=this.localTranscriber)==null?void 0:e.transcripts)||[]}static isRecordingSupported(){return typeof MediaRecorder!="undefined"&&typeof MediaRecorder.isTypeSupported=="function"}static isTranscriptionSupported(){return!!(window.SpeechRecognition||window.webkitSpeechRecognition)}static getSupportedMimeTypes(){return["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm;codecs=h264,opus","video/webm","video/mp4;codecs=h264,aac","video/mp4"].filter(t=>MediaRecorder.isTypeSupported&&MediaRecorder.isTypeSupported(t))}cleanup(){return Tn(this,null,function*(){console.log("[CallRecorder] Cleaning up recorder"),this.isRecording&&(yield this.stopRecording()),this.localTranscriber&&(this.localTranscriber.stop(),this.localTranscriber=null),this.mixer&&(this.mixer.releaseStreams(),this.mixer=null),this.recorder=null})}}var tl=Object.defineProperty,rl=Object.defineProperties,nl=Object.getOwnPropertyDescriptors,Jo=Object.getOwnPropertySymbols,il=Object.prototype.hasOwnProperty,ol=Object.prototype.propertyIsEnumerable,An=(r,e,t)=>e in r?tl(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,al=(r,e)=>{for(var t in e||(e={}))il.call(e,t)&&An(r,t,e[t]);if(Jo)for(var t of Jo(e))ol.call(e,t)&&An(r,t,e[t]);return r},sl=(r,e)=>rl(r,nl(e)),Ge=(r,e,t)=>An(r,typeof e!="symbol"?e+"":e,t),Le=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class Yo extends Wo{constructor(e,t={}){if(super(je),Ge(this,"config"),Ge(this,"callbacks"),Ge(this,"socket"),Ge(this,"localParticipant",null),Ge(this,"participants",new Map),Ge(this,"recorder",null),Ge(this,"iceServers",[]),Ge(this,"isInitialized",!1),Ge(this,"listenersSetup",!1),Ge(this,"roomId"),Ge(this,"eventListeners",new Map),this.roomId=e.roomId,!this.roomId)throw new Error("roomId must be provided in config");this.config=sl(al({maxParticipants:4,debug:!1,socketPath:"/apis/video-call",mediaConfig:{video:!0,audio:!0}},e),{roomId:this.roomId}),this.callbacks=t,this.socket=new $n(this.config.socketUrl,this.config.token,this.config.socketPath),this.iceServers=this.config.iceServers||[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"}],this.state.setRoomId(this.roomId),console.log("[PeersCaller] Initialized with config:",{roomId:this.roomId,tokenLength:this.config.token.length,maxParticipants:this.config.maxParticipants})}initialize(){return Le(this,null,function*(){try{if(console.log("[PeersCaller] Initializing..."),this.isInitialized){console.warn("[PeersCaller] Already initialized");return}yield this.socket.connect(),yield this.fetchIceServers(),this.setupSocketListeners(),yield this.initializeLocalParticipant(),this.isInitialized=!0,this.state.setCallStatus("idle"),console.log("[PeersCaller] Initialization completed successfully (ready to start/join call)")}catch(e){throw console.error("[PeersCaller] Initialization failed:",e),this.handleError("NETWORK_ERROR",`Failed to initialize: ${e}`),e}})}startCall(){return Le(this,arguments,function*(e=this.config.mediaConfig){var t,s;try{if(console.log("[PeersCaller] Starting call..."),this.isInitialized||(yield this.initialize()),this.localParticipant&&!this.localParticipant.getCurrentStream()){const l={video:e!=null&&e.video&&typeof e.video=="boolean"?e.video:!0,audio:e!=null&&e.audio&&typeof e.audio=="boolean"?e.audio:!0};yield this.localParticipant.initialize(l)}this.state.setIsCalling(!0),this.state.setCallStatus("connecting"),console.log("[PeersCaller] Starting call for room:",this.config.roomId);const f=yield this.socket.startCall(this.config.roomId);if(console.log("[PeersCaller] Received call.start response:",f),f.success)this.state.setCallStatus("connected"),f.participants.forEach(l=>{l!==this.config.userId&&this.handleParticipantJoined(l)}),console.log("[PeersCaller] Call started successfully"),(s=(t=this.callbacks).onCallStarted)==null||s.call(t,f);else{this.state.setIsCalling(!1),this.state.setCallStatus("idle");const l="Failed to start call on server";throw this.handleError("SIGNALING_ERROR",l),console.error("[PeersCaller] Call start failed:",l),new Error(l)}}catch(f){throw console.error("[PeersCaller] Failed to start call:",f),this.handleError("MEDIA_ACCESS_DENIED",`Failed to start call: ${f}`),f}})}joinCall(){return Le(this,arguments,function*(e=this.config.mediaConfig){try{console.log("[PeersCaller] Joining call..."),this.isInitialized||(yield this.initialize());const t=yield this.checkCallStatus();if(!t.hasActiveCall)throw new Error("No active call found");if(!t.canJoin)throw new Error(`Cannot join call: ${t.status==="full"?"Call is full":"Unable to join"}`);if(this.state.setCallStatus("connecting"),this.localParticipant&&!this.localParticipant.getCurrentStream()){const f={video:typeof(e==null?void 0:e.video)=="boolean"?e.video:!0,audio:typeof(e==null?void 0:e.audio)=="boolean"?e.audio:!0};console.log("[PeersCaller] Initializing local media with config:",f),yield this.localParticipant.initialize(f)}console.log("[PeersCaller] Joining call for room:",this.config.roomId);const s=yield this.socket.joinRoom(this.config.roomId);console.log("[PeersCaller] Received call.join response:",s),this.state.setCallStatus("connected"),this.state.setIsCalling(!0),s.participants.forEach(f=>{f!==this.config.userId&&this.handleParticipantJoined(f)}),console.log("[PeersCaller] Joined call successfully")}catch(t){throw console.error("[PeersCaller] Failed to join call:",t),this.state.setCallStatus("idle"),this.handleError("INVALID_ROOM_ID",`Failed to join call: ${t}`),t}})}endCall(){return Le(this,null,function*(){try{console.log("[PeersCaller] Ending call..."),this.recorder&&this.state.isRecording&&(yield this.stopRecording());try{yield this.socket.endCallForAll(this.config.roomId),console.log("[PeersCaller] End call request sent to server")}catch(e){console.warn("[PeersCaller] Failed to notify server of call end:",e)}this.cleanupAllParticipants(),this.state.setIsCalling(!1),this.state.setCallStatus("idle"),this.state.clearParticipants(),console.log("[PeersCaller] Call ended successfully")}catch(e){console.error("[PeersCaller] Error ending call:",e)}})}leaveCall(){return Le(this,null,function*(){try{console.log("[PeersCaller] Leaving call..."),console.log("[PeersCaller] Leaving call for room:",this.config.roomId);const e=yield this.socket.leaveCall(this.config.roomId);if(console.log("[PeersCaller] Received call.leave response:",e),e.success)this.cleanupAllParticipants(),this.state.setIsCalling(!1),this.state.setCallStatus("idle"),this.state.clearParticipants(),console.log("[PeersCaller] Left call successfully");else{const t="Failed to leave call on server";throw this.handleError("SIGNALING_ERROR",t),console.error("[PeersCaller] Call leave failed:",t),new Error(t)}}catch(e){throw console.error("[PeersCaller] Failed to leave call:",e),this.handleError("SIGNALING_ERROR",`Failed to leave call: ${e}`),e}})}toggleAudio(e){this.localParticipant&&(this.localParticipant.toggleAudio(e),this.broadcastStateUpdate({audioOn:e}),console.log(`[PeersCaller] Audio ${e?"enabled":"disabled"}`))}toggleVideo(e){this.localParticipant&&(this.localParticipant.toggleVideo(e),this.broadcastStateUpdate({videoOn:e}),console.log(`[PeersCaller] Video ${e?"enabled":"disabled"}`))}startScreenShare(){return Le(this,null,function*(){try{if(!this.localParticipant)throw new Error("Local participant not initialized");yield this.localParticipant.startScreenShare(),this.broadcastStateUpdate({screenSharing:!0}),console.log("[PeersCaller] Screen sharing started")}catch(e){throw console.error("[PeersCaller] Failed to start screen share:",e),this.handleError("MEDIA_ACCESS_DENIED",`Failed to start screen share: ${e}`),e}})}stopScreenShare(){return Le(this,null,function*(){try{if(!this.localParticipant)throw new Error("Local participant not initialized");yield this.localParticipant.stopScreenShare(),this.broadcastStateUpdate({screenSharing:!1}),console.log("[PeersCaller] Screen sharing stopped")}catch(e){throw console.error("[PeersCaller] Failed to stop screen share:",e),e}})}startRecording(e,t){return Le(this,null,function*(){var s;try{if(console.log("[PeersCaller] Starting recording..."),this.state.isRecording){console.warn("[PeersCaller] Recording already in progress");return}const f=[],l=(s=this.localParticipant)==null?void 0:s.getCurrentStream();l&&f.push(l);for(const g of this.participants.values()){const u=g.getCurrentStream();u&&f.push(u)}if(f.length===0)throw new Error("No streams available for recording");this.recorder=new Ho(t,{onRecordingStarted:g=>{this.socket.startRecording(this.config.roomId,g.id)},onRecordingChunk:(g,u)=>{this.socket.sendRecordingChunk(this.config.roomId,u.id,g)},onRecordingStopped:g=>{this.socket.endRecording(this.config.roomId,g.id)},onTranscriptReceived:g=>{this.socket.sendTranscript(this.config.roomId,g.text)},onError:g=>{this.handleError("RECORDING_FAILED",g.message)}}),yield this.recorder.startRecording(f,e),this.state.setIsRecording(!0),console.log("[PeersCaller] Recording started successfully")}catch(f){throw console.error("[PeersCaller] Failed to start recording:",f),this.handleError("RECORDING_FAILED",`Failed to start recording: ${f}`),f}})}stopRecording(){return Le(this,null,function*(){try{if(console.log("[PeersCaller] Stopping recording..."),!this.recorder||!this.state.isRecording){console.warn("[PeersCaller] No active recording to stop");return}yield this.recorder.stopRecording(),this.state.setIsRecording(!1),console.log("[PeersCaller] Recording stopped successfully")}catch(e){throw console.error("[PeersCaller] Failed to stop recording:",e),e}})}getCallState(){return this.state}getLocalParticipant(){return this.localParticipant}getParticipants(){return new Map(this.participants)}getParticipant(e){return this.participants.get(e)}getDebugInfo(){return{isInitialized:this.isInitialized,localParticipant:this.localParticipant?{userId:this.localParticipant.getUserId(),hasStream:!!this.localParticipant.getCurrentStream(),streamTracks:this.localParticipant.getCurrentStream()?{video:this.localParticipant.getCurrentStream().getVideoTracks().length,audio:this.localParticipant.getCurrentStream().getAudioTracks().length}:null,peerConnections:Array.from(this.localParticipant.getAllPeerConnections().keys()),connectionStatus:this.localParticipant.getConnectionStatus()}:null,remoteParticipants:Array.from(this.participants.keys()),storeState:this.state,socketConnected:this.socket.isConnected()}}cleanup(){console.log("[PeersCaller] Cleaning up..."),this.state.isCalling&&this.endCall(),this.cleanupSocketListeners(),this.cleanupAllParticipants(),this.recorder&&(this.recorder.cleanup(),this.recorder=null),this.socket.disconnect(),this.state.resetCall(),this.isInitialized=!1,console.log("[PeersCaller] Cleanup completed")}initializeLocalParticipant(){return Le(this,null,function*(){this.localParticipant=new Cn(this.config.userId,{onSignal:(e,t,s)=>{this.forwardSignalToServer(e,t,s)},onError:e=>this.handleError("UNKNOWN_ERROR",e.message)},!0),console.log("[PeersCaller] Local participant created (media not initialized yet)")})}setupSocketListeners(){if(this.listenersSetup){console.log("[PeersCaller] Socket listeners already set up, skipping...");return}this.cleanupSocketListeners(),console.log("[PeersCaller] Setting up socket listeners...");const e=T=>{this.handleParticipantJoined(T.userId)};this.socket.on("call.participant.joined",e),this.eventListeners.set("call.participant.joined",e);const t=T=>{this.handleParticipantLeft(T.userId)};this.socket.on("call.participant.left",t),this.eventListeners.set("call.participant.left",t);const s=T=>{T.participants.forEach(m=>{m!==this.config.userId&&this.handleParticipantJoined(m)})};this.socket.on("call.participants",s),this.eventListeners.set("call.participants",s);const f=()=>{this.state.setIsCalling(!1)};this.socket.on("call.left",f),this.eventListeners.set("call.left",f);const l=T=>{var m,R;console.error("[PeersCaller] Server error:",T),(R=(m=this.callbacks).onError)==null||R.call(m,T.error,T.message)};this.socket.on("call.error",l),this.eventListeners.set("call.error",l);const g=T=>{this.handleOffer(T.from,T.offer)};this.socket.on("call.offer",g),this.eventListeners.set("call.offer",g);const u=T=>{this.handleAnswer(T.from,T.answer)};this.socket.on("call.answer",u),this.eventListeners.set("call.answer",u);const c=T=>{this.handleCandidate(T.from,T.candidate)};this.socket.on("call.candidate",c),this.eventListeners.set("call.candidate",c);const v=T=>{this.handleParticipantStateUpdate(T.from,T.state)};this.socket.on("call.state",v),this.eventListeners.set("call.state",v);const h=T=>{this.handleCallEnded(T)};this.socket.on("call.ended",h),this.eventListeners.set("call.ended",h);const I=T=>{this.handleCallStatusChanged(T)};this.socket.on("call.status.changed",I),this.eventListeners.set("call.status.changed",I);const B=T=>{console.log("[PeersCaller] Recording started:",T.recordingId),this.state.setIsRecording(!0)};this.socket.on("call.recording.start",B),this.eventListeners.set("call.recording.start",B);const x=T=>{console.log("[PeersCaller] Recording chunk received:",T)};this.socket.on("call.recording.chunk.received",x),this.eventListeners.set("call.recording.chunk.received",x);const b=T=>{console.log("[PeersCaller] Recording ended:",T.recordingId),this.state.setIsRecording(!1)};this.socket.on("call.recording.end",b),this.eventListeners.set("call.recording.end",b);const N=T=>{console.log("[PeersCaller] Transcript received:",T)};this.socket.on("call.transcript",N),this.eventListeners.set("call.transcript",N),this.listenersSetup=!0,console.log("[PeersCaller] Socket listeners set up successfully")}cleanupSocketListeners(){if(!(!this.listenersSetup&&this.eventListeners.size===0)){console.log("[PeersCaller] Cleaning up socket listeners...");for(const[e,t]of this.eventListeners)this.socket.off(e,t);this.eventListeners.clear(),this.listenersSetup=!1,console.log("[PeersCaller] Socket listeners cleaned up successfully")}}handleParticipantJoined(e){return Le(this,null,function*(){var t,s;try{if(e===this.config.userId||this.participants.has(e))return;if(this.participants.size>=this.config.maxParticipants-1){console.warn("[PeersCaller] Maximum participants reached");return}console.log(`[PeersCaller] Participant ${e} joined`);const f=new Cn(e,{onStreamReceived:(u,c)=>{var v,h;(h=(v=this.callbacks).onStreamReceived)==null||h.call(v,u,c)},onPeerConnected:u=>{console.log(`[PeersCaller] Peer connection established with ${u}`)},onPeerDisconnected:u=>{this.handleParticipantLeft(u)},onSignal:(u,c,v)=>{this.forwardSignalToServer(u,c,v)},onError:u=>{this.handleError("PEER_CONNECTION_FAILED",u.message)}},!1);if(this.participants.set(e,f),!this.localParticipant){console.error("[PeersCaller] Cannot create peer connection - local participant not initialized");return}const l=this.config.userId<e,g={iceServers:this.iceServers,initiator:l};yield this.localParticipant.createPeerConnection(e,g,l),(s=(t=this.callbacks).onParticipantJoined)==null||s.call(t,{userId:e,videoOn:!0,audioOn:!0,screenSharing:!1})}catch(f){console.error(`[PeersCaller] Failed to handle participant ${e} joining:`,f)}})}checkCallStatus(){return Le(this,null,function*(){try{if(console.log("[PeersCaller] Checking call status..."),!this.socket.isConnected())throw new Error("Socket not connected");this.state.setCallStatusLoading(!0),this.state.setCallStatusError(null);const e=yield this.socket.checkCallStatus(this.config.roomId);return this.state.setCallStatusInfo(e),this.state.setCallStatusLoading(!1),console.log("[PeersCaller] Call status received:",e),e}catch(e){console.error("[PeersCaller] Failed to check call status:",e);const t=e instanceof Error?e.message:String(e);throw this.state.setCallStatusLoading(!1),this.state.setCallStatusError(t),this.handleError("NETWORK_ERROR",`Failed to check call status: ${t}`),e}})}handleOffer(e,t){return Le(this,null,function*(){try{if(!this.localParticipant){console.warn(`[PeersCaller] Received offer from ${e} but local participant not initialized`);return}const s=this.localParticipant.getPeerConnection(e);s?(console.log(`[PeersCaller] Processing offer from ${e}`),s.signal({type:"offer",sdp:t.sdp})):console.warn(`[PeersCaller] No peer connection found for offer from ${e}`)}catch(s){console.error(`[PeersCaller] Failed to handle offer from ${e}:`,s)}})}handleAnswer(e,t){return Le(this,null,function*(){try{if(!this.localParticipant){console.warn(`[PeersCaller] Received answer from ${e} but local participant not initialized`);return}const s=this.localParticipant.getPeerConnection(e);s?(console.log(`[PeersCaller] Processing answer from ${e}`),s.signal({type:"answer",sdp:t.sdp})):console.warn(`[PeersCaller] No peer connection found for answer from ${e}`)}catch(s){console.error(`[PeersCaller] Failed to handle answer from ${e}:`,s)}})}handleCandidate(e,t){return Le(this,null,function*(){try{if(!this.localParticipant){console.warn(`[PeersCaller] Received candidate from ${e} but local participant not initialized`);return}const s=this.localParticipant.getPeerConnection(e);s?(console.log(`[PeersCaller] Processing candidate from ${e}`),s.signal({type:"candidate",candidate:t})):console.warn(`[PeersCaller] No peer connection found for candidate from ${e}`)}catch(s){console.error(`[PeersCaller] Failed to handle candidate from ${e}:`,s)}})}handleParticipantStateUpdate(e,t){var s,f;this.state.updateParticipant(e,t),(f=(s=this.callbacks).onParticipantStateChanged)==null||f.call(s,e,t)}handleParticipantLeft(e){var t,s;console.log(`[PeersCaller] Participant ${e} left`);const f=this.participants.get(e);f&&(f.cleanup(),this.participants.delete(e)),this.state.removeParticipant(e),(s=(t=this.callbacks).onParticipantLeft)==null||s.call(t,e)}handleCallEnded(e){return Le(this,null,function*(){var t,s;console.log(`[PeersCaller] Call ended by ${e.endedBy}, reason: ${e.reason}`);try{this.recorder&&this.state.isRecording&&(yield this.stopRecording()),this.cleanupAllParticipants(),this.state.setIsCalling(!1),this.state.setCallStatus("idle"),this.state.clearParticipants(),(s=(t=this.callbacks).onCallEnded)==null||s.call(t,e),console.log("[PeersCaller] Call ended cleanup completed")}catch(f){console.error("[PeersCaller] Error handling call ended:",f)}})}broadcastStateUpdate(e){for(const t of this.participants.keys())this.socket.sendStateUpdate(t,e,this.config.roomId)}handleCallStatusChanged(e){var t,s;console.log("[PeersCaller] Call status changed:",e),this.state.setCallStatusInfo(e),(s=(t=this.callbacks).onCallStatusChanged)==null||s.call(t,e)}cleanupAllParticipants(){for(const e of this.participants.values())e.cleanup();this.participants.clear(),this.localParticipant&&(this.localParticipant.cleanup(),this.localParticipant=null)}handleError(e,t){var s,f;console.error(`[PeersCaller] ${e}: ${t}`),this.state.setError(e,t),(f=(s=this.callbacks).onError)==null||f.call(s,e,t)}fetchIceServers(){return Le(this,null,function*(){try{console.log("[PeersCaller] Fetching ICE servers from backend...");const e=yield this.socket.getIceServers(this.roomId);if(e.error){console.warn("[PeersCaller] Failed to fetch ICE servers from backend:",e.error),console.log("[PeersCaller] Using default ICE servers");return}e.iceServers&&e.iceServers.length>0?this.iceServers=e.iceServers:console.log("[PeersCaller] No ICE servers received from backend, using defaults")}catch(e){console.warn("[PeersCaller] Error fetching ICE servers:",e)}})}forwardSignalToServer(e,t,s){try{switch(console.log(`[PeersCaller] Forwarding signal from ${e} to ${t}:`,s.type),s.type){case"offer":this.socket.sendOffer(t,s,this.config.roomId);break;case"answer":this.socket.sendAnswer(t,s,this.config.roomId);break;case"candidate":this.socket.sendCandidate(t,s.candidate,this.config.roomId);break;case"renegotiate":console.log(`[PeersCaller] Renegotiation signal from ${e} to ${t} - handled locally`);break;default:console.warn(`[PeersCaller] Unknown signal type: ${s.type} - this may indicate a new signal type that needs handling`),this.config.debug&&console.log("[PeersCaller] Unknown signal data:",s);break}}catch(f){console.error(`[PeersCaller] Failed to forward signal from ${e} to ${t}:`,f),this.handleError("SIGNALING_ERROR",`Failed to forward signal: ${f}`)}}}var Xe=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});function ll(r){const[e,t]=ue.useState(null),[s,f]=ue.useState(!1),l=ue.useRef(!1),g=je(C=>C),u=Object.values(je(C=>C.participants)),c=je(C=>C.localParticipant),v=je(C=>C.callStatus==="connected"),h=je(C=>C.isRecording),I=je(C=>C.error),B=ue.useCallback(()=>Xe(null,null,function*(){if(!(l.current||e))try{l.current=!0;const C=new Yo(r,r.callbacks);yield C.initialize(),t(C),f(!0)}catch(C){throw console.error("[useVideoCall] Failed to initialize:",C),l.current=!1,C}}),[r,e]),x=ue.useCallback(C=>Xe(null,null,function*(){if(!e){yield B();return}return e.startCall(C)}),[e,B]),b=ue.useCallback(C=>Xe(null,null,function*(){if(!e){yield B();return}return e.joinCall(C)}),[e,B]),N=ue.useCallback(()=>{e==null||e.endCall()},[e]),T=ue.useCallback(C=>{e==null||e.toggleAudio(C)},[e]),m=ue.useCallback(C=>{e==null||e.toggleVideo(C)},[e]),R=ue.useCallback(()=>Xe(null,null,function*(){if(!e)throw new Error("PeersCaller not initialized");return e.startScreenShare()}),[e]),A=ue.useCallback(()=>Xe(null,null,function*(){if(!e)throw new Error("PeersCaller not initialized");return e.stopScreenShare()}),[e]),P=ue.useCallback(C=>Xe(null,null,function*(){if(!e)throw new Error("PeersCaller not initialized");return e.startRecording(C)}),[e]),k=ue.useCallback(()=>Xe(null,null,function*(){if(!e)throw new Error("PeersCaller not initialized");return e.stopRecording()}),[e]),S=ue.useCallback(()=>{e&&(e.cleanup(),t(null),f(!1),l.current=!1)},[e]);return ue.useEffect(()=>{r.autoInitialize&&!s&&!l.current&&B().catch(console.error)},[r.autoInitialize,s,B]),ue.useEffect(()=>()=>{S()},[S]),{initialize:B,startCall:x,joinCall:b,endCall:N,toggleAudio:T,toggleVideo:m,startScreenShare:R,stopScreenShare:A,startRecording:P,stopRecording:k,callState:g,participants:u,localParticipant:c,isConnected:v,isRecording:h,error:I,cleanup:S,peersCaller:e}}function cl(r){const[e,t]=ue.useState(null),[s,f]=ue.useState(null),l=je(g=>g.participants[r]);return ue.useEffect(()=>{var g;if(l!=null&&l.stream){if(f(l.stream),!e){const u=document.createElement("video");u.autoplay=!0,u.playsInline=!0,u.muted=r===((g=je.getState().localParticipant)==null?void 0:g.userId),t(u)}e&&(e.srcObject=l.stream)}},[l==null?void 0:l.stream,r,e]),ue.useEffect(()=>()=>{e&&(e.srcObject=null)},[e]),{videoElement:e,stream:s,participant:l}}function ul(){const r=je();return{roomId:r.roomId,participants:r.participants,localParticipant:r.localParticipant,isCalling:r.isCalling,isRecording:r.isRecording,recordLoading:r.recordLoading,callStatus:r.callStatus,error:r.error,participantCount:Object.keys(r.participants).length,isConnected:r.callStatus==="connected",hasError:!!r.error}}function fl(){const[r,e]=ue.useState({videoDevices:[],audioDevices:[]}),[t,s]=ue.useState({camera:null,microphone:null}),f=ue.useCallback(()=>Xe(null,null,function*(){try{const u=yield navigator.mediaDevices.enumerateDevices();e({videoDevices:u.filter(c=>c.kind==="videoinput"),audioDevices:u.filter(c=>c.kind==="audioinput")})}catch(u){console.error("[useMediaDevices] Failed to get devices:",u)}}),[]),l=ue.useCallback(()=>Xe(null,null,function*(){try{if("permissions"in navigator){const u=yield navigator.permissions.query({name:"camera"}),c=yield navigator.permissions.query({name:"microphone"});s({camera:u.state,microphone:c.state})}}catch(u){console.error("[useMediaDevices] Failed to check permissions:",u)}}),[]),g=ue.useCallback(()=>Xe(null,null,function*(){try{return(yield navigator.mediaDevices.getUserMedia({video:!0,audio:!0})).getTracks().forEach(c=>c.stop()),yield l(),yield f(),!0}catch(u){return console.error("[useMediaDevices] Failed to request permissions:",u),!1}}),[l,f]);return ue.useEffect(()=>{var u;f(),l();const c=()=>{f()};return(u=navigator.mediaDevices)==null||u.addEventListener("devicechange",c),()=>{var v;(v=navigator.mediaDevices)==null||v.removeEventListener("devicechange",c)}},[f,l]),{devices:r,permissions:t,getDevices:f,checkPermissions:l,requestPermissions:g}}function hl(){const[r,e]=ue.useState({webRTC:!1,getUserMedia:!1,getDisplayMedia:!1,mediaRecorder:!1,speechRecognition:!1});return ue.useEffect(()=>{e({webRTC:!!window.RTCPeerConnection,getUserMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia),getDisplayMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia),mediaRecorder:typeof MediaRecorder!="undefined",speechRecognition:!!(window.SpeechRecognition||window.webkitSpeechRecognition)})},[]),{support:r,isSupported:Object.values(r).every(Boolean),unsupportedFeatures:Object.entries(r).filter(([,t])=>!t).map(([t])=>t)}}function dl(r=""){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,8);return r?`${r}_${e}_${t}`:`${e}_${t}`}const pl=()=>`peer_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,gl=r=>!r||typeof r!="string"?!1:/^peer_\d+_[a-z0-9]{1,9}$/.test(r),yl=r=>{var e,t;return{video:(e=r.video)!=null?e:!0,audio:(t=r.audio)!=null?t:!0}};function ml(r,e,t){const s=`[${r}] ${e}`,f=new Error(s);return t&&(f.details=t),f}function vl(){const r={getUserMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia),getDisplayMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia),RTCPeerConnection:!!window.RTCPeerConnection,MediaRecorder:typeof MediaRecorder!="undefined",WebSocket:typeof WebSocket!="undefined"},e=Object.entries(r).filter(([,t])=>!t).map(([t])=>t);return{supported:e.length===0,features:r,missingFeatures:e}}const wl=()=>{try{return typeof window!="undefined"&&typeof window.RTCPeerConnection!="undefined"&&typeof navigator!="undefined"&&typeof navigator.mediaDevices!="undefined"&&typeof navigator.mediaDevices.getUserMedia!="undefined"}catch(r){return!1}};function bl(){return[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"},{urls:"stun:stun2.l.google.com:19302"},{urls:"stun:stun3.l.google.com:19302"}]}te.CallMediaStream=jn,te.CallParticipant=Cn,te.CallPeerConnection=No,te.CallRecorder=Ho,te.CallSocket=$n,te.PeersCaller=Yo,te.canAcceptMoreParticipants=Ns,te.checkWebRTCSupport=vl,te.formatError=ml,te.formatMediaConstraints=yl,te.generateId=dl,te.generatePeerId=pl,te.getDefaultIceServers=bl,te.getParticipant=xo,te.getParticipantList=Ls,te.isParticipantConnected=Ms,te.isValidPeerId=gl,te.isWebRTCSupported=wl,te.selectCallStatus=Rs,te.selectCallStatusError=Bs,te.selectCallStatusInfo=As,te.selectCallStatusLoading=Is,te.selectCanJoinCall=ks,te.selectError=Ts,te.selectIsCallActive=Os,te.selectIsConnected=Ps,te.selectLocalParticipant=Cs,te.selectParticipantCount=qo,te.selectParticipants=Es,te.useBrowserSupport=hl,te.useCallState=ul,te.useCallStore=je,te.useMediaDevices=fl,te.useParticipantVideo=cl,te.useVideoCall=ll,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})});
|
|
26
|
+
`);const P=A.state[u];if(P==null)return;JSON.stringify(f.getState())!==JSON.stringify(P)&&x(P);return}f.dispatchFromDevtools&&typeof f.dispatch=="function"&&f.dispatch(A)});case"DISPATCH":switch(m.payload.type){case"RESET":return x(b),u===void 0?h==null?void 0:h.init(f.getState()):h==null?void 0:h.init(Mt(c.name));case"COMMIT":if(u===void 0){h==null||h.init(f.getState());return}return h==null?void 0:h.init(Mt(c.name));case"ROLLBACK":return bn(m.state,A=>{if(u===void 0){x(A),h==null||h.init(f.getState());return}x(A[u]),h==null||h.init(Mt(c.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return bn(m.state,A=>{if(u===void 0){x(A);return}JSON.stringify(f.getState())!==JSON.stringify(A[u])&&x(A[u])});case"IMPORT_STATE":{const{nextLiftedState:A}=m.payload,P=(R=A.computedStates.slice(-1)[0])==null?void 0:R.state;if(!P)return;x(u===void 0?P:P[u]),h==null||h.send(null,A);return}case"PAUSE_RECORDING":return B=!B}return}}),b},bn=(r,e)=>{let t;try{t=JSON.parse(r)}catch(s){console.error("[zustand devtools middleware] Could not parse the received json",s)}t!==void 0&&e(t)};var vs=Object.defineProperty,ws=Object.defineProperties,bs=Object.getOwnPropertyDescriptors,Lt=Object.getOwnPropertySymbols,Fo=Object.prototype.hasOwnProperty,Uo=Object.prototype.propertyIsEnumerable,$o=(r,e,t)=>e in r?vs(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,at=(r,e)=>{for(var t in e||(e={}))Fo.call(e,t)&&$o(r,t,e[t]);if(Lt)for(var t of Lt(e))Uo.call(e,t)&&$o(r,t,e[t]);return r},Sn=(r,e)=>ws(r,bs(e)),Ss=r=>typeof r=="symbol"?r:r+"",_s=(r,e)=>{var t={};for(var s in r)Fo.call(r,s)&&e.indexOf(s)<0&&(t[s]=r[s]);if(r!=null&&Lt)for(var s of Lt(r))e.indexOf(s)<0&&Uo.call(r,s)&&(t[s]=r[s]);return t};const jo={roomId:"",participants:{},localParticipant:null,isCalling:!1,isRecording:!1,recordLoading:!1,callStatus:"idle",error:null,callStatusInfo:null,callStatusLoading:!1,callStatusError:null},je=Ie.create()(ms(r=>Sn(at({},jo),{setRoomId:e=>r({roomId:e},!1,"setRoomId"),setLocalParticipant:e=>r({localParticipant:e},!1,"setLocalParticipant"),addParticipant:e=>r(t=>({participants:Sn(at({},t.participants),{[e.userId]:e})}),!1,"addParticipant"),removeParticipant:e=>r(t=>{const s=t.participants,{[e]:f}=s;return{participants:_s(s,[Ss(e)])}},!1,"removeParticipant"),updateParticipant:(e,t)=>r(s=>({participants:Sn(at({},s.participants),{[e]:s.participants[e]?at(at({},s.participants[e]),t):at({userId:e,videoOn:!0,audioOn:!0,screenSharing:!1},t)})}),!1,"updateParticipant"),clearParticipants:()=>r({participants:{}},!1,"clearParticipants"),setCallStatus:e=>r({callStatus:e},!1,"setCallStatus"),setIsCalling:e=>r({isCalling:e},!1,"setIsCalling"),setIsRecording:e=>r({isRecording:e},!1,"setIsRecording"),setRecordLoading:e=>r({recordLoading:e},!1,"setRecordLoading"),setError:(e,t)=>r({error:t||e},!1,"setError"),clearError:()=>r({error:null},!1,"clearError"),setCallStatusInfo:e=>r({callStatusInfo:e},!1,"setCallStatusInfo"),setCallStatusLoading:e=>r({callStatusLoading:e},!1,"setCallStatusLoading"),setCallStatusError:e=>r({callStatusError:e},!1,"setCallStatusError"),resetCall:()=>r(at({},jo),!1,"resetCall")}),{name:"peers-caller-store",enabled:ae.env.NODE_ENV==="development"})),Es=r=>r.participants,qo=r=>Object.keys(r.participants).length,Cs=r=>r.localParticipant,Rs=r=>r.callStatus,Ps=r=>r.callStatus==="connected",Ts=r=>r.error,As=r=>r.callStatusInfo,Is=r=>r.callStatusLoading,Bs=r=>r.callStatusError,ks=r=>{var e;return((e=r.callStatusInfo)==null?void 0:e.canJoin)||!1},Os=r=>{var e;return((e=r.callStatusInfo)==null?void 0:e.hasActiveCall)||!1},xo=r=>je.getState().participants[r],Ms=r=>{const e=xo(r);return!!(e!=null&&e.stream)},Ls=()=>{const r=je.getState();return Object.values(r.participants)},Ns=(r=4)=>qo(je.getState())<r;var Ds=Object.defineProperty,Fs=(r,e,t)=>e in r?Ds(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Us=(r,e,t)=>Fs(r,e+"",t);class Wo{constructor(e){if(Us(this,"store"),e&&typeof e.getState=="function")this.store=e;else{const t=e;this.store={getState:()=>t}}}get state(){return this.store.getState()}}var $s=Object.defineProperty,js=Object.defineProperties,qs=Object.getOwnPropertyDescriptors,Go=Object.getOwnPropertySymbols,xs=Object.prototype.hasOwnProperty,Ws=Object.prototype.propertyIsEnumerable,_n=(r,e,t)=>e in r?$s(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,En=(r,e)=>{for(var t in e||(e={}))xs.call(e,t)&&_n(r,t,e[t]);if(Go)for(var t of Go(e))Ws.call(e,t)&&_n(r,t,e[t]);return r},Gs=(r,e)=>js(r,qs(e)),dt=(r,e,t)=>_n(r,typeof e!="symbol"?e+"":e,t),Nt=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class Cn extends Wo{constructor(e,t={},s=!1){super(je),dt(this,"userId"),dt(this,"mediaStream",null),dt(this,"peerConnections",new Map),dt(this,"remoteStreams",new Map),dt(this,"isLocalParticipant",!1),dt(this,"callbacks"),this.userId=e,this.callbacks=t,this.isLocalParticipant=s;const f={userId:e,videoOn:!0,audioOn:!0,screenSharing:!1};this.isLocalParticipant&&this.state.setLocalParticipant(f),this.state.addParticipant(f)}initialize(e){return Nt(this,null,function*(){var t,s;try{console.log(`[CallParticipant] Initializing participant ${this.userId}`),this.mediaStream=new jn(e);const l={stream:yield this.mediaStream.initialize(),videoElement:this.mediaStream.createVideoElement()};this.updateState(l),console.log(`[CallParticipant] Participant ${this.userId} initialized successfully`)}catch(f){throw console.error(`[CallParticipant] Failed to initialize participant ${this.userId}:`,f),(s=(t=this.callbacks).onError)==null||s.call(t,f),f}})}createPeerConnection(e,t,s){return Nt(this,null,function*(){var f,l;try{if(console.log(`[CallParticipant] Creating peer connection from ${this.userId} to ${e}`),this.peerConnections.has(e)){console.warn(`[CallParticipant] Peer connection to ${e} already exists`);return}const g={onSignal:c=>{var v,h;console.log(`[CallParticipant] Signal from ${this.userId} to ${e}:`,c.type),(h=(v=this.callbacks).onSignal)==null||h.call(v,this.userId,e,c)},onConnect:()=>{var c,v;console.log(`[CallParticipant] ${this.userId} connected to ${e}`),(v=(c=this.callbacks).onPeerConnected)==null||v.call(c,e)},onStream:c=>{var v,h;console.log(`[CallParticipant] Stream received from ${e} by ${this.userId}`),this.remoteStreams.set(e,c),this.state.updateParticipant(e,{stream:c}),(h=(v=this.callbacks).onStreamReceived)==null||h.call(v,e,c)},onClose:()=>{var c,v;console.log(`[CallParticipant] Connection closed between ${this.userId} and ${e}`),this.remoteStreams.delete(e),this.state.updateParticipant(e,{stream:void 0}),(v=(c=this.callbacks).onPeerDisconnected)==null||v.call(c,e)},onError:c=>{var v,h;console.error(`[CallParticipant] Peer connection error between ${this.userId} and ${e}:`,c),(h=(v=this.callbacks).onError)==null||h.call(v,c)}},u=new No(e,Gs(En({},t),{initiator:s}),g);yield u.createConnection(this.getCurrentStream()),this.peerConnections.set(e,u)}catch(g){throw console.error(`[CallParticipant] Failed to create peer connection from ${this.userId} to ${e}:`,g),(l=(f=this.callbacks).onError)==null||l.call(f,g),g}})}getPeerConnection(e){return this.peerConnections.get(e)}signalToPeer(e,t){const s=this.peerConnections.get(e);s?s.signal(t):console.warn(`[CallParticipant] No peer connection found for ${e}`)}toggleAudio(e){this.mediaStream&&(this.mediaStream.toggleAudio(e),this.updateState({audioOn:e}))}toggleVideo(e){this.mediaStream&&(this.mediaStream.toggleVideo(e),this.updateState({videoOn:e}))}startScreenShare(){return Nt(this,null,function*(){var e,t;try{if(!this.mediaStream)throw new Error("Media stream not initialized");console.log(`[CallParticipant] Starting screen share for ${this.userId}`);const s=yield this.mediaStream.startScreenShare(),f=this.mediaStream.getScreenVideoTrack(),l=this.mediaStream.getCameraVideoTrack();if(!f)throw new Error("Failed to get screen video track");for(const[g,u]of this.peerConnections)l?(u.replaceTrack(l,f),console.log(`[CallParticipant] Screen video track replaced for connection with ${g}`)):console.warn(`[CallParticipant] No camera video track to replace for ${g}`);this.updateState({screenSharing:!0,stream:s}),console.log(`[CallParticipant] Screen sharing started for ${this.userId}`)}catch(s){throw console.error(`[CallParticipant] Failed to start screen share for ${this.userId}:`,s),(t=(e=this.callbacks).onError)==null||t.call(e,s),s}})}stopScreenShare(){return Nt(this,null,function*(){var e,t;try{if(!this.mediaStream)throw new Error("Media stream not initialized");console.log(`[CallParticipant] Stopping screen share for ${this.userId}`);const s=this.mediaStream.getScreenVideoTrack();console.log("[CallParticipant] Screen video track found:",!!s);const f=yield this.mediaStream.stopScreenShare(),l=this.mediaStream.getCameraVideoTrack();if(console.log("[CallParticipant] Camera stream:",!!f),console.log("[CallParticipant] Camera video track:",!!l),!l)throw new Error("Failed to get camera video track");for(const[g,u]of this.peerConnections)try{s&&l?(u.replaceTrack(s,l),console.log(`[CallParticipant] Camera video track restored for connection with ${g}`)):(console.log(`[CallParticipant] Updating entire stream for connection with ${g}`),u.addStream(f))}catch(c){console.warn(`[CallParticipant] Failed to replace track for ${g}, trying stream replacement:`,c)}if(this.updateState({screenSharing:!1,stream:f}),this.isLocalParticipant&&this.mediaStream){const g=this.mediaStream.getVideoElement();g&&(g.srcObject=f,console.log(`[CallParticipant] Updated local video element for ${this.userId}`))}console.log(`[CallParticipant] Screen sharing stopped for ${this.userId}`)}catch(s){throw console.error(`[CallParticipant] Failed to stop screen share for ${this.userId}:`,s),(t=(e=this.callbacks).onError)==null||t.call(e,s),s}})}getState(){const e=this.state;return this.isLocalParticipant?e.localParticipant||{userId:this.userId,videoOn:!0,audioOn:!0,screenSharing:!1}:e.participants[this.userId]||{userId:this.userId,videoOn:!0,audioOn:!0,screenSharing:!1}}getUserId(){return this.userId}getMediaStream(){return this.mediaStream}getCurrentStream(){return this.getState().stream}getVideoElement(){return this.getState().videoElement}getRemoteStream(e){return this.remoteStreams.get(e)}getAllRemoteStreams(){return new Map(this.remoteStreams)}getAllPeerConnections(){return new Map(this.peerConnections)}getConnectionStatus(){const e={};for(const[t,s]of this.peerConnections)e[t]=s.isConnected();return e}removePeerConnection(e){const t=this.peerConnections.get(e);t&&(t.destroy(),this.peerConnections.delete(e),this.remoteStreams.delete(e),this.state.updateParticipant(e,{stream:void 0}),console.log(`[CallParticipant] Removed peer connection from ${this.userId} to ${e}`))}updateState(e){var t,s;const f=this.getState();if(Object.keys(e).some(g=>f[g]!==e[g])){const g=En(En({},f),e);this.isLocalParticipant&&this.state.setLocalParticipant(g),this.state.updateParticipant(this.userId,e),(s=(t=this.callbacks).onStateChanged)==null||s.call(t,this.userId,e)}}getDebugInfo(){var e;return{userId:this.userId,state:this.getState(),peerConnections:Array.from(this.peerConnections.keys()),remoteStreams:Array.from(this.remoteStreams.keys()),connectionStatus:this.getConnectionStatus(),mediaStreamInfo:(e=this.mediaStream)==null?void 0:e.getStreamInfo()}}cleanup(){console.log(`[CallParticipant] Cleaning up participant ${this.userId}`),this.state.removeParticipant(this.userId);for(const e of this.peerConnections.values())e.destroy();this.peerConnections.clear(),this.remoteStreams.clear(),this.mediaStream&&(this.mediaStream.cleanup(),this.mediaStream=null),console.log(`[CallParticipant] Participant ${this.userId} cleanup completed`)}}var Rn={exports:{}},Vo;function Vs(){return Vo||(Vo=1,function(r){function e(t,s){var f="Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45";(function(S){typeof RecordRTC=="undefined"&&S&&typeof window=="undefined"&&typeof globalThis!="undefined"&&(globalThis.navigator={userAgent:f,getUserMedia:function(){}},globalThis.console||(globalThis.console={}),(typeof globalThis.console.log=="undefined"||typeof globalThis.console.error=="undefined")&&(globalThis.console.error=globalThis.console.log=globalThis.console.log||function(){console.log(arguments)}),typeof document=="undefined"&&(S.document={documentElement:{appendChild:function(){return""}}},document.createElement=document.captureStream=document.mozCaptureStream=function(){var C={getContext:function(){return C},play:function(){},pause:function(){},drawImage:function(){},toDataURL:function(){return""},style:{}};return C},S.HTMLVideoElement=function(){}),typeof location=="undefined"&&(S.location={protocol:"file:",href:"",hash:""}),typeof screen=="undefined"&&(S.screen={width:0,height:0}),typeof I=="undefined"&&(S.URL={createObjectURL:function(){return""},revokeObjectURL:function(){return""}}),S.window=globalThis)})(typeof globalThis!="undefined"?globalThis:null),s=s||"multi-streams-mixer";var l=[],g=!1,u=document.createElement("canvas"),c=u.getContext("2d");u.style.opacity=0,u.style.position="absolute",u.style.zIndex=-1,u.style.top="-1000em",u.style.left="-1000em",u.className=s,(document.body||document.documentElement).appendChild(u),this.disableLogs=!1,this.frameInterval=10,this.width=360,this.height=240,this.useGainNode=!0;var v=this,h=window.AudioContext;typeof h=="undefined"&&(typeof webkitAudioContext!="undefined"&&(h=webkitAudioContext),typeof mozAudioContext!="undefined"&&(h=mozAudioContext));var I=window.URL;typeof I=="undefined"&&typeof webkitURL!="undefined"&&(I=webkitURL),typeof navigator!="undefined"&&typeof navigator.getUserMedia=="undefined"&&(typeof navigator.webkitGetUserMedia!="undefined"&&(navigator.getUserMedia=navigator.webkitGetUserMedia),typeof navigator.mozGetUserMedia!="undefined"&&(navigator.getUserMedia=navigator.mozGetUserMedia));var B=window.MediaStream;typeof B=="undefined"&&typeof webkitMediaStream!="undefined"&&(B=webkitMediaStream),typeof B!="undefined"&&typeof B.prototype.stop=="undefined"&&(B.prototype.stop=function(){this.getTracks().forEach(function(S){S.stop()})});var x={};typeof h!="undefined"?x.AudioContext=h:typeof webkitAudioContext!="undefined"&&(x.AudioContext=webkitAudioContext);function b(S,C){"srcObject"in C?C.srcObject=S:"mozSrcObject"in C?C.mozSrcObject=S:C.srcObject=S}this.startDrawingFrames=function(){N()};function N(){if(!g){var S=l.length,C=!1,M=[];if(l.forEach(function(X){X.stream||(X.stream={}),X.stream.fullcanvas?C=X:M.push(X)}),C)u.width=C.stream.width,u.height=C.stream.height;else if(M.length){u.width=S>1?M[0].width*2:M[0].width;var W=1;(S===3||S===4)&&(W=2),(S===5||S===6)&&(W=3),(S===7||S===8)&&(W=4),(S===9||S===10)&&(W=5),u.height=M[0].height*W}else u.width=v.width||360,u.height=v.height||240;C&&C instanceof HTMLVideoElement&&T(C),M.forEach(function(X,re){T(X,re)}),setTimeout(N,v.frameInterval)}}function T(S,C){if(!g){var M=0,W=0,X=S.width,re=S.height;C===1&&(M=S.width),C===2&&(W=S.height),C===3&&(M=S.width,W=S.height),C===4&&(W=S.height*2),C===5&&(M=S.width,W=S.height*2),C===6&&(W=S.height*3),C===7&&(M=S.width,W=S.height*3),typeof S.stream.left!="undefined"&&(M=S.stream.left),typeof S.stream.top!="undefined"&&(W=S.stream.top),typeof S.stream.width!="undefined"&&(X=S.stream.width),typeof S.stream.height!="undefined"&&(re=S.stream.height),c.drawImage(S,M,W,X,re),typeof S.stream.onRender=="function"&&S.stream.onRender(c,M,W,X,re,C)}}function m(){g=!1;var S=R(),C=A();return C&&C.getTracks().filter(function(M){return M.kind==="audio"}).forEach(function(M){S.addTrack(M)}),t.forEach(function(M){M.fullcanvas}),S}function R(){k();var S;"captureStream"in u?S=u.captureStream():"mozCaptureStream"in u?S=u.mozCaptureStream():v.disableLogs||console.error("Upgrade to latest Chrome or otherwise enable this flag: chrome://flags/#enable-experimental-web-platform-features");var C=new B;return S.getTracks().filter(function(M){return M.kind==="video"}).forEach(function(M){C.addTrack(M)}),u.stream=C,C}function A(){x.AudioContextConstructor||(x.AudioContextConstructor=new x.AudioContext),v.audioContext=x.AudioContextConstructor,v.audioSources=[],v.useGainNode===!0&&(v.gainNode=v.audioContext.createGain(),v.gainNode.connect(v.audioContext.destination),v.gainNode.gain.value=0);var S=0;if(t.forEach(function(C){if(C.getTracks().filter(function(W){return W.kind==="audio"}).length){S++;var M=v.audioContext.createMediaStreamSource(C);v.useGainNode===!0&&M.connect(v.gainNode),v.audioSources.push(M)}}),!!S)return v.audioDestination=v.audioContext.createMediaStreamDestination(),v.audioSources.forEach(function(C){C.connect(v.audioDestination)}),v.audioDestination.stream}function P(S){var C=document.createElement("video");return b(S,C),C.className=s,C.muted=!0,C.volume=0,C.width=S.width||v.width||360,C.height=S.height||v.height||240,C.play(),C}this.appendStreams=function(S){if(!S)throw"First parameter is required.";S instanceof Array||(S=[S]),S.forEach(function(C){var M=new B;if(C.getTracks().filter(function(re){return re.kind==="video"}).length){var W=P(C);W.stream=C,l.push(W),M.addTrack(C.getTracks().filter(function(re){return re.kind==="video"})[0])}if(C.getTracks().filter(function(re){return re.kind==="audio"}).length){var X=v.audioContext.createMediaStreamSource(C);v.audioDestination=v.audioContext.createMediaStreamDestination(),X.connect(v.audioDestination),M.addTrack(v.audioDestination.stream.getTracks().filter(function(re){return re.kind==="audio"})[0])}t.push(M)})},this.releaseStreams=function(){l=[],g=!0,v.gainNode&&(v.gainNode.disconnect(),v.gainNode=null),v.audioSources.length&&(v.audioSources.forEach(function(S){S.disconnect()}),v.audioSources=[]),v.audioDestination&&(v.audioDestination.disconnect(),v.audioDestination=null),v.audioContext&&v.audioContext.close(),v.audioContext=null,c.clearRect(0,0,u.width,u.height),u.stream&&(u.stream.stop(),u.stream=null)},this.resetVideoStreams=function(S){S&&!(S instanceof Array)&&(S=[S]),k(S)};function k(S){l=[],S=S||t,S.forEach(function(C){if(C.getTracks().filter(function(W){return W.kind==="video"}).length){var M=P(C);M.stream=C,l.push(M)}})}this.name="MultiStreamsMixer",this.toString=function(){return this.name},this.getMixedStream=m}typeof RecordRTC=="undefined"&&(r.exports=e)}(Rn)),Rn.exports}var zs=Vs();const Hs=xt(zs);var Js=Ht();const Ys=xt(Js);class Ks extends Ys{constructor(t,s=navigator.language){super();ze(this,"track",null);ze(this,"trackId",null);ze(this,"recognition",null);ze(this,"recognizing",!1);ze(this,"transcripts",[]);ze(this,"startTime",0);ze(this,"endTime",0);ze(this,"currentStamp",0);ze(this,"start",()=>(this.recognition.start(),this.recognition.stream=this.track,this.recognizing=!0,this.startTime=performance.now(),this));ze(this,"stop",()=>(this.recognition.stop(),this.recognizing=!1,this.endTime=performance.now(),this));("webkitSpeechRecognition"in window||"SpeechRecognition"in window)&&(this.recognition=new(window.SpeechRecognition||window.webkitSpeechRecognition),this.recognition.continuous=!0,this.recognition.interimResults=!0,this.recognition.lang=s,this.track=t,this.recognition.onstart=this.emit("start"),this.recognition.onend=()=>this.emit("end"),this.recognition.onresult=f=>{const{results:l,resultIndex:g}=f;let u="";if(l[g].isFinal&&l[g][0].transcript){const c={sentence:l[g][0].transcript,confidence:l[g][0].confidence,timeStamp:this.currentStamp,endTimeStamp:new Date().getTime()};this.transcripts.push(c),this.emit("sentence",c)}else this.currentStamp=new Date().getTime(),u+=l[g][0].transcript,this.emit("interim",{sentence:u,timeStamp:this.currentStamp});this.emit("result",f)})}}var Xs=Object.defineProperty,zo=Object.getOwnPropertySymbols,Zs=Object.prototype.hasOwnProperty,Qs=Object.prototype.propertyIsEnumerable,Pn=(r,e,t)=>e in r?Xs(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,el=(r,e)=>{for(var t in e||(e={}))Zs.call(e,t)&&Pn(r,t,e[t]);if(zo)for(var t of zo(e))Qs.call(e,t)&&Pn(r,t,e[t]);return r},pt=(r,e,t)=>Pn(r,typeof e!="symbol"?e+"":e,t),Tn=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class Ho{constructor(e={},t={}){pt(this,"mixer",null),pt(this,"recorder",null),pt(this,"localTranscriber",null),pt(this,"isRecording",!1),pt(this,"config"),pt(this,"callbacks"),this.config=el({mimeType:"video/webm;codecs=vp8,opus",videoBitsPerSecond:1e6,audioBitsPerSecond:128e3,interval:1e3},e),this.callbacks=t}startRecording(e,t){return Tn(this,null,function*(){var s,f,l,g;try{if(console.log("[CallRecorder] Starting recording with",e.length,"streams"),this.isRecording)throw new Error("Recording already in progress");if(!t)throw new Error("Recording data is required");this.mixer=new Hs(e),this.mixer.frameInterval=1,this.mixer.startDrawingFrames();const u=e[0];u&&u.getAudioTracks().length>0&&(this.localTranscriber=new Ks(u)),MediaRecorder.isTypeSupported(this.config.mimeType)||(console.warn("[CallRecorder] Preferred mime type not supported, falling back to default"),this.config.mimeType="video/webm");const c=this.mixer.getMixedStream();this.recorder=new MediaRecorder(c,{mimeType:this.config.mimeType,videoBitsPerSecond:this.config.videoBitsPerSecond,audioBitsPerSecond:this.config.audioBitsPerSecond}),this.setupRecorderEventHandlers(t),this.recorder.start(this.config.interval),this.isRecording=!0,this.localTranscriber&&this.localTranscriber.start(),(f=(s=this.callbacks).onRecordingStarted)==null||f.call(s,t),console.log("[CallRecorder] Recording started successfully")}catch(u){throw console.error("[CallRecorder] Failed to start recording:",u),(g=(l=this.callbacks).onError)==null||g.call(l,u),u}})}stopRecording(){return Tn(this,null,function*(){var e,t;try{if(console.log("[CallRecorder] Stopping recording"),!this.isRecording||!this.recorder){console.warn("[CallRecorder] No active recording to stop");return}this.recorder.stop(),this.isRecording=!1,this.localTranscriber&&this.localTranscriber.stop(),this.mixer&&this.mixer.releaseStreams(),console.log("[CallRecorder] Recording stopped successfully")}catch(s){console.error("[CallRecorder] Failed to stop recording:",s),(t=(e=this.callbacks).onError)==null||t.call(e,s)}})}resetVideoStreams(e){this.mixer&&(this.mixer.resetVideoStreams(e),console.log("[CallRecorder] Video streams reset"))}setupRecorderEventHandlers(e){this.recorder&&(this.recorder.ondataavailable=t=>{var s,f;t.data&&t.data.size>0&&((f=(s=this.callbacks).onRecordingChunk)==null||f.call(s,t.data,e))},this.recorder.onstart=()=>{console.log("[CallRecorder] MediaRecorder started")},this.recorder.onstop=()=>{var t,s;console.log("[CallRecorder] MediaRecorder stopped"),(s=(t=this.callbacks).onRecordingStopped)==null||s.call(t,e,this.getTranscripts())},this.recorder.onerror=t=>{var s,f;console.error("[CallRecorder] MediaRecorder error:",t),(f=(s=this.callbacks).onError)==null||f.call(s,new Error(`Recording error: ${t}`))})}getRecordingState(){var e,t;return{isRecording:this.isRecording,isTranscribing:this.localTranscriber!==null,transcriptCount:((t=(e=this.localTranscriber)==null?void 0:e.transcripts)==null?void 0:t.length)||0}}getTranscripts(){var e;return((e=this.localTranscriber)==null?void 0:e.transcripts)||[]}static isRecordingSupported(){return typeof MediaRecorder!="undefined"&&typeof MediaRecorder.isTypeSupported=="function"}static isTranscriptionSupported(){return!!(window.SpeechRecognition||window.webkitSpeechRecognition)}static getSupportedMimeTypes(){return["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm;codecs=h264,opus","video/webm","video/mp4;codecs=h264,aac","video/mp4"].filter(t=>MediaRecorder.isTypeSupported&&MediaRecorder.isTypeSupported(t))}cleanup(){return Tn(this,null,function*(){console.log("[CallRecorder] Cleaning up recorder"),this.isRecording&&(yield this.stopRecording()),this.localTranscriber&&(this.localTranscriber.stop(),this.localTranscriber=null),this.mixer&&(this.mixer.releaseStreams(),this.mixer=null),this.recorder=null})}}var tl=Object.defineProperty,rl=Object.defineProperties,nl=Object.getOwnPropertyDescriptors,Jo=Object.getOwnPropertySymbols,il=Object.prototype.hasOwnProperty,ol=Object.prototype.propertyIsEnumerable,An=(r,e,t)=>e in r?tl(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,al=(r,e)=>{for(var t in e||(e={}))il.call(e,t)&&An(r,t,e[t]);if(Jo)for(var t of Jo(e))ol.call(e,t)&&An(r,t,e[t]);return r},sl=(r,e)=>rl(r,nl(e)),Ge=(r,e,t)=>An(r,typeof e!="symbol"?e+"":e,t),Le=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});class Yo extends Wo{constructor(e,t={}){if(super(je),Ge(this,"config"),Ge(this,"callbacks"),Ge(this,"socket"),Ge(this,"localParticipant",null),Ge(this,"participants",new Map),Ge(this,"recorder",null),Ge(this,"iceServers",[]),Ge(this,"isInitialized",!1),Ge(this,"listenersSetup",!1),Ge(this,"roomId"),Ge(this,"eventListeners",new Map),this.roomId=e.roomId,!this.roomId)throw new Error("roomId must be provided in config");this.config=sl(al({maxParticipants:4,debug:!1,socketPath:"/apis/video-call",mediaConfig:{video:!0,audio:!0}},e),{roomId:this.roomId}),this.callbacks=t,this.socket=new $n(this.config.socketUrl,this.config.token,this.config.socketPath),this.iceServers=this.config.iceServers||[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"}],this.state.setRoomId(this.roomId),console.log("[PeersCaller] Initialized with config:",{roomId:this.roomId,tokenLength:this.config.token.length,maxParticipants:this.config.maxParticipants})}initialize(){return Le(this,null,function*(){try{if(console.log("[PeersCaller] Initializing..."),this.isInitialized){console.warn("[PeersCaller] Already initialized");return}yield this.socket.connect(),yield this.fetchIceServers(),this.setupSocketListeners(),yield this.initializeLocalParticipant(),this.isInitialized=!0,this.state.setCallStatus("idle"),console.log("[PeersCaller] Initialization completed successfully (ready to start/join call)")}catch(e){throw console.error("[PeersCaller] Initialization failed:",e),this.handleError("NETWORK_ERROR",`Failed to initialize: ${e}`),e}})}startCall(){return Le(this,arguments,function*(e=this.config.mediaConfig){var t,s;try{if(console.log("[PeersCaller] Starting call..."),this.isInitialized||(yield this.initialize()),this.localParticipant&&!this.localParticipant.getCurrentStream()){const l={video:e!=null&&e.video&&typeof e.video=="boolean"?e.video:!0,audio:e!=null&&e.audio&&typeof e.audio=="boolean"?e.audio:!0};yield this.localParticipant.initialize(l)}this.state.setIsCalling(!0),this.state.setCallStatus("connecting"),console.log("[PeersCaller] Starting call for room:",this.config.roomId);const f=yield this.socket.startCall(this.config.roomId);if(console.log("[PeersCaller] Received call.start response:",f),f.success)this.state.setCallStatus("connected"),f.participants.forEach(l=>{l!==this.config.userId&&this.handleParticipantJoined(l)}),console.log("[PeersCaller] Call started successfully"),(s=(t=this.callbacks).onCallStarted)==null||s.call(t,f);else{this.state.setIsCalling(!1),this.state.setCallStatus("idle");const l="Failed to start call on server";throw this.handleError("SIGNALING_ERROR",l),console.error("[PeersCaller] Call start failed:",l),new Error(l)}}catch(f){throw console.error("[PeersCaller] Failed to start call:",f),this.handleError("MEDIA_ACCESS_DENIED",`Failed to start call: ${f}`),f}})}joinCall(){return Le(this,arguments,function*(e=this.config.mediaConfig){try{console.log("[PeersCaller] Joining call..."),this.isInitialized||(yield this.initialize());const t=yield this.checkCallStatus();if(!t.hasActiveCall)throw new Error("No active call found");if(!t.canJoin)throw new Error(`Cannot join call: ${t.status==="full"?"Call is full":"Unable to join"}`);if(this.state.setCallStatus("connecting"),this.localParticipant&&!this.localParticipant.getCurrentStream()){const f={video:typeof(e==null?void 0:e.video)=="boolean"?e.video:!0,audio:typeof(e==null?void 0:e.audio)=="boolean"?e.audio:!0};console.log("[PeersCaller] Initializing local media with config:",f),yield this.localParticipant.initialize(f)}console.log("[PeersCaller] Joining call for room:",this.config.roomId);const s=yield this.socket.joinRoom(this.config.roomId);console.log("[PeersCaller] Received call.join response:",s),this.state.setCallStatus("connected"),this.state.setIsCalling(!0),s.participants.forEach(f=>{f!==this.config.userId&&this.handleParticipantJoined(f)}),console.log("[PeersCaller] Joined call successfully")}catch(t){throw console.error("[PeersCaller] Failed to join call:",t),this.state.setCallStatus("idle"),this.handleError("INVALID_ROOM_ID",`Failed to join call: ${t}`),t}})}endCall(){return Le(this,null,function*(){try{console.log("[PeersCaller] Ending call..."),this.recorder&&this.state.isRecording&&(yield this.stopRecording());try{yield this.socket.endCallForAll(this.config.roomId),console.log("[PeersCaller] End call request sent to server")}catch(e){console.warn("[PeersCaller] Failed to notify server of call end:",e)}this.cleanupAllParticipants(),this.state.setIsCalling(!1),this.state.setCallStatus("idle"),this.state.clearParticipants(),console.log("[PeersCaller] Call ended successfully")}catch(e){console.error("[PeersCaller] Error ending call:",e)}})}leaveCall(){return Le(this,null,function*(){try{console.log("[PeersCaller] Leaving call..."),console.log("[PeersCaller] Leaving call for room:",this.config.roomId);const e=yield this.socket.leaveCall(this.config.roomId);if(console.log("[PeersCaller] Received call.leave response:",e),e.success)this.cleanupAllParticipants(),this.state.setIsCalling(!1),this.state.setCallStatus("idle"),this.state.clearParticipants(),console.log("[PeersCaller] Left call successfully");else{const t="Failed to leave call on server";throw this.handleError("SIGNALING_ERROR",t),console.error("[PeersCaller] Call leave failed:",t),new Error(t)}}catch(e){throw console.error("[PeersCaller] Failed to leave call:",e),this.handleError("SIGNALING_ERROR",`Failed to leave call: ${e}`),e}})}toggleAudio(e){this.localParticipant&&(this.localParticipant.toggleAudio(e),this.broadcastStateUpdate({audioOn:e}),console.log(`[PeersCaller] Audio ${e?"enabled":"disabled"}`))}toggleVideo(e){this.localParticipant&&(this.localParticipant.toggleVideo(e),this.broadcastStateUpdate({videoOn:e}),console.log(`[PeersCaller] Video ${e?"enabled":"disabled"}`))}startScreenShare(){return Le(this,null,function*(){try{if(!this.localParticipant)throw new Error("Local participant not initialized");yield this.localParticipant.startScreenShare(),this.broadcastStateUpdate({screenSharing:!0}),console.log("[PeersCaller] Screen sharing started")}catch(e){throw console.error("[PeersCaller] Failed to start screen share:",e),this.handleError("MEDIA_ACCESS_DENIED",`Failed to start screen share: ${e}`),e}})}stopScreenShare(){return Le(this,null,function*(){try{if(!this.localParticipant)throw new Error("Local participant not initialized");yield this.localParticipant.stopScreenShare(),this.broadcastStateUpdate({screenSharing:!1}),console.log("[PeersCaller] Screen sharing stopped")}catch(e){throw console.error("[PeersCaller] Failed to stop screen share:",e),e}})}startRecording(e,t){return Le(this,null,function*(){var s;try{if(console.log("[PeersCaller] Starting recording..."),this.state.isRecording){console.warn("[PeersCaller] Recording already in progress");return}const f=[],l=(s=this.localParticipant)==null?void 0:s.getCurrentStream();l&&f.push(l);for(const g of this.participants.values()){const u=g.getCurrentStream();u&&f.push(u)}if(f.length===0)throw new Error("No streams available for recording");this.recorder=new Ho(t,{onRecordingStarted:g=>{this.socket.startRecording(this.config.roomId,g.id)},onRecordingChunk:(g,u)=>{this.socket.sendRecordingChunk(this.config.roomId,u.id,g)},onRecordingStopped:(g,u)=>{this.socket.endRecording(this.config.roomId,g.id,u)},onTranscriptReceived:g=>{this.socket.sendTranscript(this.config.roomId,g.text)},onError:g=>{this.handleError("RECORDING_FAILED",g.message)}}),yield this.recorder.startRecording(f,e),this.state.setIsRecording(!0),console.log("[PeersCaller] Recording started successfully")}catch(f){throw console.error("[PeersCaller] Failed to start recording:",f),this.handleError("RECORDING_FAILED",`Failed to start recording: ${f}`),f}})}stopRecording(){return Le(this,null,function*(){try{if(console.log("[PeersCaller] Stopping recording..."),!this.recorder||!this.state.isRecording){console.warn("[PeersCaller] No active recording to stop");return}yield this.recorder.stopRecording(),this.state.setIsRecording(!1),console.log("[PeersCaller] Recording stopped successfully")}catch(e){throw console.error("[PeersCaller] Failed to stop recording:",e),e}})}getCallState(){return this.state}getLocalParticipant(){return this.localParticipant}getParticipants(){return new Map(this.participants)}getParticipant(e){return this.participants.get(e)}getDebugInfo(){return{isInitialized:this.isInitialized,localParticipant:this.localParticipant?{userId:this.localParticipant.getUserId(),hasStream:!!this.localParticipant.getCurrentStream(),streamTracks:this.localParticipant.getCurrentStream()?{video:this.localParticipant.getCurrentStream().getVideoTracks().length,audio:this.localParticipant.getCurrentStream().getAudioTracks().length}:null,peerConnections:Array.from(this.localParticipant.getAllPeerConnections().keys()),connectionStatus:this.localParticipant.getConnectionStatus()}:null,remoteParticipants:Array.from(this.participants.keys()),storeState:this.state,socketConnected:this.socket.isConnected()}}cleanup(){console.log("[PeersCaller] Cleaning up..."),this.state.isCalling&&this.endCall(),this.cleanupSocketListeners(),this.cleanupAllParticipants(),this.recorder&&(this.recorder.cleanup(),this.recorder=null),this.socket.disconnect(),this.state.resetCall(),this.isInitialized=!1,console.log("[PeersCaller] Cleanup completed")}initializeLocalParticipant(){return Le(this,null,function*(){this.localParticipant=new Cn(this.config.userId,{onSignal:(e,t,s)=>{this.forwardSignalToServer(e,t,s)},onError:e=>this.handleError("UNKNOWN_ERROR",e.message)},!0),console.log("[PeersCaller] Local participant created (media not initialized yet)")})}setupSocketListeners(){if(this.listenersSetup){console.log("[PeersCaller] Socket listeners already set up, skipping...");return}this.cleanupSocketListeners(),console.log("[PeersCaller] Setting up socket listeners...");const e=T=>{this.handleParticipantJoined(T.userId)};this.socket.on("call.participant.joined",e),this.eventListeners.set("call.participant.joined",e);const t=T=>{this.handleParticipantLeft(T.userId)};this.socket.on("call.participant.left",t),this.eventListeners.set("call.participant.left",t);const s=T=>{T.participants.forEach(m=>{m!==this.config.userId&&this.handleParticipantJoined(m)})};this.socket.on("call.participants",s),this.eventListeners.set("call.participants",s);const f=()=>{this.state.setIsCalling(!1)};this.socket.on("call.left",f),this.eventListeners.set("call.left",f);const l=T=>{var m,R;console.error("[PeersCaller] Server error:",T),(R=(m=this.callbacks).onError)==null||R.call(m,T.error,T.message)};this.socket.on("call.error",l),this.eventListeners.set("call.error",l);const g=T=>{this.handleOffer(T.from,T.offer)};this.socket.on("call.offer",g),this.eventListeners.set("call.offer",g);const u=T=>{this.handleAnswer(T.from,T.answer)};this.socket.on("call.answer",u),this.eventListeners.set("call.answer",u);const c=T=>{this.handleCandidate(T.from,T.candidate)};this.socket.on("call.candidate",c),this.eventListeners.set("call.candidate",c);const v=T=>{this.handleParticipantStateUpdate(T.from,T.state)};this.socket.on("call.state",v),this.eventListeners.set("call.state",v);const h=T=>{this.handleCallEnded(T)};this.socket.on("call.ended",h),this.eventListeners.set("call.ended",h);const I=T=>{this.handleCallStatusChanged(T)};this.socket.on("call.status.changed",I),this.eventListeners.set("call.status.changed",I);const B=T=>{console.log("[PeersCaller] Recording started:",T.recordingId),this.state.setIsRecording(!0)};this.socket.on("call.recording.start",B),this.eventListeners.set("call.recording.start",B);const x=T=>{console.log("[PeersCaller] Recording chunk received:",T)};this.socket.on("call.recording.chunk.received",x),this.eventListeners.set("call.recording.chunk.received",x);const b=T=>{console.log("[PeersCaller] Recording ended:",T.recordingId),this.state.setIsRecording(!1)};this.socket.on("call.recording.end",b),this.eventListeners.set("call.recording.end",b);const N=T=>{console.log("[PeersCaller] Transcript received:",T)};this.socket.on("call.transcript",N),this.eventListeners.set("call.transcript",N),this.listenersSetup=!0,console.log("[PeersCaller] Socket listeners set up successfully")}cleanupSocketListeners(){if(!(!this.listenersSetup&&this.eventListeners.size===0)){console.log("[PeersCaller] Cleaning up socket listeners...");for(const[e,t]of this.eventListeners)this.socket.off(e,t);this.eventListeners.clear(),this.listenersSetup=!1,console.log("[PeersCaller] Socket listeners cleaned up successfully")}}handleParticipantJoined(e){return Le(this,null,function*(){var t,s;try{if(e===this.config.userId||this.participants.has(e))return;if(this.participants.size>=this.config.maxParticipants-1){console.warn("[PeersCaller] Maximum participants reached");return}console.log(`[PeersCaller] Participant ${e} joined`);const f=new Cn(e,{onStreamReceived:(u,c)=>{var v,h;(h=(v=this.callbacks).onStreamReceived)==null||h.call(v,u,c)},onPeerConnected:u=>{console.log(`[PeersCaller] Peer connection established with ${u}`)},onPeerDisconnected:u=>{this.handleParticipantLeft(u)},onSignal:(u,c,v)=>{this.forwardSignalToServer(u,c,v)},onError:u=>{this.handleError("PEER_CONNECTION_FAILED",u.message)}},!1);if(this.participants.set(e,f),!this.localParticipant){console.error("[PeersCaller] Cannot create peer connection - local participant not initialized");return}const l=this.config.userId<e,g={iceServers:this.iceServers,initiator:l};yield this.localParticipant.createPeerConnection(e,g,l),(s=(t=this.callbacks).onParticipantJoined)==null||s.call(t,{userId:e,videoOn:!0,audioOn:!0,screenSharing:!1})}catch(f){console.error(`[PeersCaller] Failed to handle participant ${e} joining:`,f)}})}checkCallStatus(){return Le(this,null,function*(){try{if(console.log("[PeersCaller] Checking call status..."),!this.socket.isConnected())throw new Error("Socket not connected");this.state.setCallStatusLoading(!0),this.state.setCallStatusError(null);const e=yield this.socket.checkCallStatus(this.config.roomId);return this.state.setCallStatusInfo(e),this.state.setCallStatusLoading(!1),console.log("[PeersCaller] Call status received:",e),e}catch(e){console.error("[PeersCaller] Failed to check call status:",e);const t=e instanceof Error?e.message:String(e);throw this.state.setCallStatusLoading(!1),this.state.setCallStatusError(t),this.handleError("NETWORK_ERROR",`Failed to check call status: ${t}`),e}})}handleOffer(e,t){return Le(this,null,function*(){try{if(!this.localParticipant){console.warn(`[PeersCaller] Received offer from ${e} but local participant not initialized`);return}const s=this.localParticipant.getPeerConnection(e);s?(console.log(`[PeersCaller] Processing offer from ${e}`),s.signal({type:"offer",sdp:t.sdp})):console.warn(`[PeersCaller] No peer connection found for offer from ${e}`)}catch(s){console.error(`[PeersCaller] Failed to handle offer from ${e}:`,s)}})}handleAnswer(e,t){return Le(this,null,function*(){try{if(!this.localParticipant){console.warn(`[PeersCaller] Received answer from ${e} but local participant not initialized`);return}const s=this.localParticipant.getPeerConnection(e);s?(console.log(`[PeersCaller] Processing answer from ${e}`),s.signal({type:"answer",sdp:t.sdp})):console.warn(`[PeersCaller] No peer connection found for answer from ${e}`)}catch(s){console.error(`[PeersCaller] Failed to handle answer from ${e}:`,s)}})}handleCandidate(e,t){return Le(this,null,function*(){try{if(!this.localParticipant){console.warn(`[PeersCaller] Received candidate from ${e} but local participant not initialized`);return}const s=this.localParticipant.getPeerConnection(e);s?(console.log(`[PeersCaller] Processing candidate from ${e}`),s.signal({type:"candidate",candidate:t})):console.warn(`[PeersCaller] No peer connection found for candidate from ${e}`)}catch(s){console.error(`[PeersCaller] Failed to handle candidate from ${e}:`,s)}})}handleParticipantStateUpdate(e,t){var s,f;this.state.updateParticipant(e,t),(f=(s=this.callbacks).onParticipantStateChanged)==null||f.call(s,e,t)}handleParticipantLeft(e){var t,s;console.log(`[PeersCaller] Participant ${e} left`);const f=this.participants.get(e);f&&(f.cleanup(),this.participants.delete(e)),this.state.removeParticipant(e),(s=(t=this.callbacks).onParticipantLeft)==null||s.call(t,e)}handleCallEnded(e){return Le(this,null,function*(){var t,s;console.log(`[PeersCaller] Call ended by ${e.endedBy}, reason: ${e.reason}`);try{this.recorder&&this.state.isRecording&&(yield this.stopRecording()),this.cleanupAllParticipants(),this.state.setIsCalling(!1),this.state.setCallStatus("idle"),this.state.clearParticipants(),(s=(t=this.callbacks).onCallEnded)==null||s.call(t,e),console.log("[PeersCaller] Call ended cleanup completed")}catch(f){console.error("[PeersCaller] Error handling call ended:",f)}})}broadcastStateUpdate(e){for(const t of this.participants.keys())this.socket.sendStateUpdate(t,e,this.config.roomId)}handleCallStatusChanged(e){var t,s;console.log("[PeersCaller] Call status changed:",e),this.state.setCallStatusInfo(e),(s=(t=this.callbacks).onCallStatusChanged)==null||s.call(t,e)}cleanupAllParticipants(){for(const e of this.participants.values())e.cleanup();this.participants.clear(),this.localParticipant&&(this.localParticipant.cleanup(),this.localParticipant=null)}handleError(e,t){var s,f;console.error(`[PeersCaller] ${e}: ${t}`),this.state.setError(e,t),(f=(s=this.callbacks).onError)==null||f.call(s,e,t)}fetchIceServers(){return Le(this,null,function*(){try{console.log("[PeersCaller] Fetching ICE servers from backend...");const e=yield this.socket.getIceServers(this.roomId);if(e.error){console.warn("[PeersCaller] Failed to fetch ICE servers from backend:",e.error),console.log("[PeersCaller] Using default ICE servers");return}e.iceServers&&e.iceServers.length>0?this.iceServers=e.iceServers:console.log("[PeersCaller] No ICE servers received from backend, using defaults")}catch(e){console.warn("[PeersCaller] Error fetching ICE servers:",e)}})}forwardSignalToServer(e,t,s){try{switch(console.log(`[PeersCaller] Forwarding signal from ${e} to ${t}:`,s.type),s.type){case"offer":this.socket.sendOffer(t,s,this.config.roomId);break;case"answer":this.socket.sendAnswer(t,s,this.config.roomId);break;case"candidate":this.socket.sendCandidate(t,s.candidate,this.config.roomId);break;case"renegotiate":console.log(`[PeersCaller] Renegotiation signal from ${e} to ${t} - handled locally`);break;default:console.warn(`[PeersCaller] Unknown signal type: ${s.type} - this may indicate a new signal type that needs handling`),this.config.debug&&console.log("[PeersCaller] Unknown signal data:",s);break}}catch(f){console.error(`[PeersCaller] Failed to forward signal from ${e} to ${t}:`,f),this.handleError("SIGNALING_ERROR",`Failed to forward signal: ${f}`)}}}var Xe=(r,e,t)=>new Promise((s,f)=>{var l=c=>{try{u(t.next(c))}catch(v){f(v)}},g=c=>{try{u(t.throw(c))}catch(v){f(v)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,g);u((t=t.apply(r,e)).next())});function ll(r){const[e,t]=ue.useState(null),[s,f]=ue.useState(!1),l=ue.useRef(!1),g=je(C=>C),u=Object.values(je(C=>C.participants)),c=je(C=>C.localParticipant),v=je(C=>C.callStatus==="connected"),h=je(C=>C.isRecording),I=je(C=>C.error),B=ue.useCallback(()=>Xe(null,null,function*(){if(!(l.current||e))try{l.current=!0;const C=new Yo(r,r.callbacks);yield C.initialize(),t(C),f(!0)}catch(C){throw console.error("[useVideoCall] Failed to initialize:",C),l.current=!1,C}}),[r,e]),x=ue.useCallback(C=>Xe(null,null,function*(){if(!e){yield B();return}return e.startCall(C)}),[e,B]),b=ue.useCallback(C=>Xe(null,null,function*(){if(!e){yield B();return}return e.joinCall(C)}),[e,B]),N=ue.useCallback(()=>{e==null||e.endCall()},[e]),T=ue.useCallback(C=>{e==null||e.toggleAudio(C)},[e]),m=ue.useCallback(C=>{e==null||e.toggleVideo(C)},[e]),R=ue.useCallback(()=>Xe(null,null,function*(){if(!e)throw new Error("PeersCaller not initialized");return e.startScreenShare()}),[e]),A=ue.useCallback(()=>Xe(null,null,function*(){if(!e)throw new Error("PeersCaller not initialized");return e.stopScreenShare()}),[e]),P=ue.useCallback(C=>Xe(null,null,function*(){if(!e)throw new Error("PeersCaller not initialized");return e.startRecording(C)}),[e]),k=ue.useCallback(()=>Xe(null,null,function*(){if(!e)throw new Error("PeersCaller not initialized");return e.stopRecording()}),[e]),S=ue.useCallback(()=>{e&&(e.cleanup(),t(null),f(!1),l.current=!1)},[e]);return ue.useEffect(()=>{r.autoInitialize&&!s&&!l.current&&B().catch(console.error)},[r.autoInitialize,s,B]),ue.useEffect(()=>()=>{S()},[S]),{initialize:B,startCall:x,joinCall:b,endCall:N,toggleAudio:T,toggleVideo:m,startScreenShare:R,stopScreenShare:A,startRecording:P,stopRecording:k,callState:g,participants:u,localParticipant:c,isConnected:v,isRecording:h,error:I,cleanup:S,peersCaller:e}}function cl(r){const[e,t]=ue.useState(null),[s,f]=ue.useState(null),l=je(g=>g.participants[r]);return ue.useEffect(()=>{var g;if(l!=null&&l.stream){if(f(l.stream),!e){const u=document.createElement("video");u.autoplay=!0,u.playsInline=!0,u.muted=r===((g=je.getState().localParticipant)==null?void 0:g.userId),t(u)}e&&(e.srcObject=l.stream)}},[l==null?void 0:l.stream,r,e]),ue.useEffect(()=>()=>{e&&(e.srcObject=null)},[e]),{videoElement:e,stream:s,participant:l}}function ul(){const r=je();return{roomId:r.roomId,participants:r.participants,localParticipant:r.localParticipant,isCalling:r.isCalling,isRecording:r.isRecording,recordLoading:r.recordLoading,callStatus:r.callStatus,error:r.error,participantCount:Object.keys(r.participants).length,isConnected:r.callStatus==="connected",hasError:!!r.error}}function fl(){const[r,e]=ue.useState({videoDevices:[],audioDevices:[]}),[t,s]=ue.useState({camera:null,microphone:null}),f=ue.useCallback(()=>Xe(null,null,function*(){try{const u=yield navigator.mediaDevices.enumerateDevices();e({videoDevices:u.filter(c=>c.kind==="videoinput"),audioDevices:u.filter(c=>c.kind==="audioinput")})}catch(u){console.error("[useMediaDevices] Failed to get devices:",u)}}),[]),l=ue.useCallback(()=>Xe(null,null,function*(){try{if("permissions"in navigator){const u=yield navigator.permissions.query({name:"camera"}),c=yield navigator.permissions.query({name:"microphone"});s({camera:u.state,microphone:c.state})}}catch(u){console.error("[useMediaDevices] Failed to check permissions:",u)}}),[]),g=ue.useCallback(()=>Xe(null,null,function*(){try{return(yield navigator.mediaDevices.getUserMedia({video:!0,audio:!0})).getTracks().forEach(c=>c.stop()),yield l(),yield f(),!0}catch(u){return console.error("[useMediaDevices] Failed to request permissions:",u),!1}}),[l,f]);return ue.useEffect(()=>{var u;f(),l();const c=()=>{f()};return(u=navigator.mediaDevices)==null||u.addEventListener("devicechange",c),()=>{var v;(v=navigator.mediaDevices)==null||v.removeEventListener("devicechange",c)}},[f,l]),{devices:r,permissions:t,getDevices:f,checkPermissions:l,requestPermissions:g}}function hl(){const[r,e]=ue.useState({webRTC:!1,getUserMedia:!1,getDisplayMedia:!1,mediaRecorder:!1,speechRecognition:!1});return ue.useEffect(()=>{e({webRTC:!!window.RTCPeerConnection,getUserMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia),getDisplayMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia),mediaRecorder:typeof MediaRecorder!="undefined",speechRecognition:!!(window.SpeechRecognition||window.webkitSpeechRecognition)})},[]),{support:r,isSupported:Object.values(r).every(Boolean),unsupportedFeatures:Object.entries(r).filter(([,t])=>!t).map(([t])=>t)}}function dl(r=""){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,8);return r?`${r}_${e}_${t}`:`${e}_${t}`}const pl=()=>`peer_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,gl=r=>!r||typeof r!="string"?!1:/^peer_\d+_[a-z0-9]{1,9}$/.test(r),yl=r=>{var e,t;return{video:(e=r.video)!=null?e:!0,audio:(t=r.audio)!=null?t:!0}};function ml(r,e,t){const s=`[${r}] ${e}`,f=new Error(s);return t&&(f.details=t),f}function vl(){const r={getUserMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia),getDisplayMedia:!!(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia),RTCPeerConnection:!!window.RTCPeerConnection,MediaRecorder:typeof MediaRecorder!="undefined",WebSocket:typeof WebSocket!="undefined"},e=Object.entries(r).filter(([,t])=>!t).map(([t])=>t);return{supported:e.length===0,features:r,missingFeatures:e}}const wl=()=>{try{return typeof window!="undefined"&&typeof window.RTCPeerConnection!="undefined"&&typeof navigator!="undefined"&&typeof navigator.mediaDevices!="undefined"&&typeof navigator.mediaDevices.getUserMedia!="undefined"}catch(r){return!1}};function bl(){return[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"},{urls:"stun:stun2.l.google.com:19302"},{urls:"stun:stun3.l.google.com:19302"}]}te.CallMediaStream=jn,te.CallParticipant=Cn,te.CallPeerConnection=No,te.CallRecorder=Ho,te.CallSocket=$n,te.PeersCaller=Yo,te.canAcceptMoreParticipants=Ns,te.checkWebRTCSupport=vl,te.formatError=ml,te.formatMediaConstraints=yl,te.generateId=dl,te.generatePeerId=pl,te.getDefaultIceServers=bl,te.getParticipant=xo,te.getParticipantList=Ls,te.isParticipantConnected=Ms,te.isValidPeerId=gl,te.isWebRTCSupported=wl,te.selectCallStatus=Rs,te.selectCallStatusError=Bs,te.selectCallStatusInfo=As,te.selectCallStatusLoading=Is,te.selectCanJoinCall=ks,te.selectError=Ts,te.selectIsCallActive=Os,te.selectIsConnected=Ps,te.selectLocalParticipant=Cs,te.selectParticipantCount=qo,te.selectParticipants=Es,te.useBrowserSupport=hl,te.useCallState=ul,te.useCallStore=je,te.useMediaDevices=fl,te.useParticipantVideo=cl,te.useVideoCall=ll,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})});
|
|
27
27
|
//# sourceMappingURL=peers-caller.umd.js.map
|