добавлена обработка первого события в getPlaying

This commit is contained in:
Norbaev 2024-06-27 20:51:07 +05:00
parent 3da3f39f5a
commit b82f4137a6
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,16 +237,21 @@ 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',
data.np.station.listen_url,
);
this.$store.dispatch('changePlayer', data.np.station.listen_url); this.$store.dispatch('changePlayer', data.np.station.listen_url);
console.log(this.player); console.log(this.player);
const params = { const params = {
@ -260,7 +267,6 @@ export default {
console.log(this.$store.state); console.log(this.$store.state);
} }
} }
}
}, },
updateProgress(e) { updateProgress(e) {
this.playerInfo = { this.playerInfo = {

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() {