"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../node_modules/tslib/tslib.es6.js"),r=require("../node_modules/@rematch/core/dist/core.esm.js"),a=require("../lib/phone/audio.js"),u=require("../events/PlayerEvents.js"),n={audioPlayer:null,audioPlayerPlaying:!1,audioPlayerPaused:!1,audioPlayerLoop:!1,audioPlayerTrackType:null,audioPlayerTrackName:null,audioPlayerTrackDuration:null,localAudio:null,remoteAudio:null,localVideo:null,largeRemoteVideo:null,smallRemoteVideo:null,localScreen:null,remoteScreen:null},i=r.createModel()({state:n,reducers:{updatePlayer:function(r,a){return e.__assign(e.__assign({},r),a)},updateAudioPlayerTrackDuration:function(r,a){return e.__assign(e.__assign({},r),{audioPlayerTrackDuration:a})},updateAudioPlayerSrc:function(e,r){return e.audioPlayer&&e.audioPlayer.current&&(e.audioPlayer.current.src=r),e},stopAudioPlayer:function(r){if(r.audioPlayer&&r.audioPlayer.current)return r.audioPlayer.current.pause(),r.audioPlayer.current.currentTime=0,"function"==typeof r.audioPlayer.current.setSinkId&&r.audioPlayer.current.setSinkId("default").catch((function(e){console.warn("Failed to reset audio output device to default:",e)})),e.__assign(e.__assign({},r),{audioPlayerPlaying:!1})},emergencyStopAudioPlayer:function(r){if(r.audioPlayer&&r.audioPlayer.current)try{r.audioPlayer.current.pause(),r.audioPlayer.current.currentTime=0,r.audioPlayer.current.src="","function"==typeof r.audioPlayer.current.setSinkId&&r.audioPlayer.current.setSinkId("default").catch((function(e){console.warn("Failed to reset audio output device to default:",e)}))}catch(e){console.error("Error in emergency stop audio player:",e)}return e.__assign(e.__assign({},r),{audioPlayerPlaying:!1,audioPlayerPaused:!1,audioPlayerLoop:!1,audioPlayerTrackType:null,audioPlayerTrackName:null})},pauseAudioPlayer:function(r){if(r.audioPlayer&&r.audioPlayer.current)return r.audioPlayer.current.pause(),e.__assign(e.__assign({},r),{audioPlayerPaused:!0,audioPlayerPlaying:!1})},setAudioPlayerPaused:function(r,a){return e.__assign(e.__assign({},r),{audioPlayerPaused:a})},setAudioPlayerLoop:function(r,a){return e.__assign(e.__assign({},r),{audioPlayerLoop:a})},setAudioPlayerType:function(r,a){return e.__assign(e.__assign({},r),{audioPlayerTrackType:a})},setAudioPlayerPlaying:function(r,a){return e.__assign(e.__assign({},r),{audioPlayerPlaying:a})},resetAudioPlayerType:function(r){return e.__assign(e.__assign({},r),{audioPlayerTrackType:null})},setAudioPlayerTrackName:function(r,a){return e.__assign(e.__assign({},r),{audioPlayerTrackName:a})},playRemoteAudio:function(e){var r;e.remoteAudio&&(null===(r=e.remoteAudio.current)||void 0===r||r.play())},pauseRemoteAudio:function(e){var r;e.remoteAudio&&(null===(r=e.remoteAudio.current)||void 0===r||r.pause())},setAudioPlayerCurrentTime:function(e,r){e.audioPlayer&&e.audioPlayer.current&&(e.audioPlayer.current.currentTime=r)},reset:function(){return n}},effects:function(r){return{startAudioPlayer:function(e,a){if(a.player.audioPlayer&&a.player.audioPlayer.current){a.player.audioPlayerPlaying&&(a.player.audioPlayer.current.pause(),a.player.audioPlayer.current.currentTime=0);var n=function(){r.player.setAudioPlayerPlaying(!1),a.player.audioPlayer.current.removeEventListener("ended",n),e()};a.player.audioPlayer.current.addEventListener("ended",n),a.player.audioPlayer.current.play(),r.player.setAudioPlayerPlaying(!0),r.player.setAudioPlayerPaused(!1),"player"===a.island.view&&u.dispatchAudioPlayerStarted()}},updateStartAudioPlayer:function(u,n){var i=u.src,o=u.loop,t=void 0!==o&&o,l=u.useRingtoneOutput,d=void 0!==l&&l;return e.__awaiter(void 0,void 0,void 0,(function(){var u,o,l,s,c;return e.__generator(this,(function(e){switch(e.label){case 0:if(r.player.setAudioPlayerLoop(t),!(u=d?null===(s=n.ringtones)||void 0===s?void 0:s.outputDeviceId:null)||!(null===(c=n.player.audioPlayer)||void 0===c?void 0:c.current)||"function"!=typeof n.player.audioPlayer.current.setSinkId)return[3,8];e.label=1;case 1:return e.trys.push([1,3,,8]),[4,n.player.audioPlayer.current.setSinkId(u)];case 2:return e.sent(),console.info("Ringtone output device applied:",u),[3,8];case 3:o=e.sent(),console.warn("Failed to set ringtone output device, trying fallback to default:",o),e.label=4;case 4:return e.trys.push([4,6,,7]),[4,n.player.audioPlayer.current.setSinkId("default")];case 5:return e.sent(),console.info("Ringtone output fallback to default successful"),r.ringtones.setOutputDeviceId("default"),[3,7];case 6:return l=e.sent(),console.error("Even default device failed for ringtone:",l),[3,7];case 7:return[3,8];case 8:return[4,a.updateAudioPlayerSource("data:audio/ogg;base64, ".concat(i))];case 9:return e.sent(),r.player.startAudioPlayer((function(){})),[2]}}))}))}}}});exports.player=i;
//# sourceMappingURL=player.js.map
