diff --git a/client/src/boot/main.js b/client/src/boot/main.js index 996adb4..19c55f8 100644 --- a/client/src/boot/main.js +++ b/client/src/boot/main.js @@ -73,6 +73,7 @@ export default boot(async ({ app, router }) => { }), toggle: createInput(toggle, { props: ['placeholder', 'disabled', 'readonly'], + emits: ['toggle'] }), }, }; diff --git a/client/src/components/inputs/toggle.vue b/client/src/components/inputs/toggle.vue index 553d985..6e2adc7 100644 --- a/client/src/components/inputs/toggle.vue +++ b/client/src/components/inputs/toggle.vue @@ -1,27 +1,42 @@ - diff --git a/client/src/components/player.vue b/client/src/components/player.vue index c30defe..85dc023 100644 --- a/client/src/components/player.vue +++ b/client/src/components/player.vue @@ -10,17 +10,17 @@
- {{currentPlay.title || '—'}} - {{currentPlay.artist || '—'}} + {{ currentPlay.title || '—' }} + {{ currentPlay.artist || '—' }}
- {{isLive}}
@@ -50,88 +50,98 @@ export default { audioUrl: 'http://82.97.242.49:18000/radio.mp3', isFavorites: false, isPlayRadio: true, - connection: null, - isLive: false - } + connection: null, + isLive: !this.$store.state.currentPlay.live, + } }, - computed:{ - user() { - return this.$store.state.user; - }, - currentPlay(){ - return this.$store.state.currentPlay - }, - player(){ - return this.$store.state.player - } - }, - watch:{ - 'currentPlay': { - immediate: true, - handler() { - console.debug('this.currentPlay.live',!this.currentPlay.live) - this.isLive = !this.currentPlay.live - }, - } - }, - created() { - this.connectionPlayer(); - }, - mounted() { - // if (!this.player.target){ - this.$store.dispatch('initPlayer'); - // } + computed: { + user() { + return this.$store.state.user; + }, + currentPlay() { + return this.$store.state.currentPlay + }, + player() { + return this.$store.state.player + } + }, + watch: { + 'currentPlay': { + immediate: false, + handler() { + if (this.isLive!==!this.currentPlay.live){ + this.isLive = !this.currentPlay.live; + } + }, + }, + }, + created() { + this.connectionPlayer(); + }, + mounted() { + if (!this.player.target) { + this.$store.dispatch('initPlayer'); + } }, methods: { - connectionPlayer() { - if (this.connection) { - this.connection.removePlay(); - } - this.connection = new Player(); - this.connection.init(); - this.connection.onHandler(this.getPlaying); - }, - getPlaying (e){ - const jsonData = JSON.parse(e.data) - if (jsonData?.pub?.data){ - const data = jsonData?.pub?.data; - if (this.currentPlay.live){ - if (data.np.station.listen_url!==this.player.target.src){ - this.$store.dispatch('changePlayer', data.np.station.listen_url); - } - this.$store.dispatch('setCurrentPlay', {...data.np.now_playing.song, live: false}); - } - } - }, - updateProgress(){ + connectionPlayer() { + if (this.connection) { + this.connection.removePlay(); + } + this.connection = new Player(); + this.connection.init(); + this.connection.onHandler(this.getPlaying); + }, + getPlaying(e) { + const jsonData = JSON.parse(e.data) + if (jsonData?.pub?.data) { + const data = jsonData?.pub?.data; + if (this.currentPlay.live) { + if (data.np.station.listen_url !== this.player.target.src) { + this.$store.dispatch('changePlayer', data.np.station.listen_url); + } + this.$store.dispatch('setCurrentPlay', {...data.np.now_playing.song, live: true}); + } + } + }, + updateProgress() { console.log(this.$refs.player.currentTime) console.log(this.$refs.player.duration) }, handlerPlay() { - this.$store.dispatch('handlerPlayer', {play: true}); + this.$store.dispatch('handlerPlayer', {play: true}); }, handlerPause() { - this.$store.dispatch('handlerPlayer', {pause: true}); + this.$store.dispatch('handlerPlayer', {pause: true}); }, - handlerFavorites(){ - if (this.user?.id){ - this.isFavorites = !this.isFavorites; - const params = {...this.currentPlay, azura_id:this.currentPlay.id}; - app.createFavoriteForUser(params).then(()=>{ + handlerFavorites() { + if (this.user?.id) { + this.isFavorites = !this.isFavorites; + const params = {...this.currentPlay, azura_id: this.currentPlay.id}; + app.createFavoriteForUser(params).then(() => { + + }) + } else { + this.$emit('shopAuthentication', true) + } - }) - }else { - this.$emit('shopAuthentication', true) - } - }, - setVolume(){ - this.$store.dispatch('handlerPlayer', {volume: 100}); - }, + setVolume() { + this.$store.dispatch('handlerPlayer', {volume: 100}); + }, changeVolume() { - this.$store.dispatch('handlerPlayer', {volume: 100}); + this.$store.dispatch('handlerPlayer', {volume: 100}); }, - + changeLive(e) { + console.log(e) + if (this.currentPlay.live) { + this.$store.dispatch('setCurrentPlay', {live: false}); + console.log('избранное') + } else { + this.$store.dispatch('setCurrentPlay', {live: true}); + console.log('поток') + } + } } } diff --git a/client/src/store/index.js b/client/src/store/index.js index 2d94931..8039931 100644 --- a/client/src/store/index.js +++ b/client/src/store/index.js @@ -22,7 +22,7 @@ export default createStore({ player:{ target: null, volume: 50, - live: false, + live: true, } } }, @@ -53,7 +53,7 @@ export default createStore({ state.player.target.src = ''; state.player.target.preload = 'auto'; state.player.target.controls = true; - console.log(state.player.target) + console.log('initPlayer',state.player.target) }, changePlayer(state, params){ state.player.target.src = params; @@ -101,6 +101,6 @@ export default createStore({ changePlayer(context, params){ context.commit('changePlayer', params); } - + } });