sceyt-call 1.0.0

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/.editorconfig ADDED
@@ -0,0 +1,4 @@
1
+ root=true
2
+
3
+ [*]
4
+ max_line_length = 120
package/.eslintrc.js ADDED
@@ -0,0 +1,22 @@
1
+ module.exports = {
2
+ parser: "@typescript-eslint/parser", // Specifies the ESLint parser
3
+ extends: [
4
+ "plugin:prettier/recommended",
5
+ "plugin:@typescript-eslint/recommended", // Uses the recommended rules from @typescript-eslint/eslint-plugin
6
+ ],
7
+ parserOptions: {
8
+ ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
9
+ sourceType: "module", // Allows for the use of imports
10
+ },
11
+ rules: {
12
+ "max-line-length": [
13
+ true,
14
+ {
15
+ limit: 140,
16
+ "ignore-pattern": "^import |^export {(.*?)}",
17
+ },
18
+ ],
19
+ // Place to specify ESLint rules - can be used to overwrite rules specified from the extended configs
20
+ // e.g. "@typescript-eslint/explicit-function-return-type": "off",
21
+ },
22
+ };
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # Getting Started with Sceyt Call SDK
2
+ To begin using Sceyt Call SDK in your project, you need to install two essential packages: sceyt-chat and
3
+ sceyt-call. Follow these steps to set up your environment:
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ # If you use npm:
9
+ npm install sceyt-chat
10
+ npm install sceyt-call
11
+
12
+ # Or if you use Yarn:
13
+ yarn add sceyt-chat
14
+ yarn add sceyt-call
15
+ ```
16
+
17
+ ## Initializing Sceyt Chat in Your Application
18
+
19
+ ### 1. Register on Sceyt.com:
20
+ Visit [sceyt.com](https://sceyt.com 'sceyt.com') and sign up for an account. Follow the registration process to create your account.
21
+
22
+ ### 2. Create an Application:
23
+ Once your account is set up, navigate to the dashboard and create a new application. This
24
+ application will be the basis for integrating Sceyt chat into your project.
25
+
26
+ ### 3. Obtain Application Credentials:
27
+ After creating your application, you will receive unique credentials – appId and apiUrl.
28
+ These are critical for the initialization process and will be used to authenticate and configure your chat instance.
29
+
30
+ ### 4. Initialize Sceyt Chat:
31
+ Then, initialize Sceyt chat by using the credentials obtained from your Sceyt dashboard. Here's an example of how you
32
+ can do this in your application:\
33
+ **clientId:** serves as a unique identifier for each device or connection instance. This is crucial for managing user
34
+ sessions across different devices or browsers.The clientId distinguishes each connection or device from others. When a
35
+ user logs in from a new device or browser, they must use a unique clientId. Otherwise, the previously established
36
+ connection with the same userId will be disconnected.
37
+
38
+ ```tsx
39
+ import SceytChatClient from 'sceyt-chat'
40
+
41
+ const chatClient = new SceytChatClient('{apiUrl}', '{appId}', '{clientId}')
42
+
43
+ // Before connecting to the SceytChat service, it's a good idea to add connection listeners to the SceytChat client to handle various events that may occur during the connection process. Here are connection listeners you can add:
44
+
45
+ // Create a new connection listener
46
+ const connectionListener = new chatClient.ConnectionListener();
47
+
48
+ // Set the listener function for the listen connection status changes
49
+ connectionListener.onConnectionStatusChanged = async (status) => {
50
+ logger.info('Connection status changed:', status);
51
+ };
52
+
53
+ // Set the listener function for the 'tokenWillExpire' event
54
+ connectionListener.onTokenWillExpire = async (timeInterval) => {
55
+ logger.info('Token will expire in', timeInterval/1000, 'seconds');
56
+ };
57
+
58
+ // Set the listener function for the 'tokenExpired' event
59
+ connectionListener.onTokenExpired = async () => {
60
+ logger.info('Access token has expired');
61
+ };
62
+
63
+ // Add the connection listener with unique id to the SceytChat client
64
+ chatClient.addConnectionListener('my-connection-listener-id', connectionListener);
65
+
66
+ // Connect to the Sceyt Chat API with a valid access token
67
+ chatClient.connect('{accessToken}');
68
+ ```
69
+ #
70
+ #### Prior to using the Sceyt Call SDK, verify that the SceytChatClient is both initialized and connected. This can be done by monitoring changes in the connection status changes listener.
71
+
72
+ ## Initializing Sceyt Call
73
+
74
+ ```tsx
75
+
76
+ import SceytCallClient from 'sceyt-call';
77
+
78
+ const callClient = new SceytCallClient(chatClient)
79
+ ```
80
+
81
+ #### To listen to the call invitation, you need to set up a listener on callClient after initialization.
82
+
83
+ ```tsx
84
+ const handleInvitedToCall = async (call: any) => {
85
+ // Handle call invitation here
86
+ }
87
+
88
+ callClient.onInvitedToCall = handleInvitedToCall
89
+ ```
90
+
91
+ #### To start a call, you need to call the joinCall method of the callClient object and pass the necessary properties. This method will return a call object.
92
+ ```tsx
93
+ const joinedCall = await callClient.joinCall({
94
+ callId: 'unique-call-id',
95
+ mediaFlow: 'p2p' || 'sfu',
96
+ participantIds: ['participant-id-1', 'participant-id-2'],
97
+ videoCall: true || false,
98
+ })
99
+ ```
100
+
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["sceyt-call"]=t():e["sceyt-call"]=t()}(this,(()=>(()=>{var e={43:function(e,t,n){var i,a;!function(o,s){"use strict";i=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),i=["trace","debug","info","warn","error"],a={},o=null;function s(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function r(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(){for(var n=this.getLevel(),a=0;a<i.length;a++){var o=i[a];this[o]=a<n?e:this.methodFactory(o,n,this.name)}if(this.log=this.debug,typeof console===t&&n<this.levels.SILENT)return"No console available for logging"}function l(e){return function(){typeof console!==t&&(c.call(this),this[e].apply(this,arguments))}}function d(i,a,o){return function(i){return"debug"===i&&(i="log"),typeof console!==t&&("trace"===i&&n?r:void 0!==console[i]?s(console,i):void 0!==console.log?s(console,"log"):e)}(i)||l.apply(this,arguments)}function u(e,n){var s,r,l,u=this,p="loglevel";function h(){var e;if(typeof window!==t&&p){try{e=window.localStorage[p]}catch(e){}if(typeof e===t)try{var n=window.document.cookie,i=encodeURIComponent(p),a=n.indexOf(i+"=");-1!==a&&(e=/^([^;]+)/.exec(n.slice(a+i.length+1))[1])}catch(e){}return void 0===u.levels[e]&&(e=void 0),e}}function f(e){var t=e;if("string"==typeof t&&void 0!==u.levels[t.toUpperCase()]&&(t=u.levels[t.toUpperCase()]),"number"==typeof t&&t>=0&&t<=u.levels.SILENT)return t;throw new TypeError("log.setLevel() called with invalid level: "+e)}"string"==typeof e?p+=":"+e:"symbol"==typeof e&&(p=void 0),u.name=e,u.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},u.methodFactory=n||d,u.getLevel=function(){return null!=l?l:null!=r?r:s},u.setLevel=function(e,n){return l=f(e),!1!==n&&function(e){var n=(i[e]||"silent").toUpperCase();if(typeof window!==t&&p){try{return void(window.localStorage[p]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(p)+"="+n+";"}catch(e){}}}(l),c.call(u)},u.setDefaultLevel=function(e){r=f(e),h()||u.setLevel(e,!1)},u.resetLevel=function(){l=null,function(){if(typeof window!==t&&p){try{window.localStorage.removeItem(p)}catch(e){}try{window.document.cookie=encodeURIComponent(p)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}(),c.call(u)},u.enableAll=function(e){u.setLevel(u.levels.TRACE,e)},u.disableAll=function(e){u.setLevel(u.levels.SILENT,e)},u.rebuild=function(){if(o!==u&&(s=f(o.getLevel())),c.call(u),o===u)for(var e in a)a[e].rebuild()},s=f(o?o.getLevel():"WARN");var C=h();null!=C&&(l=f(C)),c.call(u)}(o=new u).getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=a[e];return t||(t=a[e]=new u(e,o.methodFactory)),t};var p=typeof window!==t?window.log:void 0;return o.noConflict=function(){return typeof window!==t&&window.log===o&&(window.log=p),o},o.getLoggers=function(){return a},o.default=o,o},void 0===(a=i.call(t,n,t,e))||(e.exports=a)}()},518:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CallParticipantStateMachine=void 0;const i=n(230),a=(0,n(645).createLogger)("CallParticipantStateMachine");class o{constructor(e,t=i.PresenceState.Pending,n=i.ConnectionState.Idle){this.userId=e,this.stateHistory=[],this._presenceState=t,this._connectionState=n,this.addToStateHistory()}addToStateHistory(){this.stateHistory.push({presence:this._presenceState,connection:this._connectionState,timestamp:Date.now()})}get presenceState(){return this._presenceState}set presenceState(e){var t;(null===(t=o.validPresenceTransitions[this._presenceState])||void 0===t?void 0:t.includes(e))?(a.debug(`Presence state transition: ${this._presenceState} -> ${e}`),this._presenceState=e,this.addToStateHistory()):a.warn(`Invalid PresenceState transition from ${this._presenceState} to ${e}`)}get connectionState(){return this._connectionState}set connectionState(e){var t;(null===(t=o.validConnectionTransitions[this._connectionState])||void 0===t?void 0:t.includes(e))?(a.debug(`Connection state transition: ${this._connectionState} -> ${e}`),this._connectionState=e,this.addToStateHistory()):a.warn(`Invalid ConnectionState transition from ${this._connectionState} to ${e}`)}handleEvent(e){const t={CALL_INVITED:()=>{this.presenceState=i.PresenceState.Invited,this._connectionState!==i.ConnectionState.Idle&&(this.connectionState=i.ConnectionState.Idle)},CALL_RINGING:()=>{this.presenceState=i.PresenceState.Ringing},CALL_ACCEPTED:()=>{this.presenceState=i.PresenceState.Joined,this.connectionState=i.ConnectionState.Connecting},CALL_CONNECTED:()=>{this.connectionState=i.ConnectionState.Connected},CALL_RECONNECTING:()=>{this.connectionState=i.ConnectionState.Reconnecting},CALL_RECONNECTED:()=>{this.connectionState=i.ConnectionState.Connected},CALL_DISCONNECTED:()=>{this.connectionState=i.ConnectionState.Disconnected},CALL_LEFT:()=>{this.presenceState=i.PresenceState.Left,this.connectionState=i.ConnectionState.Disconnected},CALL_DECLINED:()=>{this.presenceState=i.PresenceState.Declined},CALL_NO_ANSWER:()=>{this.presenceState=i.PresenceState.NoAnswer},CALL_KICKED:()=>{this.presenceState=i.PresenceState.Kicked,this.connectionState=i.ConnectionState.Disconnected},CALL_REINVITED:()=>{this.presenceState=i.PresenceState.Invited,this.connectionState=i.ConnectionState.Idle}};t[e]?(a.debug(`Handling event: ${e}`),t[e]()):a.warn(`Unknown event: ${e}`)}getStateHistory(){return[...this.stateHistory]}isInCall(){return this._presenceState===i.PresenceState.Joined&&(this._connectionState===i.ConnectionState.Connected||this._connectionState===i.ConnectionState.Reconnecting)}}t.CallParticipantStateMachine=o,o.validPresenceTransitions={[i.PresenceState.Pending]:[i.PresenceState.Invited],[i.PresenceState.Invited]:[i.PresenceState.Ringing,i.PresenceState.Declined,i.PresenceState.Kicked,i.PresenceState.NoAnswer],[i.PresenceState.Ringing]:[i.PresenceState.Joined,i.PresenceState.Declined,i.PresenceState.Kicked,i.PresenceState.NoAnswer],[i.PresenceState.Joined]:[i.PresenceState.Left,i.PresenceState.Kicked],[i.PresenceState.Left]:[i.PresenceState.Invited],[i.PresenceState.Declined]:[i.PresenceState.Invited],[i.PresenceState.Kicked]:[i.PresenceState.Invited],[i.PresenceState.NoAnswer]:[i.PresenceState.Invited]},o.validConnectionTransitions={[i.ConnectionState.Idle]:[i.ConnectionState.Connecting],[i.ConnectionState.Connecting]:[i.ConnectionState.Connected,i.ConnectionState.Disconnected],[i.ConnectionState.Connected]:[i.ConnectionState.Reconnecting,i.ConnectionState.Disconnected],[i.ConnectionState.Reconnecting]:[i.ConnectionState.Connected,i.ConnectionState.Disconnected],[i.ConnectionState.Disconnected]:[i.ConnectionState.Connecting]}},271:function(e,t,n){"use strict";var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(a,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function r(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}c((i=i.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SceytCallClient=void 0;const o=n(998),s=n(429),r=n(578),c=n(787),l=n(650),d=n(489),u=n(37),p=n(230),h=a(n(645));t.SceytCallClient=class{constructor(e){this.joinedCalls=[],this.activeCalls=[],this.joinCall=e=>i(this,void 0,void 0,(function*(){h.default.info("joinCall with options: ",e);let t,n=this.activeCalls.find((t=>t.id===e.callId)),i=[];if(n)t=n.localParticipant,i=n.participants;else{t=new c.Participant(this.user.id);const a=(0,s.v4)();i=e.participantIds.map((e=>{const n=new c.Participant(e);return this.user.id===e&&(t=n,n.handleEvent("CALL_INVITED"),n.handleEvent("CALL_RINGING")),n}));const r=(0,d.makeFirstById)(i,this.user.id);n=new o.Call({id:e.callId||a,mediaFlow:e.mediaFlow,localParticipant:t,participants:r}),this.activeCalls.push(n)}h.default.info("should log call");const a=yield navigator.mediaDevices.getUserMedia({video:!!e.videoCall&&{width:{min:640,max:1280},height:{min:480,max:720}},audio:!0}),l=e.videoCall?a.getVideoTracks():(0,d.getEmptyVideoTrack)(),f=a.getAudioTracks();n.localAudioTracks=f,e.videoCall||l.forEach((e=>{e.enabled=!1})),n.localVideoTracks=l,n.localParticipant.setVideoTracks(l),n.localParticipant.setVideoEnabled(e.videoCall),n.setVideoEnabled(e.videoCall),n.localParticipant.audioTracks=f,n.setState("connecting");const C=r.CALL_TYPE["sfu"===e.mediaFlow?"group":"p2p"];h.default.info("should log callType",e.participantIds);const v=yield this.internalCallHandler.joinToCall({callType:C,roomId:n.id,sessionId:e.sessionId,participantIds:e.participantIds,videoEnabled:e.videoCall});if(h.default.info("should log joinAck"),h.default.info("joinAck received: ",v),v.signal===u.SIGNAL.ERROR)throw h.default.error("Join call failed:",{code:v.code,message:v.message}),n.localParticipant.setPresenceState(p.PresenceState.Left),n.localParticipant.setConnectionState(p.ConnectionState.Disconnected),this.leaveCall(n),{code:v.code,message:v.message};if(n.onParticipantVideoTrackAdded(n,n.localParticipant,l[0]),n.onParticipantAudioTrackAdded(n,n.localParticipant,f[0]),n.setState("connected"),n.sessionId||(n.setSessionId(v.sessionId),n.setOriginatorId(v.originatorId),v.metadata&&n.setMetadata(v.metadata)),v.participants&&v.participants.forEach((e=>{if(!(null==n?void 0:n.participants.find((t=>t.id===e.id)))){const t=new c.Participant(e.id);t.handleEvent("CALL_INVITED"),t.handleEvent("CALL_ACCEPTED"),this.internalCallHandler.addParticipantToRTCMap(n,t),null==n||n.addParticipantToList(t)}})),this.internalCallHandler.setRTCConfig({iceServers:[{urls:v.hostname,credential:v.password,username:v.username}],bundlePolicy:"max-bundle",rtcpMuxPolicy:"require"}),i.forEach((e=>{this.internalCallHandler.addParticipantToRTCMap(n,e)})),"p2p"!==n.mediaFlow){const e=new c.Participant(n.id);e.setPresenceState(p.PresenceState.Joined),e.setConnectionState(p.ConnectionState.Connecting),this.internalCallHandler.addParticipantToRTCMap(n,e),this.internalCallHandler.addTracksToPeerConnection(n,e.id);const t=yield this.internalCallHandler.createOffer(n.id,e.id);yield this.internalCallHandler.setLocalDescription(n.id,e.id,t),n.setServerParticipant(e),yield this.internalCallHandler.sendOffer({callType:C,callId:n.id,description:t,sessionId:v.sessionId})}return n})),this.rejectCall=(e,t)=>i(this,void 0,void 0,(function*(){return h.default.info("Rejecting call",{callId:e.id,reason:t}),e.localParticipant.setPresenceState(p.PresenceState.Declined),e.localParticipant.setConnectionState(p.ConnectionState.Disconnected),this.internalCallHandler.rejectCall(e,t)})),this.leaveCall=e=>i(this,void 0,void 0,(function*(){return h.default.info("Leaving call",{callId:e.id}),e.localParticipant.setPresenceState(p.PresenceState.Left),e.localParticipant.setConnectionState(p.ConnectionState.Disconnected),this.internalCallHandler.leaveCall(e)})),this.chatClient=e,this.internalCallHandler=new l.InternalCallHandler(e),this.user=e.user,this.activeCalls=this.internalCallHandler.activeCalls}set onInvitedToCall(e){this.internalCallHandler.setCallEvent("onInvitedToCall",e)}}},998:function(e,t,n){"use strict";var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(a,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function r(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}c((i=i.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Call=void 0;const o=n(650),s=n(489),r=a(n(645));t.Call=class{constructor({id:e,sessionId:t="",mediaFlow:n,originatorId:i="",localParticipant:a,participants:o}){this.state="idle",this.duration=0,this._localAudioTracks=[],this._localVideoTracks=[],this._muted=!1,this._onHold=!1,this.videoEnabled=!1,this.id=e,this.sessionId=t,this.originatorId=i,this.participants=o,this.localParticipant=a,this.mediaFlow=n,this._onParticipantJoined=()=>{},this._onParticipantLeft=()=>{},this._onParticipantAudioTrackAdded=()=>{},this._onParticipantVideoTrackAdded=()=>{},this._onParticipantStateChanged=()=>{},this._onParticipantEvent=()=>{},this._onCallStateChanged=()=>{},this._onParticipantRejectedCall=()=>{}}addParticipants(e){o.InternalCallHandler.hasInstance()||r.default.info("Call service not initialized");const t=o.InternalCallHandler.getInstance();return null==t?void 0:t.addParticipantsToCall(e,this)}addParticipantToList(e){this.participants.push(e)}kickParticipantFromList(e){this.participants=this.participants.filter((t=>t.id!==e.id))}inviteParticipant(e){}setSessionId(e){this.sessionId=e}setOriginatorId(e){this.originatorId=e}changeMediaFlow(e){this.mediaFlow=e}switchToSFU(){return i(this,void 0,void 0,(function*(){this.localParticipant.isInCall()||r.default.info("Cannot switch to SFU when not in call"),r.default.info("handle switch call to sfu"),this.mediaFlow="sfu";const e=o.InternalCallHandler.getInstance();return null==e?void 0:e.switchCallToSfu(this)}))}mute(e){return i(this,void 0,void 0,(function*(){o.InternalCallHandler.hasInstance()||r.default.info("Call service not initialized"),this.localParticipant.isInCall()||r.default.info("Cannot mute/unmute when not in call"),this.muted=e;const t=o.InternalCallHandler.getInstance();return null==t?void 0:t.sendAudioEnable(this,e)}))}set localAudioTracks(e){this._localAudioTracks=e}get localAudioTracks(){return this._localAudioTracks}set localVideoTracks(e){this._localVideoTracks=e}get localVideoTracks(){return this._localVideoTracks}setState(e){const t=this.state;this.state=e,this._onCallStateChanged(this,`State changed from ${t} to ${e}`)}setServerParticipant(e){this.serverParticipant=e}set muted(e){this._muted=e}get muted(){return this._muted}set onHold(e){this._onHold=e}get onHold(){return this._onHold}enableVideo(e){return i(this,void 0,void 0,(function*(){o.InternalCallHandler.hasInstance()||r.default.info("Call service not initialized"),this.localParticipant.isInCall()||r.default.info("Cannot enable/disable video when not in call");const t=o.InternalCallHandler.getInstance();let n=[],i=e;return this.localVideoTracks.forEach((e=>{e.stop()})),n=e?(yield navigator.mediaDevices.getUserMedia({video:{width:{min:640,max:1280},height:{min:480,max:720}},audio:!0})).getVideoTracks():(0,s.getEmptyVideoTrack)(),this.localVideoTracks=n,this.localParticipant.setVideoTracks(n),this.participants.forEach((e=>{e.id!==this.localParticipant.id&&e.videoEnabled&&(i=!0)})),this.videoEnabled=i,this.localParticipant.setVideoEnabled(e,!0),null==t?void 0:t.sendVideoEnabled(this,e,n[0])}))}getStats(){return i(this,void 0,void 0,(function*(){o.InternalCallHandler.hasInstance()||r.default.info("Call service not initialized. Initialize the service with a chat client first."),this.localParticipant.isInCall()||r.default.info("Cannot get stats when not in call");const e=o.InternalCallHandler.getInstance();return null==e?void 0:e.getStats(this)}))}shareScreen(e){return i(this,void 0,void 0,(function*(){o.InternalCallHandler.hasInstance()||r.default.info("Call service not initialized"),this.localParticipant.isInCall()||r.default.info("Cannot share screen when not in call");const t=o.InternalCallHandler.getInstance();let n=[];if(e){const e=yield navigator.mediaDevices.getDisplayMedia({video:!0});this.localVideoTracks.forEach((e=>{e.stop()})),n=e.getVideoTracks()}else this.localVideoTracks.forEach((e=>{e.stop()})),n=(0,s.getEmptyVideoTrack)();return this.localVideoTracks=n,this.localParticipant.setVideoTracks(n),this.videoEnabled=e,this.localParticipant.setVideoEnabled(e,!0),this.localParticipant.setScreenSharing(e),null==t?void 0:t.sendScreenShare(this,e,n[0])}))}setVideoEnabled(e){this.videoEnabled=e}set onParticipantJoined(e){this._onParticipantJoined=e}get onParticipantJoined(){return this._onParticipantJoined}set onParticipantLeft(e){this._onParticipantLeft=e}get onParticipantLeft(){return this._onParticipantLeft}set onParticipantAudioTrackAdded(e){this._onParticipantAudioTrackAdded=e}get onParticipantAudioTrackAdded(){return this._onParticipantAudioTrackAdded}set onParticipantVideoTrackAdded(e){this._onParticipantVideoTrackAdded=e}get onParticipantVideoTrackAdded(){return this._onParticipantVideoTrackAdded}set onParticipantStateChanged(e){this._onParticipantStateChanged=e}get onParticipantStateChanged(){return this._onParticipantStateChanged}set onParticipantEvent(e){this._onParticipantEvent=e}get onParticipantEvent(){return this._onParticipantEvent}set onCallStateChanged(e){this._onCallStateChanged=e}get onCallStateChanged(){return this._onCallStateChanged}set onParticipantRejectedCall(e){this._onParticipantRejectedCall=e}get onParticipantRejectedCall(){return this._onParticipantRejectedCall}setMetadata(e){this.metadata=e}isActive(){return"connected"===this.state||"reconnecting"===this.state}hasParticipant(e){return this.participants.some((t=>t.id===e))}getParticipant(e){return this.participants.find((t=>t.id===e))}getActiveParticipants(){return this.participants.filter((e=>e.isInCall()))}}},650:function(e,t,n){"use strict";var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(a,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function r(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}c((i=i.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.InternalCallHandler=void 0;const o=n(230),s=n(787),r=n(546),c=n(786),l=n(37),d=n(578),u=n(998),p=n(489),h=a(n(645));class f{constructor(e){this.callParticipantsRTCMap={},this.activeCalls=[],this.callEvents={},this.onIceCandidate=(e,t,n)=>{if(t.candidate)try{this.signalingClient.sendSignalMessage({to:e.id,signal:l.SIGNAL.ICE,callType:d.CALL_TYPE["sfu"===n.mediaFlow?"group":"p2p"],roomId:n.id,sessionId:n.sessionId,ice:{candidate:t.candidate.candidate,sdpMid:t.candidate.sdpMid||"",sdpMLineIndex:t.candidate.sdpMLineIndex||0}})}catch(t){h.default.info("Failed to send ice: ",t)}},this.onTrack=(e,t,n)=>{"audio"===n.track.kind?(t.setAudioTracks([n.track]),e.onParticipantAudioTrackAdded(e,t,n.track)):"video"===n.track.kind&&(t.setVideoTracks([n.track]),e.videoEnabled&&!t.videoEnabled&&(t.setVideoEnabled(!0),e.setVideoEnabled(!0)),e.onParticipantVideoTrackAdded(e,t,n.track))},this.sendSignalScreenShare=(e,t)=>this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE["sfu"===e.mediaFlow?"group":"p2p"],roomId:e.id,signal:l.SIGNAL.INFO,sessionId:e.sessionId,message:t?l.INFO_MESSAGE.START_SCREEN_SHARE:l.INFO_MESSAGE.STOP_SCREEN_SHARE,participantIds:e.participants.map((e=>e.id))}),this.addTracksToPeerConnection=(e,t)=>{let n=e.localVideoTracks;const i=e.localAudioTracks,a=new MediaStream;i&&i.length>0&&a.addTrack(i[0]),this.callParticipantsRTCMap[e.id][t].addTrackToPeerConnection(i[0],a),n&&n.length>0||(n=(0,p.getEmptyVideoTrack)()),a.addTrack(n[0]),this.callParticipantsRTCMap[e.id][t].addTrackToPeerConnection(n[0],a)},e||h.default.info("ChatClient is required for InternalCallHandler initialization"),this.chatClient=e,this.user=e.user,this.signalingClient=new c.Signaling(e,this.handleSignalMessage.bind(this))}static initialize(e){return f.instance||(f.instance=new f(e)),f.instance}static getInstance(){return f.instance?f.instance:(h.default.info("InternalCallHandler not initialized. Call initialize() with chatClient first."),null)}static hasInstance(){return null!==f.instance}static reset(){f.instance=null}setCallEvent(e,t){this.callEvents[e]=t}handleSignalMessage(e){return i(this,void 0,void 0,(function*(){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.roomId));if(t)try{switch(e.signal){case l.SIGNAL.OFFER:yield this.handleOffer(t,e);break;case l.SIGNAL.ANSWER:yield this.handleAnswer(t,e);break;case l.SIGNAL.USER_JOINED:yield this.handleUserJoined(t,e);break;case l.SIGNAL.LEAVE:yield this.handleLeave(t,e);break;case l.SIGNAL.INVITE:yield this.handleInvite(e);break;default:h.default.warn(`Unhandled signal type: ${e.signal}`)}}catch(n){h.default.error(`Error handling signal ${e.signal}:`,n),this.handleSignalingError(t,n)}}))}handleOffer(e,t){return i(this,void 0,void 0,(function*(){if("connected"!==e.state)return;const n=e.participants.find((e=>e.id===t.from));if(n)try{"p2p"===e.mediaFlow&&(yield this.addTracksToPeerConnection(e,n.id)),n.shouldResetPC&&(yield this.resetPeerConnection(e,n)),yield this.setRemoteDescription(e.id,n.id,{sdp:t.sdp,type:"offer"});const i=yield this.callParticipantsRTCMap[e.id][n.id].createAnswer();yield this.setLocalDescription(e.id,n.id,i),yield this.signalingClient.sendSignalMessage({to:t.from,callType:t.type,roomId:e.id,signal:l.SIGNAL.ANSWER,sdp:i.sdp,sessionId:t.sessionId})}catch(e){throw h.default.error("Error handling offer:",e),n.handleEvent("CALL_DISCONNECTED"),e}}))}resetPeerConnection(e,t){return i(this,void 0,void 0,(function*(){this.closePeerConnections(e.id,t.id),this.addParticipantToRTCMap(e,t),t.setShouldResetPC(!1)}))}handleSignalingError(e,t){h.default.error("Signaling error:",t),"connected"===e.state&&(e.setState("reconnecting"),this.attemptConnectionRecovery(e).catch((e=>h.default.error("Failed to recover connection:",e))))}attemptConnectionRecovery(e){return i(this,void 0,void 0,(function*(){yield new Promise((e=>setTimeout(e,2e3)));try{for(const t of e.participants)if(t.id!==this.user.id){yield this.resetPeerConnection(e,t);const n=yield this.callParticipantsRTCMap[e.id][t.id].createOffer();yield this.setLocalDescription(e.id,t.id,n),yield this.sendOffer({callType:d.CALL_TYPE.group,callId:e.id,description:n,to:t.id,sessionId:e.sessionId})}}catch(t){h.default.error("Recovery attempt failed:",t),e.setState("idle"),e.onCallStateChanged(e,"Failed to recover connection")}}))}handleAnswer(e,t){var n;return i(this,void 0,void 0,(function*(){if("connected"===e.state)try{let i;e.serverParticipant&&e.serverParticipant.id===t.from?(i=e.serverParticipant,"p2p"!==e.mediaFlow&&(h.default.info("Setting local participant to connected in group call"),e.localParticipant.handleEvent("CALL_CONNECTED"))):i=e.participants.find((e=>e.id===t.from)),i&&(yield this.setRemoteDescription(e.id,i.id,{sdp:t.sdp,type:"answer"}),"p2p"!==e.mediaFlow&&(null===(n=t.participants)||void 0===n||n.forEach((n=>{n.id!==this.user.id&&(h.default.info("Send CONNECT to participant: ",n.id),this.signalingClient.sendSignalMessage({to:n.id,callType:t.type,roomId:e.id,signal:l.SIGNAL.CONNECT,sessionId:e.sessionId}))})),i.handleEvent("CALL_CONNECTED")),e.setState("connected"))}catch(e){h.default.error("Error handling answer:",e)}}))}handleUserJoined(e,t){return i(this,void 0,void 0,(function*(){h.default.info("handle user joined",t);const n=e.participants.find((e=>e.id===t.from));if(n&&(n.handleEvent("CALL_INVITED"),n.handleEvent("CALL_RINGING"),n.handleEvent("CALL_ACCEPTED"),t.videoEnabled&&(n.setVideoEnabled(!0),e.setVideoEnabled(!0)),"p2p"===e.mediaFlow)){this.addParticipantToRTCMap(e,n),this.addTracksToPeerConnection(e,n.id);const t=yield this.createOffer(e.id,n.id);yield this.setLocalDescription(e.id,n.id,t),yield this.sendOffer({callType:d.CALL_TYPE.p2p,callId:e.id,to:n.id,description:t,sessionId:e.sessionId})}}))}handleLeave(e,t){return i(this,void 0,void 0,(function*(){h.default.info("handle leave",t);const n=e.participants.find((e=>e.id===t.from));n&&(n.setPresenceState(o.PresenceState.Left),n.setConnectionState(o.ConnectionState.Disconnected),e.onParticipantStateChanged(e,n,o.ConnectionState.Disconnected),e.kickParticipantFromList(n),e.onParticipantLeft(e,n),this.closePeerConnections(e.id,n.id))}))}handleInvite(e){return i(this,void 0,void 0,(function*(){if(h.default.info("handle invite",e),!e.participants)return void h.default.error("No participants in invite message");const t=new u.Call({id:e.roomId,sessionId:e.sessionId,mediaFlow:e.type===d.CALL_TYPE.group?"sfu":"p2p",originatorId:e.from,localParticipant:new s.Participant(this.user.id),participants:e.participants.map((e=>new s.Participant(e.id)))});t.participants.forEach((t=>{t.id===e.from?(t.handleEvent("CALL_INVITED"),t.handleEvent("CALL_RINGING"),t.handleEvent("CALL_ACCEPTED")):t.id===this.user.id&&t.handleEvent("CALL_INVITED")})),this.activeCalls.push(t),this.callEvents.onInvitedToCall&&this.callEvents.onInvitedToCall(t),yield this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE["sfu"===t.mediaFlow?"group":"p2p"],roomId:t.id,signal:l.SIGNAL.RINGING,sessionId:t.sessionId,participantIds:[e.from]}),t.localParticipant.handleEvent("CALL_RINGING")}))}setRTCConfig(e){this.rtcConfig=e}onIceCandidateListener(e,t){return n=>{this.onIceCandidate(e,n,t)}}onSignalingStateChangeListener(e){return()=>{h.default.info(`PC signalingstatechange, participant: ${e.id}`)}}onIceConnectionStateChangeListener(e,t,n){return()=>{const i=n.peerConnection.iceConnectionState;switch(h.default.info("Ice connection state changed to: ",i),i){case"checking":e.setConnectionState(o.ConnectionState.Connecting),t.onParticipantStateChanged(t,e,o.ConnectionState.Connecting);break;case"connected":e.setConnectionState(o.ConnectionState.Connected),t.onParticipantStateChanged(t,e,o.ConnectionState.Connected);break;case"disconnected":e.setConnectionState(o.ConnectionState.Reconnecting),t.onParticipantStateChanged(t,e,o.ConnectionState.Reconnecting);break;case"failed":case"closed":e.setConnectionState(o.ConnectionState.Disconnected),t.onParticipantStateChanged(t,e,o.ConnectionState.Disconnected)}}}onTrackListener(e,t){return n=>{h.default.info(`PC track, participant: ${t.id}`),this.onTrack(e,t,n)}}closePeerConnections(e,t){h.default.info("close peer connection >>.... callId ,, ",e,"participantId: ",t),h.default.info("this.callParticipantsRTCMap >>.... ",this.callParticipantsRTCMap),h.default.info("this.callParticipantsRTCMap[callId] >>.... ",this.callParticipantsRTCMap[e]);const n=this.callParticipantsRTCMap[e]&&this.callParticipantsRTCMap[e][t];h.default.info("webrtcClient. . . . ",n),n&&(n.listeners&&(h.default.info("webrtcClient.listeners: ",n.listeners),h.default.info("Object.keys(webrtcClient.listeners): ",Object.keys(n.listeners)),Object.keys(n.listeners).forEach((e=>{h.default.info("close listener: ",e),n.removeEventListener(e,n.listeners[e])}))),n.close(),this.callParticipantsRTCMap[e][t]=null,delete this.callParticipantsRTCMap[e][t])}addParticipantToRTCMap(e,t){this.callParticipantsRTCMap[e.id]||(this.callParticipantsRTCMap[e.id]={});const n=new r.WebRTCClient(this.rtcConfig);this.callParticipantsRTCMap[e.id][t.id]=n;const i=this.onIceCandidateListener(t,e),a=this.onSignalingStateChangeListener(t),o=this.onIceConnectionStateChangeListener(t,e,n),s=this.onTrackListener(e,t);return n.addEventListener("icecandidate",i),n.addEventListener("signalingstatechange",a),n.addEventListener("connectionstatechange",o),n.addEventListener("track",s),n.setListeners({iceCandidateListener:i,signalingStateChangeListener:a,iceConnectionStateChangeListener:o,trackListener:s}),h.default.info("webrtcClient: set to callParticipantsRTCMap",e.id," participant.id. .. ",t.id),h.default.info("webrtcClient: ",n),t}joinToCall(e){return this.signalingClient.sendSignalMessage(Object.assign(Object.assign({callType:e.callType,roomId:e.roomId},e.sessionId&&{sessionId:e.sessionId}),{signal:l.SIGNAL.JOIN,participantIds:e.participantIds,videoEnabled:e.videoEnabled}))}sendRinging(e){return this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE["sfu"===e.mediaFlow?"group":"p2p"],roomId:e.id,sessionId:e.sessionId,signal:l.SIGNAL.RINGING,participantIds:e.participants.map((e=>e.id))})}rejectCall(e,t){return e.localParticipant.handleEvent("CALL_DECLINED"),this.activeCalls=this.activeCalls.filter((t=>t.id!==e.id)),this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE["sfu"===e.mediaFlow?"group":"p2p"],roomId:e.id,sessionId:e.sessionId,signal:l.SIGNAL.DECLINE,participantIds:e.participants.map((e=>e.id)),message:t||""})}closeCall(e){h.default.info("Handle close call. .... "),h.default.info("call.localAudioTracks. .... ",e.localAudioTracks),e.localAudioTracks.forEach((e=>{e.stop()})),h.default.info("call.localVideoTracks. .. ",e.localVideoTracks),e.localVideoTracks.forEach((e=>{e.stop()})),e.participants.forEach((t=>{this.closePeerConnections(e.id,t.id)}));const t=this.activeCalls.findIndex((e=>e.id==e.id));this.activeCalls.splice(t,1),delete this.callParticipantsRTCMap[e.id]}leaveCall(e){if(e)return e.localParticipant.handleEvent("CALL_LEFT"),this.closeCall(e),this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE["sfu"===e.mediaFlow?"group":"p2p"],roomId:e.id,sessionId:e.sessionId,signal:l.SIGNAL.LEAVE,participantIds:e.participants.map((e=>e.id))})}sendOffer(e){return h.default.info(`Send signal: ${l.SIGNAL.OFFER}, to participant: ${e.to}`),this.signalingClient.sendSignalMessage(Object.assign(Object.assign({callType:e.callType,roomId:e.callId,signal:l.SIGNAL.OFFER,sdp:e.description.sdp},e.to&&{to:e.to}),{sessionId:e.sessionId}))}addParticipantsToCall(e,t){return e.forEach((e=>{const n=new s.Participant(e);t.addParticipantToList(n),t.onParticipantJoined(t,n),this.addParticipantToRTCMap(t,n)})),this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE["sfu"===t.mediaFlow?"group":"p2p"],roomId:t.id,sessionId:t.sessionId,signal:l.SIGNAL.USER_ADDED,participantIds:e,videoEnabled:t.videoEnabled})}createAnswer(e,t){return this.callParticipantsRTCMap[e][t].createAnswer()}createOffer(e,t){return this.callParticipantsRTCMap[e][t].createOffer()}setLocalDescription(e,t,n){return this.callParticipantsRTCMap[e][t].setLocalDescription(n)}setRemoteDescription(e,t,n){return this.callParticipantsRTCMap[e][t].setRemoteDescription(n)}sendVideoEnabled(e,t,n){return"p2p"===e.mediaFlow?e.participants.forEach((i=>{i.id!==this.user.id&&this.callParticipantsRTCMap[e.id][i.id].enableVideoOnPeerConnection(t,n)})):this.callParticipantsRTCMap[e.id][e.serverParticipant.id].enableVideoOnPeerConnection(t,n),e.localParticipant.videoTracks.forEach((e=>{e.enabled=t})),e.onParticipantEvent(e,e.localParticipant,t?"VideoEnabled":"VideoDisabled"),this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE["sfu"===e.mediaFlow?"group":"p2p"],roomId:e.id,signal:l.SIGNAL.INFO,sessionId:e.sessionId,message:t?l.INFO_MESSAGE.VIDEO_ENABLED:l.INFO_MESSAGE.VIDEO_DISABLED,participantIds:e.participants.map((e=>e.id))})}getStats(e){const t=e.participants.find((e=>{if(e.id!==this.user.id)return e}));if(t)return this.callParticipantsRTCMap[e.id][null==t?void 0:t.id].getConnectionStats(e.id,e.sessionId,e.localParticipant.id)}sendScreenShare(e,t,n){return"p2p"===e.mediaFlow?e.participants.forEach((i=>{i.id!==this.user.id&&this.callParticipantsRTCMap[e.id][i.id].enableVideoOnPeerConnection(t,n)})):this.callParticipantsRTCMap[e.id][e.serverParticipant.id].enableVideoOnPeerConnection(t,n),e.localParticipant.videoTracks.forEach((e=>{e.enabled=t})),e.onParticipantEvent(e,e.localParticipant,t?"ScreenSharingStarted":"ScreenSharingStopped"),this.sendSignalScreenShare(e,t)}sendAudioEnable(e,t){return"p2p"===e.mediaFlow?e.participants.forEach((n=>{n.id!==this.user.id&&this.callParticipantsRTCMap[e.id][n.id].enableAudioPeerConnection(t)})):this.callParticipantsRTCMap[e.id][e.serverParticipant.id].enableAudioPeerConnection(t),e.localParticipant.audioTracks.forEach((e=>{e.enabled=!t})),e.onParticipantEvent(e,e.localParticipant,t?"Mute":"Unmute"),this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE["sfu"===e.mediaFlow?"group":"p2p"],roomId:e.id,signal:l.SIGNAL.INFO,sessionId:e.sessionId,message:t?l.INFO_MESSAGE.MUTE:l.INFO_MESSAGE.UNMUTE,participantIds:e.participants.map((e=>e.id))})}switchCallToSfu(e){return i(this,void 0,void 0,(function*(){try{const t=yield this.signalingClient.sendSignalMessage({callType:d.CALL_TYPE.group,roomId:e.id,signal:l.SIGNAL.SWITCH_CALL_TYPE,sessionId:e.sessionId});h.default.info("switchRes: ",t);const n=new s.Participant(e.id);this.addParticipantToRTCMap(e,n),this.addTracksToPeerConnection(e,n.id);const i=yield this.createOffer(e.id,n.id);yield this.setLocalDescription(e.id,n.id,i),e.setServerParticipant(n),e.participants.forEach((e=>{e.setShouldResetPC(!0)})),yield this.sendOffer({callType:d.CALL_TYPE.group,callId:e.id,description:i,sessionId:e.sessionId})}catch(e){return h.default.info("Failed to switch sfu"),!1}return!0}))}}t.InternalCallHandler=f,f.instance=null},787:function(e,t,n){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Participant=void 0;const a=i(n(645)),o=n(518);t.Participant=class{constructor(e){this._muted=!1,this._onHold=!1,this._videoEnabled=!1,this._screenSharing=!1,this.audioTracks=[],this.videoTracks=[],this.shouldResetPC=!1,this.isInitialized=!1,this.id=e,this.stateMachine=new o.CallParticipantStateMachine(e)}get presenceState(){return this.stateMachine.presenceState}get connectionState(){return this.stateMachine.connectionState}get videoEnabled(){return this._videoEnabled}get muted(){return this._muted}get screenSharing(){return this._screenSharing}get onHold(){return this._onHold}setPresenceState(e){this.stateMachine.presenceState=e}setConnectionState(e){this.stateMachine.connectionState=e}setShouldResetPC(e){this.shouldResetPC=e}setMuted(e){this.isInCall()||a.default.info("Cannot mute/unmute when not in call"),this.audioTracks.forEach((t=>{t.enabled=!e})),this._muted=e}setVideoEnabled(e,t=!1){if(!this.isInitialized||t||this.isInCall())return this.videoTracks.forEach((t=>{t.enabled=e})),void(this._videoEnabled=e);a.default.info("Cannot enable/disable video when not in call")}setScreenSharing(e){this.isInCall()||a.default.info("Cannot change screen sharing when not in call"),this.videoTracks.forEach((t=>{t.enabled=e})),this._screenSharing=e}setAudioTracks(e){this.audioTracks=e,this._muted&&e.forEach((e=>e.enabled=!1))}setVideoTracks(e){this.videoTracks=e,e.forEach((e=>e.enabled=this._videoEnabled))}handleEvent(e){this.stateMachine.handleEvent(e)}getStateHistory(){return this.stateMachine.getStateHistory()}isInCall(){return this.stateMachine.isInCall()}completeInitialization(){this.isInitialized=!0}initializeVideoState(e){this._videoEnabled=e,this.videoTracks.forEach((t=>{t.enabled=e}))}}},786:function(e,t,n){"use strict";var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(a,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function r(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}c((i=i.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Signaling=void 0;const o=a(n(645));t.Signaling=class{constructor(e,t){this.chatClient=e;const n=new this.chatClient.ChannelListener;n.onSignal=e=>i(this,void 0,void 0,(function*(){t(e)})),this.chatClient.addChannelListener("call_listeners",n)}sendSignalMessage(e){return o.default.info("Send signal message: ",e.signal,"message: ",e),this.chatClient.sendSignal(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({type:e.callType,roomId:e.roomId},e.sessionId&&{sessionId:e.sessionId}),{signal:e.signal}),e.sdp&&{sdp:e.sdp}),e.to&&{to:e.to}),e.videoEnabled&&{videoEnabled:e.videoEnabled}),e.message&&{message:e.message}),{invitedParticipants:e.participantIds?e.participantIds.map((e=>({id:e}))):[]}),e.ice&&{ice:e.ice}))}}},546:function(e,t,n){"use strict";var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(a,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function r(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}c((i=i.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.WebRTCClient=void 0;const o=a(n(645));t.WebRTCClient=class{constructor(e){this.listeners={},this.configuration=e,this.peerConnection=new RTCPeerConnection(this.configuration),this.lastStateChange=Date.now()}setListeners(e){this.listeners=e}setConfiguration(e){this.configuration=e,"closed"!==this.peerConnection.connectionState&&this.peerConnection.setConfiguration(e)}addTrackToPeerConnection(e,t){"closed"!==this.peerConnection.connectionState&&this.peerConnection.addTrack(e,t)}enableVideoOnPeerConnection(e,t){"closed"!==this.peerConnection.connectionState&&this.peerConnection.getSenders().forEach((n=>i(this,void 0,void 0,(function*(){if(n.track&&"video"===n.track.kind)if(t){t.enabled=e,o.default.info("senders replace track",t);try{yield n.replaceTrack(t)}catch(e){o.default.error("Failed to replace video track:",e)}}else n.track.enabled=e}))))}enableAudioPeerConnection(e){"closed"!==this.peerConnection.connectionState&&this.peerConnection.getSenders().forEach((t=>{t.track&&"audio"===t.track.kind&&(t.track.enabled=!e)}))}getConnectionStats(e,t,n){return i(this,void 0,void 0,(function*(){"closed"===this.peerConnection.connectionState&&o.default.error("Cannot get stats: peer connection is closed");const i=yield this.peerConnection.getStats(),a=[];i.forEach((e=>{"codec"!==(null==e?void 0:e.type)&&"candidate-pair"!==(null==e?void 0:e.type)&&"local-candidate"!==(null==e?void 0:e.type)&&"remote-candidate"!==(null==e?void 0:e.type)&&"inbound-rtp"!==(null==e?void 0:e.type)&&"remote-inbound-rtp"!==(null==e?void 0:e.type)&&"outbound-rtp"!==(null==e?void 0:e.type)&&"remote-outbound-rtp"!==(null==e?void 0:e.type)&&"transport"!==(null==e?void 0:e.type)||a.push(e)}));const s=a.find((e=>"candidate-pair"===(null==e?void 0:e.type))),r=a.find((e=>"remote-candidate"===(null==e?void 0:e.type))),c=a.find((e=>"local-candidate"===(null==e?void 0:e.type))),l=a.find((e=>"inbound-rtp"===(null==e?void 0:e.type)&&"audio"===(null==e?void 0:e.kind))),d=a.find((e=>"remote-inbound-rtp"===(null==e?void 0:e.type)&&"audio"===(null==e?void 0:e.kind))),u=a.find((e=>"remote-outbound-rtp"===(null==e?void 0:e.type)&&"audio"===(null==e?void 0:e.kind))),p=a.find((e=>"outbound-rtp"===(null==e?void 0:e.type)&&"audio"===(null==e?void 0:e.kind))),h=a.find((e=>"inbound-rtp"===(null==e?void 0:e.type)&&"video"===(null==e?void 0:e.kind))),f=a.find((e=>"remote-inbound-rtp"===(null==e?void 0:e.type)&&"video"===(null==e?void 0:e.kind))),C=a.find((e=>"remote-outbound-rtp"===(null==e?void 0:e.type)&&"video"===(null==e?void 0:e.kind))),v=a.find((e=>"outbound-rtp"===(null==e?void 0:e.type)&&"video"===(null==e?void 0:e.kind))),g=a.find((e=>"transport"===(null==e?void 0:e.type))),S=a.find((e=>"codec"===(null==e?void 0:e.type)&&"audio/opus"===(null==e?void 0:e.mimeType))),I=a.find((e=>"codec"===(null==e?void 0:e.type)&&"video/VP8"===(null==e?void 0:e.mimeType))),E={callId:e,sessionId:t,timestamp:Date.now(),userId:n,userAgent:`WAAFI-Web ${navigator.userAgent}`,report:{[s.id]:{properties:s},[r.id]:{properties:r},[c.id]:{properties:c},[l.id]:{properties:l},[p.id]:{properties:p},[d.id]:{properties:d},[u.id]:{properties:u},[null==h?void 0:h.id]:{properties:h},[null==v?void 0:v.id]:{properties:v},[null==f?void 0:f.id]:{properties:f},[null==C?void 0:C.id]:{properties:C},[null==g?void 0:g.id]:{properties:g},[S.id]:{properties:S},[null==I?void 0:I.id]:{properties:I}}};return Object.keys(E.report).forEach((e=>{E.report[e].properties||delete E.report[e]})),E}))}createOffer(){return"closed"===this.peerConnection.connectionState&&o.default.error("Cannot create offer: peer connection is closed"),this.connectionStartTime=Date.now(),this.peerConnection.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0})}createAnswer(){return"closed"===this.peerConnection.connectionState&&o.default.error("Cannot create answer: peer connection is closed"),this.peerConnection.createAnswer()}setLocalDescription(e){return"closed"===this.peerConnection.connectionState&&o.default.error("Cannot set local description: peer connection is closed"),this.peerConnection.setLocalDescription(e)}setRemoteDescription(e){return"closed"===this.peerConnection.connectionState&&o.default.error("Cannot set remote description: peer connection is closed"),this.peerConnection.setRemoteDescription(e)}addIceCandidate(e){return"closed"===this.peerConnection.connectionState&&o.default.error("Cannot add ICE candidate: peer connection is closed"),this.peerConnection.addIceCandidate(e)}addEventListener(e,t){this.peerConnection.addEventListener(e,t)}removeEventListener(e,t){this.peerConnection.removeEventListener(e,t)}getConnectionDuration(){return this.connectionStartTime?Date.now()-this.connectionStartTime:0}getTimeSinceLastStateChange(){return this.lastStateChange?Date.now()-this.lastStateChange:0}close(){this.lastStateChange=Date.now(),this.peerConnection.close()}}},37:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.INFO_MESSAGE=t.SIGNAL=void 0,t.SIGNAL={JOIN:"JOIN",INVITE:"INVITE",RE_INVITE:"RE_INVITE",OFFER:"OFFER",RENEGOTIATION_OFFER:"RENEGOTIATION_OFFER",ANSWER:"ANSWER",RINGING:"RINGING",BUSY:"BUSY",INFO:"INFO",GET_SESSION:"GET_SESSION",USER_JOINED:"USER_JOINED",USER_ADDED:"USER_ADDED",DECLINE:"DECLINE",LEAVE:"LEAVE",CONNECT:"CONNECT",CANCEL:"CANCEL",ICE:"ICE",CLOSE:"CLOSE",GET_ROOMS:"GET_ROOMS",SWITCH_CALL_TYPE:"SWITCH_CALL_TYPE",MEDIA_CONNECTED:"MEDIA_CONNECTED",ERROR:"ERROR"},t.INFO_MESSAGE={VIDEO_ENABLED:"VIDEO_ENABLED",VIDEO_DISABLED:"VIDEO_DISABLED",START_SCREEN_SHARE:"START_SCREEN_SHARE",STOP_SCREEN_SHARE:"STOP_SCREEN_SHARE",HOLD:"HOLD",RESUME:"RESUME",MUTE:"MUTE",UNMUTE:"UNMUTE"}},578:(e,t)=>{"use strict";var n;Object.defineProperty(t,"__esModule",{value:!0}),t.CALL_TYPE=void 0,function(e){e[e.p2p=0]="p2p",e[e.channel=1]="channel",e[e.group=2]="group"}(n||(t.CALL_TYPE=n={}))},489:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.makeFirstById=t.getEmptyVideoTrack=void 0,t.getEmptyVideoTrack=()=>{const e=document.createElement("canvas");return e.getContext("2d"),e.width=640,e.height=480,e.captureStream().getVideoTracks()},t.makeFirstById=(e,t)=>{const n=[...e],i=n.findIndex((e=>e.id===t));if(i>-1){const[e]=n.splice(i,1);n.unshift(e)}return n}},838:function(e,t,n){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var a=Object.getOwnPropertyDescriptor(t,n);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,a)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),a=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),a(n(271),t)},230:(e,t)=>{"use strict";var n,i;Object.defineProperty(t,"__esModule",{value:!0}),t.ConnectionState=t.PresenceState=void 0,function(e){e.Pending="Pending",e.Invited="Invited",e.Ringing="Ringing",e.Joined="Joined",e.Left="Left",e.Declined="Declined",e.Kicked="Kicked",e.NoAnswer="NoAnswer"}(n||(t.PresenceState=n={})),function(e){e.Idle="Idle",e.Connecting="Connecting",e.Connected="Connected",e.Reconnecting="Reconnecting",e.Disconnected="Disconnected"}(i||(t.ConnectionState=i={}))},645:function(e,t,n){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createLogger=void 0;const a=i(n(43));t.createLogger=e=>({trace:(t,...n)=>a.default.trace(`[${e}]`,t,...n),debug:(t,...n)=>a.default.debug(`[${e}]`,t,...n),info:(t,...n)=>a.default.info(`[${e}]`,t,...n),warn:(t,...n)=>a.default.warn(`[${e}]`,t,...n),error:(t,...n)=>a.default.error(`[${e}]`,t,...n)}),t.default=(0,t.createLogger)("SceytCallClient")},429:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"NIL",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(t,"parse",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return d.default}}),Object.defineProperty(t,"v1",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(t,"v3",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(t,"v4",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(t,"v5",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(t,"validate",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(t,"version",{enumerable:!0,get:function(){return c.default}});var i=p(n(990)),a=p(n(237)),o=p(n(355)),s=p(n(764)),r=p(n(314)),c=p(n(464)),l=p(n(435)),d=p(n(8)),u=p(n(222));function p(e){return e&&e.__esModule?e:{default:e}}},163:(e,t)=>{"use strict";function n(e){return 14+(e+64>>>9<<4)+1}function i(e,t){const n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function a(e,t,n,a,o,s){return i((r=i(i(t,e),i(a,s)))<<(c=o)|r>>>32-c,n);var r,c}function o(e,t,n,i,o,s,r){return a(t&n|~t&i,e,t,o,s,r)}function s(e,t,n,i,o,s,r){return a(t&i|n&~i,e,t,o,s,r)}function r(e,t,n,i,o,s,r){return a(t^n^i,e,t,o,s,r)}function c(e,t,n,i,o,s,r){return a(n^(t|~i),e,t,o,s,r)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=function(e){if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(let n=0;n<t.length;++n)e[n]=t.charCodeAt(n)}return function(e){const t=[],n=32*e.length,i="0123456789abcdef";for(let a=0;a<n;a+=8){const n=e[a>>5]>>>a%32&255,o=parseInt(i.charAt(n>>>4&15)+i.charAt(15&n),16);t.push(o)}return t}(function(e,t){e[t>>5]|=128<<t%32,e[n(t)-1]=t;let a=1732584193,l=-271733879,d=-1732584194,u=271733878;for(let t=0;t<e.length;t+=16){const n=a,p=l,h=d,f=u;a=o(a,l,d,u,e[t],7,-680876936),u=o(u,a,l,d,e[t+1],12,-389564586),d=o(d,u,a,l,e[t+2],17,606105819),l=o(l,d,u,a,e[t+3],22,-1044525330),a=o(a,l,d,u,e[t+4],7,-176418897),u=o(u,a,l,d,e[t+5],12,1200080426),d=o(d,u,a,l,e[t+6],17,-1473231341),l=o(l,d,u,a,e[t+7],22,-45705983),a=o(a,l,d,u,e[t+8],7,1770035416),u=o(u,a,l,d,e[t+9],12,-1958414417),d=o(d,u,a,l,e[t+10],17,-42063),l=o(l,d,u,a,e[t+11],22,-1990404162),a=o(a,l,d,u,e[t+12],7,1804603682),u=o(u,a,l,d,e[t+13],12,-40341101),d=o(d,u,a,l,e[t+14],17,-1502002290),l=o(l,d,u,a,e[t+15],22,1236535329),a=s(a,l,d,u,e[t+1],5,-165796510),u=s(u,a,l,d,e[t+6],9,-1069501632),d=s(d,u,a,l,e[t+11],14,643717713),l=s(l,d,u,a,e[t],20,-373897302),a=s(a,l,d,u,e[t+5],5,-701558691),u=s(u,a,l,d,e[t+10],9,38016083),d=s(d,u,a,l,e[t+15],14,-660478335),l=s(l,d,u,a,e[t+4],20,-405537848),a=s(a,l,d,u,e[t+9],5,568446438),u=s(u,a,l,d,e[t+14],9,-1019803690),d=s(d,u,a,l,e[t+3],14,-187363961),l=s(l,d,u,a,e[t+8],20,1163531501),a=s(a,l,d,u,e[t+13],5,-1444681467),u=s(u,a,l,d,e[t+2],9,-51403784),d=s(d,u,a,l,e[t+7],14,1735328473),l=s(l,d,u,a,e[t+12],20,-1926607734),a=r(a,l,d,u,e[t+5],4,-378558),u=r(u,a,l,d,e[t+8],11,-2022574463),d=r(d,u,a,l,e[t+11],16,1839030562),l=r(l,d,u,a,e[t+14],23,-35309556),a=r(a,l,d,u,e[t+1],4,-1530992060),u=r(u,a,l,d,e[t+4],11,1272893353),d=r(d,u,a,l,e[t+7],16,-155497632),l=r(l,d,u,a,e[t+10],23,-1094730640),a=r(a,l,d,u,e[t+13],4,681279174),u=r(u,a,l,d,e[t],11,-358537222),d=r(d,u,a,l,e[t+3],16,-722521979),l=r(l,d,u,a,e[t+6],23,76029189),a=r(a,l,d,u,e[t+9],4,-640364487),u=r(u,a,l,d,e[t+12],11,-421815835),d=r(d,u,a,l,e[t+15],16,530742520),l=r(l,d,u,a,e[t+2],23,-995338651),a=c(a,l,d,u,e[t],6,-198630844),u=c(u,a,l,d,e[t+7],10,1126891415),d=c(d,u,a,l,e[t+14],15,-1416354905),l=c(l,d,u,a,e[t+5],21,-57434055),a=c(a,l,d,u,e[t+12],6,1700485571),u=c(u,a,l,d,e[t+3],10,-1894986606),d=c(d,u,a,l,e[t+10],15,-1051523),l=c(l,d,u,a,e[t+1],21,-2054922799),a=c(a,l,d,u,e[t+8],6,1873313359),u=c(u,a,l,d,e[t+15],10,-30611744),d=c(d,u,a,l,e[t+6],15,-1560198380),l=c(l,d,u,a,e[t+13],21,1309151649),a=c(a,l,d,u,e[t+4],6,-145523070),u=c(u,a,l,d,e[t+11],10,-1120210379),d=c(d,u,a,l,e[t+2],15,718787259),l=c(l,d,u,a,e[t+9],21,-343485551),a=i(a,n),l=i(l,p),d=i(d,h),u=i(u,f)}return[a,l,d,u]}(function(e){if(0===e.length)return[];const t=8*e.length,i=new Uint32Array(n(t));for(let n=0;n<t;n+=8)i[n>>5]|=(255&e[n/8])<<n%32;return i}(e),8*e.length))}},790:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};t.default=n},314:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.default="00000000-0000-0000-0000-000000000000"},222:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i,a=(i=n(435))&&i.__esModule?i:{default:i};t.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}},58:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i},319:(e,t)=>{"use strict";let n;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){if(!n&&(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!n))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(i)};const i=new Uint8Array(16)},757:(e,t)=>{"use strict";function n(e,t,n,i){switch(e){case 0:return t&n^~t&i;case 1:case 3:return t^n^i;case 2:return t&n^t&i^n&i}}function i(e,t){return e<<t|e>>>32-t}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=function(e){const t=[1518500249,1859775393,2400959708,3395469782],a=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const o=e.length/4+2,s=Math.ceil(o/16),r=new Array(s);for(let t=0;t<s;++t){const n=new Uint32Array(16);for(let i=0;i<16;++i)n[i]=e[64*t+4*i]<<24|e[64*t+4*i+1]<<16|e[64*t+4*i+2]<<8|e[64*t+4*i+3];r[t]=n}r[s-1][14]=8*(e.length-1)/Math.pow(2,32),r[s-1][14]=Math.floor(r[s-1][14]),r[s-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<s;++e){const o=new Uint32Array(80);for(let t=0;t<16;++t)o[t]=r[e][t];for(let e=16;e<80;++e)o[e]=i(o[e-3]^o[e-8]^o[e-14]^o[e-16],1);let s=a[0],c=a[1],l=a[2],d=a[3],u=a[4];for(let e=0;e<80;++e){const a=Math.floor(e/20),r=i(s,5)+n(a,c,l,d)+u+t[a]+o[e]>>>0;u=d,d=l,l=i(c,30)>>>0,c=s,s=r}a[0]=a[0]+s>>>0,a[1]=a[1]+c>>>0,a[2]=a[2]+l>>>0,a[3]=a[3]+d>>>0,a[4]=a[4]+u>>>0}return[a[0]>>24&255,a[0]>>16&255,a[0]>>8&255,255&a[0],a[1]>>24&255,a[1]>>16&255,a[1]>>8&255,255&a[1],a[2]>>24&255,a[2]>>16&255,a[2]>>8&255,255&a[2],a[3]>>24&255,a[3]>>16&255,a[3]>>8&255,255&a[3],a[4]>>24&255,a[4]>>16&255,a[4]>>8&255,255&a[4]]}},8:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.unsafeStringify=s;var i,a=(i=n(435))&&i.__esModule?i:{default:i};const o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));function s(e,t=0){return o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]}t.default=function(e,t=0){const n=s(e,t);if(!(0,a.default)(n))throw TypeError("Stringified UUID is invalid");return n}},990:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i,a=(i=n(319))&&i.__esModule?i:{default:i},o=n(8);let s,r,c=0,l=0;t.default=function(e,t,n){let i=t&&n||0;const d=t||new Array(16);let u=(e=e||{}).node||s,p=void 0!==e.clockseq?e.clockseq:r;if(null==u||null==p){const t=e.random||(e.rng||a.default)();null==u&&(u=s=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==p&&(p=r=16383&(t[6]<<8|t[7]))}let h=void 0!==e.msecs?e.msecs:Date.now(),f=void 0!==e.nsecs?e.nsecs:l+1;const C=h-c+(f-l)/1e4;if(C<0&&void 0===e.clockseq&&(p=p+1&16383),(C<0||h>c)&&void 0===e.nsecs&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");c=h,l=f,r=p,h+=122192928e5;const v=(1e4*(268435455&h)+f)%4294967296;d[i++]=v>>>24&255,d[i++]=v>>>16&255,d[i++]=v>>>8&255,d[i++]=255&v;const g=h/4294967296*1e4&268435455;d[i++]=g>>>8&255,d[i++]=255&g,d[i++]=g>>>24&15|16,d[i++]=g>>>16&255,d[i++]=p>>>8|128,d[i++]=255&p;for(let e=0;e<6;++e)d[i+e]=u[e];return t||(0,o.unsafeStringify)(d)}},237:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=o(n(925)),a=o(n(163));function o(e){return e&&e.__esModule?e:{default:e}}var s=(0,i.default)("v3",48,a.default);t.default=s},925:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.URL=t.DNS=void 0,t.default=function(e,t,n){function i(e,i,s,r){var c;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof i&&(i=(0,o.default)(i)),16!==(null===(c=i)||void 0===c?void 0:c.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+e.length);if(l.set(i),l.set(e,i.length),l=n(l),l[6]=15&l[6]|t,l[8]=63&l[8]|128,s){r=r||0;for(let e=0;e<16;++e)s[r+e]=l[e];return s}return(0,a.unsafeStringify)(l)}try{i.name=e}catch(e){}return i.DNS=s,i.URL=r,i};var i,a=n(8),o=(i=n(222))&&i.__esModule?i:{default:i};const s="6ba7b810-9dad-11d1-80b4-00c04fd430c8";t.DNS=s;const r="6ba7b811-9dad-11d1-80b4-00c04fd430c8";t.URL=r},355:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=s(n(790)),a=s(n(319)),o=n(8);function s(e){return e&&e.__esModule?e:{default:e}}t.default=function(e,t,n){if(i.default.randomUUID&&!t&&!e)return i.default.randomUUID();const s=(e=e||{}).random||(e.rng||a.default)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=s[e];return t}return(0,o.unsafeStringify)(s)}},764:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=o(n(925)),a=o(n(757));function o(e){return e&&e.__esModule?e:{default:e}}var s=(0,i.default)("v5",80,a.default);t.default=s},435:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i,a=(i=n(58))&&i.__esModule?i:{default:i};t.default=function(e){return"string"==typeof e&&a.default.test(e)}},464:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i,a=(i=n(435))&&i.__esModule?i:{default:i};t.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}}},t={};function n(i){var a=t[i];if(void 0!==a)return a.exports;var o=t[i]={exports:{}};return e[i].call(o.exports,o,o.exports,n),o.exports}var i={};return(()=>{"use strict";var e=i;Object.defineProperty(e,"__esModule",{value:!0});const t=n(838);e.default=t.SceytCallClient})(),i})()));
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "sceyt-call",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "lint": "eslint . --ext .ts",
9
+ "build": "webpack --mode=production",
10
+ "watch": "webpack --mode=production --watch"
11
+ },
12
+ "author": "Sceyt LLC",
13
+ "dependencies": {
14
+ "@types/uuid": "^9.0.7",
15
+ "loglevel": "^1.9.2",
16
+ "uuid": "^9.0.1",
17
+ "webrtc-adapter": "^8.2.3"
18
+ },
19
+ "license": "ISC",
20
+ "devDependencies": {
21
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
22
+ "@typescript-eslint/parser": "^6.11.0",
23
+ "eslint": "^8.53.0",
24
+ "prettier": "^3.1.0",
25
+ "ts-loader": "^9.5.0",
26
+ "typescript": "^5.2.2",
27
+ "webpack": "^5.89.0",
28
+ "webpack-cli": "^5.1.4",
29
+ "webpack-dev-server": "^5.2.0"
30
+ }
31
+ }
@@ -0,0 +1,141 @@
1
+ import { ConnectionState, PresenceState } from "../../types";
2
+ import { createLogger } from "../../utils/logger";
3
+
4
+ const logger = createLogger('CallParticipantStateMachine');
5
+
6
+ export class CallParticipantStateMachine {
7
+ private _presenceState: PresenceState;
8
+ private _connectionState: ConnectionState;
9
+ private stateHistory: { presence: PresenceState; connection: ConnectionState; timestamp: number }[] = [];
10
+
11
+ private static validPresenceTransitions: Record<PresenceState, PresenceState[]> = {
12
+ [PresenceState.Pending]: [PresenceState.Invited],
13
+ [PresenceState.Invited]: [PresenceState.Ringing, PresenceState.Declined, PresenceState.Kicked, PresenceState.NoAnswer],
14
+ [PresenceState.Ringing]: [PresenceState.Joined, PresenceState.Declined, PresenceState.Kicked, PresenceState.NoAnswer],
15
+ [PresenceState.Joined]: [PresenceState.Left, PresenceState.Kicked],
16
+ [PresenceState.Left]: [PresenceState.Invited],
17
+ [PresenceState.Declined]: [PresenceState.Invited],
18
+ [PresenceState.Kicked]: [PresenceState.Invited],
19
+ [PresenceState.NoAnswer]: [PresenceState.Invited],
20
+ };
21
+
22
+ private static validConnectionTransitions: Record<ConnectionState, ConnectionState[]> = {
23
+ [ConnectionState.Idle]: [ConnectionState.Connecting],
24
+ [ConnectionState.Connecting]: [ConnectionState.Connected, ConnectionState.Disconnected],
25
+ [ConnectionState.Connected]: [ConnectionState.Reconnecting, ConnectionState.Disconnected],
26
+ [ConnectionState.Reconnecting]: [ConnectionState.Connected, ConnectionState.Disconnected],
27
+ [ConnectionState.Disconnected]: [ConnectionState.Connecting], // Allow reconnection attempts
28
+ };
29
+
30
+ constructor(
31
+ public userId: string,
32
+ presenceState: PresenceState = PresenceState.Pending,
33
+ connectionState: ConnectionState = ConnectionState.Idle
34
+ ) {
35
+ this._presenceState = presenceState;
36
+ this._connectionState = connectionState;
37
+ this.addToStateHistory();
38
+ }
39
+
40
+ private addToStateHistory() {
41
+ this.stateHistory.push({
42
+ presence: this._presenceState,
43
+ connection: this._connectionState,
44
+ timestamp: Date.now()
45
+ });
46
+ }
47
+
48
+ get presenceState(): PresenceState {
49
+ return this._presenceState;
50
+ }
51
+
52
+ set presenceState(newState: PresenceState) {
53
+ if (CallParticipantStateMachine.validPresenceTransitions[this._presenceState]?.includes(newState)) {
54
+ logger.debug(`Presence state transition: ${this._presenceState} -> ${newState}`);
55
+ this._presenceState = newState;
56
+ this.addToStateHistory();
57
+ } else {
58
+ logger.warn(`Invalid PresenceState transition from ${this._presenceState} to ${newState}`);
59
+ }
60
+ }
61
+
62
+ get connectionState(): ConnectionState {
63
+ return this._connectionState;
64
+ }
65
+
66
+ set connectionState(newState: ConnectionState) {
67
+ if (CallParticipantStateMachine.validConnectionTransitions[this._connectionState]?.includes(newState)) {
68
+ logger.debug(`Connection state transition: ${this._connectionState} -> ${newState}`);
69
+ this._connectionState = newState;
70
+ this.addToStateHistory();
71
+ } else {
72
+ logger.warn(`Invalid ConnectionState transition from ${this._connectionState} to ${newState}`);
73
+ }
74
+ }
75
+
76
+ handleEvent(event: string): void {
77
+ const eventMap: Record<string, () => void> = {
78
+ "CALL_INVITED": () => {
79
+ this.presenceState = PresenceState.Invited;
80
+ if (this._connectionState !== ConnectionState.Idle) {
81
+ this.connectionState = ConnectionState.Idle;
82
+ }
83
+ },
84
+ "CALL_RINGING": () => {
85
+ this.presenceState = PresenceState.Ringing;
86
+ },
87
+ "CALL_ACCEPTED": () => {
88
+ this.presenceState = PresenceState.Joined;
89
+ this.connectionState = ConnectionState.Connecting;
90
+ },
91
+ "CALL_CONNECTED": () => {
92
+ this.connectionState = ConnectionState.Connected;
93
+ },
94
+ "CALL_RECONNECTING": () => {
95
+ this.connectionState = ConnectionState.Reconnecting;
96
+ },
97
+ "CALL_RECONNECTED": () => {
98
+ this.connectionState = ConnectionState.Connected;
99
+ },
100
+ "CALL_DISCONNECTED": () => {
101
+ this.connectionState = ConnectionState.Disconnected;
102
+ },
103
+ "CALL_LEFT": () => {
104
+ this.presenceState = PresenceState.Left;
105
+ this.connectionState = ConnectionState.Disconnected;
106
+ },
107
+ "CALL_DECLINED": () => {
108
+ this.presenceState = PresenceState.Declined;
109
+ },
110
+ "CALL_NO_ANSWER": () => {
111
+ this.presenceState = PresenceState.NoAnswer;
112
+ },
113
+ "CALL_KICKED": () => {
114
+ this.presenceState = PresenceState.Kicked;
115
+ this.connectionState = ConnectionState.Disconnected;
116
+ },
117
+ "CALL_REINVITED": () => {
118
+ this.presenceState = PresenceState.Invited;
119
+ this.connectionState = ConnectionState.Idle;
120
+ }
121
+ };
122
+
123
+ if (eventMap[event]) {
124
+ logger.debug(`Handling event: ${event}`);
125
+ eventMap[event]();
126
+ } else {
127
+ logger.warn(`Unknown event: ${event}`);
128
+ }
129
+ }
130
+
131
+ getStateHistory(): { presence: PresenceState; connection: ConnectionState; timestamp: number }[] {
132
+ return [...this.stateHistory];
133
+ }
134
+
135
+ isInCall(): boolean {
136
+ return this._presenceState === PresenceState.Joined &&
137
+ (this._connectionState === ConnectionState.Connected ||
138
+ this._connectionState === ConnectionState.Reconnecting);
139
+ }
140
+ }
141
+
@@ -0,0 +1,10 @@
1
+ export class RTCConfig {
2
+ protected rtcConfig?: RTCConfiguration;
3
+ constructor(config?: RTCConfiguration) {
4
+ this.rtcConfig = config;
5
+ }
6
+
7
+ setRTCConfig(config: RTCConfiguration) {
8
+ this.rtcConfig = config;
9
+ }
10
+ }
@@ -0,0 +1,17 @@
1
+ export class AudioTrack {
2
+ id: string;
3
+ audioTrack: MediaStreamTrack;
4
+ _enable: boolean = true;
5
+ constructor(audioTrack: MediaStreamTrack) {
6
+ this.id = audioTrack.id;
7
+ this.audioTrack = audioTrack;
8
+ }
9
+
10
+ set enable(enable: boolean) {
11
+ this._enable = enable;
12
+ }
13
+
14
+ get enable() {
15
+ return this._enable;
16
+ }
17
+ }