UNPKG

@nethesis/phone-island

Version:
3 lines (2 loc) 10.6 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./node_modules/tslib/tslib.es6.js"),n=require("react"),t=require("./components/Events.js"),s=require("./components/Socket.js"),i=require("./components/WebRTC.js"),o=require("./components/Island.js"),a=require("./components/RestAPI.js"),r=require("./utils/customHooks/useEventListener.js"),c=require("./utils/genericFunctions/eventDispatch.js"),d=require("./utils/genericFunctions/localStorage.js"),l=require("./store/index.js"),u=require("./services/user.js");require("./node_modules/react-redux/es/index.js"),require("./node_modules/@fortawesome/react-fontawesome/index.es.js"),require("./node_modules/i18next/dist/esm/i18next.js"),require("./node_modules/react-tooltip/dist/react-tooltip.min.mjs.js");var p=require("./node_modules/js-base64/base64.mjs.js"),h=require("./workers/wake_up.js"),v=require("./lib/i18n.js");require("./node_modules/react-tooltip/dist/react-tooltip.min.css.js");var f=require("./lib/webrtc/messages.js"),g=require("./lib/darkTheme.js"),m=require("./utils/genericFunctions/isEmpty.js"),E=require("./utils/genericFunctions/checkConnection.js"),S=require("./utils/genericFunctions/isBackCallVisible.js"),I=require("./node_modules/react-redux/es/components/Provider.js");function w(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("./node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js"),require("./node_modules/react-redux/node_modules/react-is/index.js"),require("./node_modules/react-redux/es/components/Context.js");var D=w(n),L=function(w){var L=w.dataConfig,j=w.showAlways,b=void 0!==j&&j,q=w.uaType,y=p.Base64.atob(L||"").split(":"),x=y[0],k=y[1],C=y[2],_=y[3],T=y[4],P=y[5],A=y[6],V=n.useState(!1),O=V[0],z=V[1],N=n.useState(!1),U=N[0],F=N[1],R=n.useState(!1),W=R[0],J=R[1];n.useEffect((function(){var e=new Worker(h.default,{type:"module"});return e.onmessage=function(e){"wakeup"===e.data&&z(!0)},function(){e.terminate()}}),[]),n.useEffect((function(){W&&U&&(z(!1),F(!1),J(!1))}),[W,U]),r.useEventListener("phone-island-expand",(function(){l.store.dispatch.island.toggleIsOpen(!0),c.eventDispatch("phone-island-expanded",{})})),r.useEventListener("phone-island-compress",(function(){l.store.dispatch.island.toggleIsOpen(!1),c.eventDispatch("phone-island-compressed",{})})),r.useEventListener("phone-island-call-keypad-close",(function(){l.store.dispatch.island.setIslandView("call"),c.eventDispatch("phone-island-call-keypad-closed",{})})),r.useEventListener("phone-island-call-transfer-close",(function(){l.store.dispatch.island.setIslandView("call"),c.eventDispatch("phone-island-call-transfer-closed",{})})),r.useEventListener("phone-island-recording-close",(function(){l.store.dispatch.island.setIslandView(null),c.eventDispatch("phone-island-recording-closed",{})})),r.useEventListener("phone-island-audio-player-close",(function(){l.store.dispatch.island.setIslandView(null),c.eventDispatch("phone-island-audio-player-closed",{})})),r.useEventListener("phone-island-detach",(function(e){f.detach(),c.eventDispatch("phone-island-detached",{})})),r.useEventListener("phone-island-audio-input-change",(function(e){d.setJSONItem("phone-island-audio-input-device",{deviceId:e.deviceId}),c.eventDispatch("phone-island-audio-input-changed",{})})),r.useEventListener("phone-island-video-input-change",(function(e){d.setJSONItem("phone-island-video-input-device",{deviceId:e.deviceId}),c.eventDispatch("phone-island-video-input-changed",{})}));var B=n.useState(!0),H=B[0],M=B[1],G=n.useState(!0),K=G[0],Q=G[1];r.useEventListener("phone-island-audio-output-change",(function(e){K||(c.eventDispatch("phone-island-call-start",{number:"*43"}),l.store.dispatch.island.setIslandView(null),l.store.dispatch.island.toggleAvoidToShow(!0)),setTimeout((function(){var n=l.store.getState().player.remoteAudio;null==n||n.current.setSinkId(e.deviceId).then((function(){console.info("Default audio output device change with success!"),d.setJSONItem("phone-island-audio-output-device",{deviceId:e.deviceId}),c.eventDispatch("phone-island-audio-output-changed",{}),c.eventDispatch("phone-island-call-end",{}),l.store.dispatch.island.toggleAvoidToShow(!1)})).catch((function(e){console.error("Default audio output device change error:",e),c.eventDispatch("phone-island-call-end",{}),l.store.dispatch.island.toggleAvoidToShow(!1)}))}),500)})),r.useEventListener("phone-island-presence-change",(function(e){u.changeOperatorStatus(e),c.eventDispatch("phone-island-presence-changed",{})})),r.useEventListener("phone-island-view-changed",(function(e){var n=null==e?void 0:e.viewType;l.store.dispatch.island.setIslandView(n)})),n.useEffect((function(){H&&(v.initI18n(),M(!1))}),[H]);var X=l.store.getState().player.remoteAudio;return n.useEffect((function(){var e;if(K&&X){var n=null===(e=d.getJSONItem("phone-island-audio-output-device"))||void 0===e?void 0:e.deviceId;c.eventDispatch("phone-island-audio-output-change",{deviceId:n}),Q(!1)}}),[K,X]),n.useEffect((function(){g.checkDarkTheme()}),[]),r.useEventListener("phone-island-theme-change",(function(e){g.setTheme(null==e?void 0:e.selectedTheme)})),r.useEventListener("phone-island-default-device-change",(function(e){l.store.dispatch.currentUser.updateCurrentDefaultDevice(null==e?void 0:e.deviceInformationObject),c.eventDispatch("phone-island-default-device-changed",{})})),r.useEventListener("phone-island-alert",(function(e){l.store.dispatch.alerts.setAlert(e.toString())})),r.useEventListener("phone-island-check-connection",(function(){E.checkInternetConnection().then((function(e){e?c.eventDispatch("phone-island-internet-connected",{}):c.eventDispatch("phone-island-internet-disconnected",{})}))})),n.useEffect((function(){var e=setInterval((function(){E.checkInternetConnection().then((function(e){e?c.eventDispatch("phone-island-internet-connected",{}):c.eventDispatch("phone-island-internet-disconnected",{})}))}),5e3);return function(){return clearInterval(e)}}),[]),r.useEventListener("phone-island-main-presence",(function(e){var n,t,s,i,o=null===(n=l.store.getState().currentUser)||void 0===n?void 0:n.username,a=l.store.getState().currentUser,r=null==a?void 0:a.mainPresence;if(void 0!==o&&""!==o&&!m.isEmpty(e[o])&&void 0!==(null===(t=e[o])||void 0===t?void 0:t.mainPresence)){var d=null===(s=e[o])||void 0===s?void 0:s.mainPresence;l.store.dispatch.currentUser.updateMainPresence(null===(i=e[o])||void 0===i?void 0:i.mainPresence),"online"===d&&"online"!==r&&c.eventDispatch("phone-island-call-ended",{})}})),r.useEventListener("phone-island-call-status",(function(){var e=l.store.getState().currentCall;console.log("Call status debug informations: ",e)})),r.useEventListener("phone-island-user-status",(function(){var e=l.store.getState().currentUser;console.log("User status debug informations: ",e)})),r.useEventListener("phone-island-all-users-status",(function(){var e=l.store.getState().users;console.log("Users status debug informations: ",e)})),r.useEventListener("phone-island-status",(function(){var e=l.store.getState().island;console.log("Phone island status debug informations: ",e)})),r.useEventListener("phone-island-webrtc-status",(function(){var e=l.store.getState().webrtc;console.log("Webrtc status debug informations: ",e)})),r.useEventListener("phone-island-player-status",(function(){var e=l.store.getState().player;console.log("Player status debug informations: ",e)})),r.useEventListener("phone-island-conference-status",(function(){var e=l.store.getState().conference;console.log("Webrtc status debug informations: ",e)})),r.useEventListener("phone-island-streaming-status",(function(){var e=l.store.getState().streaming;console.log("Streaming status debug informations: ",e)})),r.useEventListener("phone-island-player-force-stop",(function(){l.store.dispatch.player.reset(),console.log("Audio player is interrupted")})),r.useEventListener("phone-island-sideview-open",(function(){l.store.dispatch.island.toggleSideViewVisible(!0),c.eventDispatch("phone-island-sideview-opened",{})})),r.useEventListener("phone-island-sideview-close",(function(){l.store.dispatch.island.toggleSideViewVisible(!1),c.eventDispatch("phone-island-sideview-closed",{})})),r.useEventListener("phone-island-size-change",(function(n){var t=l.store.getState().island.sideViewIsVisible,s=n.sizeInformation,i=e.__assign(e.__assign({},s),{right:t?"42px":"0px",top:S.isBackCallActive()?"40px":"0px"});c.eventDispatch("phone-island-size-changed",{sizes:i})})),r.useEventListener("phone-island-call-ended",(function(){if("online"===l.store.getState().currentUser.mainPresence){c.eventDispatch("phone-island-size-change",{sizeInformation:{width:"0px",height:"0px"}}),c.eventDispatch("phone-island-sideview-close",{}),l.store.dispatch.island.resetIslandStore()}})),r.useEventListener("phone-island-conference-list-open",(function(){l.store.dispatch.island.toggleConferenceList(!0),c.eventDispatch("phone-island-conference-list-opened",{})})),r.useEventListener("phone-island-alert-removed",(function(e){var n=l.store.getState().alerts.status.activeAlertsCount,t=l.store.getState().island,s=t.view,i=t.previousView,o=l.store.getState().conference.isActive,a=l.store.getState().alerts.data,r=l.store.getState().currentCall,d=r.incoming,u=r.outgoing,p=r.accepted,h=null==e?void 0:e.type,v=r.incoming||r.outgoing||r.accepted||""!==r.conversationId;if(!(d||u||p||n>0||"player"===s||"recorder"===s||"physicalPhoneRecorder"===s||"waitingConference"===s&&o||"transfer"===s&&o||"settings"===s&&o||"settings"===s&&("recorder"===i||"player"===i))&&0===n&&(!h||a[h]&&!a[h].active)&&!v){c.eventDispatch("phone-island-size-change",{sizeInformation:{width:"0px",height:"0px"}}),c.eventDispatch("phone-island-sideview-close",{}),l.store.dispatch.island.resetIslandStore()}})),r.useEventListener("phone-island-conference-list-close",(function(){l.store.dispatch.island.toggleConferenceList(!1),c.eventDispatch("phone-island-conference-list-closed",{})})),D.default.createElement(D.default.Fragment,null,D.default.createElement(I.default,{store:l.store},D.default.createElement(i.WebRTC,{hostName:x,sipExten:_,sipSecret:T,sipHost:P,sipPort:A,reload:O,reloadedCallback:function(){return F(!0)},uaType:q},D.default.createElement(a.RestAPI,{hostName:x,username:k,authToken:C},D.default.createElement(s.Socket,{hostName:x,username:k,authToken:C,reload:O,reloadedCallback:function(){return J(!0)},uaType:q},D.default.createElement(t.Events,{sipHost:P},D.default.createElement(o.Island,{showAlways:b,uaType:q})))))))};L.displayName="PhoneIsland",exports.PhoneIsland=L; //# sourceMappingURL=App.js.map