This commit is contained in:
Norbaev 2024-06-28 09:03:52 +05:00
commit 15acc8c861
2 changed files with 31 additions and 23 deletions

View File

@ -156,7 +156,7 @@ export default {
}, },
}, },
created() { created() {
this.initializationInfo(); // this.initializationInfo();
this.connectionPlayer(); this.connectionPlayer();
}, },
mounted() { mounted() {
@ -209,8 +209,10 @@ export default {
if (this.connection) { if (this.connection) {
this.connection.removePlay(); this.connection.removePlay();
} }
this.connection = new Player(); this.connection = new Player();
this.connection.init(); this.connection.init();
this.connection.onHandler(this.getPlaying); this.connection.onHandler(this.getPlaying);
}, },
checkSongIsFavorite() { checkSongIsFavorite() {
@ -235,30 +237,34 @@ export default {
}); });
}, },
getPlaying(e) { getPlaying(e) {
// console.log('getPlaying', e);
const jsonData = JSON.parse(e.data); 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) { if (!data) return;
const data = jsonData?.pub?.data; if (this.currentPlay.live) {
if (this.currentPlay.live) { const dataUrl = data.np.station.listen_url;
if (data.np.station.listen_url !== this.player.target.src) { if (data.np.station.listen_url !== this.player.target.src) {
console.log( console.log('data.np.station.listen_url', data.np.station.listen_url);
'data.np.station.listen_url', this.$store.dispatch('changePlayer', data.np.station.listen_url);
data.np.station.listen_url, console.log(this.player);
); const params = {
this.$store.dispatch('changePlayer', data.np.station.listen_url); ...this.currentPlay,
console.log(this.player); ...data.np.now_playing.song,
const params = { azura_id: data.np.now_playing.song.id,
...this.currentPlay, isLoader: false,
...data.np.now_playing.song, live: true,
azura_id: data.np.now_playing.song.id, currentIndex: null,
isLoader: false, };
live: true, delete params.unique_id;
currentIndex: null, this.$store.dispatch('setCurrentPlay', params);
}; console.log(this.$store.state);
delete params.unique_id;
this.$store.dispatch('setCurrentPlay', params);
console.log(this.$store.state);
}
} }
} }
}, },

View File

@ -24,6 +24,8 @@ export default class extends REST {
this.connection = new EventSource( this.connection = new EventSource(
sseBaseUri + '?' + sseUriParams.toString(), sseBaseUri + '?' + sseUriParams.toString(),
); );
// window.connection = this.connection;
this.connection.onopen = (e) => console.log('connected', e);
} }
removePlay() { removePlay() {