diff --git a/client/src/components/player.vue b/client/src/components/player.vue index 87c4442..757e2f0 100644 --- a/client/src/components/player.vue +++ b/client/src/components/player.vue @@ -156,7 +156,7 @@ export default { }, }, created() { - this.initializationInfo(); + // this.initializationInfo(); this.connectionPlayer(); }, mounted() { @@ -209,8 +209,10 @@ export default { if (this.connection) { this.connection.removePlay(); } + this.connection = new Player(); this.connection.init(); + this.connection.onHandler(this.getPlaying); }, checkSongIsFavorite() { @@ -235,30 +237,34 @@ export default { }); }, getPlaying(e) { + // console.log('getPlaying', e); const jsonData = JSON.parse(e.data); + console.log('jsonData', jsonData); + const data = + // Второй ответ + jsonData?.pub?.data || + // Первый ответ + jsonData?.connect?.subs?.['station:it-radio']?.publications?.[0]?.data; + console.log('getPlaying', data); - if (jsonData?.pub?.data) { - const data = jsonData?.pub?.data; - if (this.currentPlay.live) { - if (data.np.station.listen_url !== this.player.target.src) { - console.log( - 'data.np.station.listen_url', - data.np.station.listen_url, - ); - this.$store.dispatch('changePlayer', data.np.station.listen_url); - console.log(this.player); - const params = { - ...this.currentPlay, - ...data.np.now_playing.song, - azura_id: data.np.now_playing.song.id, - isLoader: false, - live: true, - currentIndex: null, - }; - delete params.unique_id; - this.$store.dispatch('setCurrentPlay', params); - console.log(this.$store.state); - } + if (!data) return; + if (this.currentPlay.live) { + const dataUrl = data.np.station.listen_url; + if (data.np.station.listen_url !== this.player.target.src) { + console.log('data.np.station.listen_url', data.np.station.listen_url); + this.$store.dispatch('changePlayer', data.np.station.listen_url); + console.log(this.player); + const params = { + ...this.currentPlay, + ...data.np.now_playing.song, + azura_id: data.np.now_playing.song.id, + isLoader: false, + live: true, + currentIndex: null, + }; + delete params.unique_id; + this.$store.dispatch('setCurrentPlay', params); + console.log(this.$store.state); } } }, diff --git a/client/src/services/audio.js b/client/src/services/audio.js index 532793d..6ab2f17 100644 --- a/client/src/services/audio.js +++ b/client/src/services/audio.js @@ -24,6 +24,8 @@ export default class extends REST { this.connection = new EventSource( sseBaseUri + '?' + sseUriParams.toString(), ); + // window.connection = this.connection; + this.connection.onopen = (e) => console.log('connected', e); } removePlay() {