UNPKG

@nethesis/phone-island

Version:
3 lines (2 loc) 11.9 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../node_modules/tslib/tslib.es6.js"),t=require("../webrtc/messages.js"),r=require("../../store/index.js"),n=require("../user/default_device.js"),s=require("../../services/astproxy.js"),o=require("../../static/dtmf/index.js");require("react");var i=require("../../utils/genericFunctions/eventDispatch.js"),a=require("../../services/user.js"),c=require("../../utils/genericFunctions/isEmpty.js"),u=require("../../utils/streaming/getStreamingSourceId.js");function l(){var e=r.store.getState().currentCall,o=e.outgoing,c=e.accepted,l=e.streamingSourceNumber,d=r.store.getState().island.isFromStreaming;if(o||c){if(n.isWebRTC()?t.hangup():s.hangupPhysical(),r.store.dispatch.player.stopAudioPlayer(),r.store.dispatch.currentCall.reset(),r.store.dispatch.listen.reset(),d&&l){var p=u.getStreamingSourceId(l);p&&(a.unsubscribe({id:p}).then((function(){return console.debug("Unsubscribed from streaming source: ".concat(p))})).catch((function(e){return console.error("Error unsubscribing from streaming source:",e)})),r.store.dispatch.streaming.clearSourceImages())}r.store.dispatch.island.setIsFromStreaming(!1)}r.store.dispatch.island.resetOperatorBusy(),i.eventDispatch("phone-island-call-ended",{})}function d(){n.isWebRTC()?t.unpauseWebRTC()&&(r.store.dispatch.currentCall.updateCurrentCall({paused:!1}),r.store.dispatch.player.playRemoteAudio()):s.pausePhysical(!1);i.eventDispatch("phone-island-call-unheld",{})}function p(t){return e.__awaiter(this,void 0,void 0,(function(){var n,o,i;return e.__generator(this,(function(e){switch(e.label){case 0:return n=r.store.getState().currentCall.conversationId,o=r.store.getState().currentUser.default_device,i=(null==o?void 0:o.id)||(null==o?void 0:o.exten),n&&i&&t?[4,s.attendedTransfer({convid:n,to:t,endpointId:i})]:[3,2];case 1:return[2,e.sent()];case 2:return[2]}}))}))}function v(){var t;return e.__awaiter(this,void 0,void 0,(function(){var n,o,a,u,l,d,p,v,f,h,g,C,m,b;return e.__generator(this,(function(e){switch(e.label){case 0:if(n=null===(t=null===r.store||void 0===r.store?void 0:r.store.getState())||void 0===t?void 0:t.currentCall,o=n.accepted,a=n.chSource,u=n.chDest,l=n.incoming,d=n.outgoing,p=n.incomingSocket,v=n.outgoingSocket,f=n.conversationId,h=r.store.getState().currentUser.default_device,g=(null==h?void 0:h.id)||(null==h?void 0:h.exten),C="",o&&(l||p)&&!c.isEmpty(a)?C=null==a?void 0:a.callerNum:o&&(d||v)&&!c.isEmpty(u)&&(C=null==u?void 0:u.callerNum),""===g||""===f||""===C)return[3,4];if(!(m={convid:null==f?void 0:f.toString(),addEndpointId:null==C?void 0:C.toString(),ownerEndpointId:null==g?void 0:g.toString()}))return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,s.startConf(m)];case 2:return e.sent()?(r.store.dispatch.currentCall.updateCurrentCall({conferencing:!0,paused:!1}),i.eventDispatch("phone-island-call-conferenced",{}),[2,!0]):[2,!1];case 3:return b=e.sent(),console.error(b),[2,!1];case 4:return[2,!1]}}))}))}function f(){return e.__awaiter(this,void 0,void 0,(function(){var t,n,o;return e.__generator(this,(function(e){switch(e.label){case 0:if(""===(t=r.store.getState().conference.conferenceId))return[3,4];if(!(n={confId:null==t?void 0:t.toString()}))return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,s.endConf(n)];case 2:return e.sent()?(i.eventDispatch("phone-island-owner-conference-finished",{}),[2,!0]):[2,!1];case 3:return o=e.sent(),console.error(o),[2,!1];case 4:return[2,!1]}}))}))}var h=function(){return!!r.store.getState().island.isConferenceList},g=function(e,t){var n=r.store.getState(),s=n.currentUser.username,o=n.conference,a=o.isActive,c=o.isOwnerInside,u=o.conferenceId,d=n.users.extensions;!a&&s&&(t.conference.setConferenceActive(!0),t.conference.setConferenceStartedFrom(s));var p=d?Object.values(d).find((function(t){return t.exten===e})):null,v=(null==p?void 0:p.name)||e;t.conference.addPendingUser({id:"".concat(u,"-").concat(e),name:v,owner:!1,muted:!1,extenId:e,joinTime:Date.now()}),c&&(l(),t.conference.toggleIsOwnerInside(!1)),requestAnimationFrame((function(){setTimeout((function(){i.eventDispatch("phone-island-call-start",{number:e})}),1e3)}))};function C(t,r){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return d(),[4,p(t)];case 1:return e.sent()&&(r.currentCall.updateCurrentCall({transferring:!0,paused:!1}),requestAnimationFrame((function(){r.player.playRemoteAudio(),i.eventDispatch("phone-island-call-transfered",{})}))),[2]}}))}))}exports.answerIncomingCall=function(){n.isWebRTC()?t.answerWebRTC():s.answerPhysical(),r.store.dispatch.island.resetOperatorBusyCompletely()},exports.attendedTransfer=p,exports.blindTransferFunction=function(t,n){return e.__awaiter(this,void 0,void 0,(function(){var o;return e.__generator(this,(function(e){switch(e.label){case 0:return(o=r.store.getState().currentCall.conversationId)&&n&&t?[4,s.blindTransfer({convid:o,to:t,endpointId:n})]:[3,2];case 1:return[2,e.sent()];case 2:return[2]}}))}))},exports.callNumber=function(e,o){var a="sip:".concat(e,"@").concat(o);r.store.dispatch.island.resetOperatorBusy(),r.store.dispatch.island.setOperatorBusyCalledNumber(e),n.isWebRTC()?t.callSipURI(a):s.callPhysical(e),i.eventDispatch("phone-island-call-started",{})},exports.clickTransferOrConference=function(t,n){return e.__awaiter(void 0,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return h()?r.store.getState().conference.isActive?[3,2]:[4,v()]:[3,3];case 1:if(!e.sent())return[2];e.label=2;case 2:return g(t,n),[3,4];case 3:C(t,n),e.label=4;case 4:return[2]}}))}))},exports.endConference=f,exports.forceHangupConversation=function(){var e=r.store.getState().currentUser.conversations,t=function(t){Object.keys(e[t]).forEach((function(e){s.forceHangup({convid:e,endpointId:t,endpointType:"extension"})}))};for(var n in e)t(n)},exports.handleAttendedTransfer=C,exports.hangupAllExtensions=function(){var e=r.store.getState().currentUser.conversations,t=function(t){Object.keys(e[t]).forEach((function(e){s.hangupConversation({convid:e,endpointId:t})}))};for(var n in e)t(n)},exports.hangupCurrentCall=l,exports.hangupCurrentPhysicalRecording=function(){s.hangupPhysicalRecordingCall(),r.store.dispatch.player.stopAudioPlayer(),r.store.dispatch.physicalRecorder.reset(),r.store.dispatch.physicalRecorder.setRecording(!1),r.store.dispatch.island.setIslandView(null),r.store.dispatch.listen.reset(),i.eventDispatch("phone-island-call-ended",{})},exports.isInsideConferenceList=h,exports.joinConference=function(){return e.__awaiter(this,void 0,void 0,(function(){var t,n,o,a;return e.__generator(this,(function(e){switch(e.label){case 0:if(t=r.store.getState().currentUser.default_device,""===(n=(null==t?void 0:t.id)||(null==t?void 0:t.exten)))return[3,4];if(!(o={endpointId:null==n?void 0:n.toString()}))return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,s.joinMyConf(o)];case 2:return e.sent()?(i.eventDispatch("phone-island-owner-conference-enter",{}),[2,!0]):[2,!1];case 3:return a=e.sent(),console.error(a),[2,!1];case 4:return[2,!1]}}))}))},exports.muteAllUsersConference=function(t,n){var o;return e.__awaiter(this,void 0,void 0,(function(){var i,a,c,u,l,d,p,v;return e.__generator(this,(function(e){switch(e.label){case 0:if(""===t)return[2,!1];if(!(i=r.store.getState().conference.usersList)||0===Object.keys(i).length)return[2,!1];e.label=1;case 1:e.trys.push([1,6,,7]),a=Object.values(i),c=n?s.unmuteUserConf:s.muteUserConf,u=0,l=a,e.label=2;case 2:return u<l.length?(d=l[u],p={confId:null==t?void 0:t.toString(),userId:null===(o=d.id)||void 0===o?void 0:o.toString()},[4,c(p)]):[3,5];case 3:e.sent()&&r.store.dispatch.conference.toggleUserMuted({extenId:d.extenId,muted:!n}),e.label=4;case 4:return u++,[3,2];case 5:return[2,!0];case 6:return v=e.sent(),console.error(v),[2,!1];case 7:return[2]}}))}))},exports.muteCurrentCall=function(){n.isWebRTC()?t.muteWebRTC()&&r.store.dispatch.currentCall.updateCurrentCall({muted:!0}):s.mutePhysical(!0),i.eventDispatch("phone-island-call-muted",{})},exports.muteUserConference=function(t,r,n){return e.__awaiter(this,void 0,void 0,(function(){var o,i;return e.__generator(this,(function(e){switch(e.label){case 0:if(""===t||""===r)return[2,!1];o={confId:null==t?void 0:t.toString(),userId:null==r?void 0:r.toString()},e.label=1;case 1:return e.trys.push([1,3,,4]),[4,(n?s.unmuteUserConf:s.muteUserConf)(o)];case 2:return[2,!!e.sent()];case 3:return i=e.sent(),console.error(i),[2,!1];case 4:return[2]}}))}))},exports.parkCurrentCall=function(){var e,t,n,o,a=null===(t=null===(e=null===r.store||void 0===r.store?void 0:r.store.getState())||void 0===e?void 0:e.currentCall)||void 0===t?void 0:t.conversationId,c=null===(o=null===(n=null===r.store||void 0===r.store?void 0:r.store.getState())||void 0===n?void 0:n.currentUser)||void 0===o?void 0:o.conversations,u={};if(a){if(c)for(var l in c)if(c.hasOwnProperty(l)){var d=c[l];Object.keys(d).length>0&&(u={numberParkId:l,idConversation:a})}Object.keys(u).length>0&&(null==u?void 0:u.numberParkId)&&(s.parkConversation({applicantId:null==u?void 0:u.numberParkId,convid:a,endpointId:null==u?void 0:u.numberParkId}),r.store.dispatch.currentCall.setParked(!0),i.eventDispatch("phone-island-call-parked",{}))}},exports.pauseCurrentCall=function(){n.isWebRTC()?t.pauseWebRTC()&&(r.store.dispatch.currentCall.updateCurrentCall({paused:!0}),r.store.dispatch.player.pauseRemoteAudio()):s.pausePhysical(!0),i.eventDispatch("phone-island-call-held",{})},exports.playDtmfAudio=function(e){"*"===e&&(e="star"),"#"===e&&(e="pound"),r.store.dispatch.player.updateStartAudioPlayer({src:o.default["dtmf_".concat(e)]})},exports.recordCurrentCall=function(t){var n,o,i,a;return e.__awaiter(this,void 0,void 0,(function(){var c,u,l,d,p,v,f;return e.__generator(this,(function(e){switch(e.label){case 0:return r.store.dispatch.currentCall.updateRecordingStatus(!t),c=null===(o=null===(n=null===r.store||void 0===r.store?void 0:r.store.getState())||void 0===n?void 0:n.currentUser)||void 0===o?void 0:o.conversations,(u=function(e){for(var t in e)if(0!==Object.keys(e[t]).length){var r=Object.values(e[t])[0];return{id:r.id,recording:r.recording}}return null}(c))?[3,1]:[2];case 1:switch(l=null===(i=null==u?void 0:u.id)||void 0===i?void 0:i.match(/\/(\d+)-/),d=l[1],p={convid:null===(a=null==u?void 0:u.id)||void 0===a?void 0:a.toString(),endpointId:null==d?void 0:d.toString()},v="",null==u?void 0:u.recording){case"false":v="start_record";break;case"true":v="mute_record";break;case"mute":v="unmute_record";break;default:v=""}if(!p)return[3,5];e.label=2;case 2:return e.trys.push([2,4,,5]),[4,s.toggleRecord(v,p)];case 3:return e.sent(),[3,5];case 4:return f=e.sent(),console.error(f),[2,[]];case 5:return[2]}}))}))},exports.removeUserConference=function(t,n){return e.__awaiter(this,void 0,void 0,(function(){var o,i,a=this;return e.__generator(this,(function(c){switch(c.label){case 0:if(""===t||""===n)return[3,4];if(!(o={confId:null==t?void 0:t.toString(),extenId:null==n?void 0:n.toString()}))return[3,4];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,s.hangupUserConf(o)];case 2:return c.sent()?(setTimeout((function(){return e.__awaiter(a,void 0,void 0,(function(){var t,s;return e.__generator(this,(function(e){switch(e.label){case 0:return t=r.store.getState().conference.usersList,s=Object.values(t||{}).filter((function(e){return!e.owner&&e.extenId!==n})).length,0!==s?[3,2]:[4,f()];case 1:e.sent(),e.label=2;case 2:return[2]}}))}))}),500),[2,!0]):[2,!1];case 3:return i=c.sent(),console.error(i),[2,!1];case 4:return[2,!1]}}))}))},exports.startConference=v,exports.unmuteCurrentCall=function(){n.isWebRTC()?t.unmuteWebRTC()&&r.store.dispatch.currentCall.updateCurrentCall({muted:!1}):s.mutePhysical(!1),i.eventDispatch("phone-island-call-unmuted",{})},exports.unpauseCurrentCall=d,exports.waitingConferenceView=g; //# sourceMappingURL=call.js.map