|
@@ -760,55 +760,29 @@ export default {
|
|
|
}
|
|
|
);
|
|
|
|
|
|
- this.socket.on("event:songs.next", res => {
|
|
|
- const { currentSong } = res.data;
|
|
|
-
|
|
|
- this.updateCurrentSong(currentSong || {});
|
|
|
-
|
|
|
- let nextSong = null;
|
|
|
- if (this.songsList[1]) {
|
|
|
- nextSong = this.songsList[1].youtubeId
|
|
|
- ? this.songsList[1]
|
|
|
- : null;
|
|
|
+ this.socket.on("event:songs.skip", res => {
|
|
|
+ const { skippedSong } = res.data;
|
|
|
+ if (this.currentSong._id === skippedSong._id) {
|
|
|
+ this.skipSong();
|
|
|
}
|
|
|
- this.updateNextSong(nextSong);
|
|
|
-
|
|
|
- this.startedAt = res.data.startedAt;
|
|
|
- this.updateStationPaused(res.data.paused);
|
|
|
- this.timePaused = res.data.timePaused;
|
|
|
-
|
|
|
- if (currentSong) {
|
|
|
- this.updateNoSong(false);
|
|
|
-
|
|
|
- if (!this.playerReady) this.youtubeReady();
|
|
|
- else this.playVideo();
|
|
|
-
|
|
|
- this.socket.dispatch(
|
|
|
- "songs.getOwnSongRatings",
|
|
|
- currentSong.youtubeId,
|
|
|
- res => {
|
|
|
- if (
|
|
|
- res.status === "success" &&
|
|
|
- this.currentSong.youtubeId === res.data.youtubeId
|
|
|
- ) {
|
|
|
- this.liked = res.data.liked;
|
|
|
- this.disliked = res.data.disliked;
|
|
|
+ });
|
|
|
|
|
|
- if (
|
|
|
- this.autoSkipDisliked &&
|
|
|
- res.data.disliked === true
|
|
|
- ) {
|
|
|
- this.voteSkipStation();
|
|
|
- new Toast(
|
|
|
- "Automatically voted to skip disliked song."
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- } else {
|
|
|
- if (this.playerReady) this.player.pauseVideo();
|
|
|
- this.updateNoSong(true);
|
|
|
+ this.socket.on("event:songs.next", res => {
|
|
|
+ const { currentSong, startedAt, paused, timePaused } = res.data;
|
|
|
+ if (this.noSong) {
|
|
|
+ this.setCurrentSong({
|
|
|
+ currentSong,
|
|
|
+ startedAt,
|
|
|
+ paused,
|
|
|
+ timePaused,
|
|
|
+ pausedAt: 0
|
|
|
+ });
|
|
|
+ } else if (
|
|
|
+ this.nextSong &&
|
|
|
+ currentSong &&
|
|
|
+ this.nextSong._id === currentSong._id
|
|
|
+ ) {
|
|
|
+ this.setNextSong(currentSong);
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -816,12 +790,20 @@ export default {
|
|
|
this.pausedAt = res.data.pausedAt;
|
|
|
this.updateStationPaused(true);
|
|
|
this.pauseLocalPlayer();
|
|
|
+
|
|
|
+ clearTimeout(window.stationNextSongTimeout);
|
|
|
});
|
|
|
|
|
|
this.socket.on("event:stations.resume", res => {
|
|
|
this.timePaused = res.data.timePaused;
|
|
|
this.updateStationPaused(false);
|
|
|
if (!this.localPaused) this.resumeLocalPlayer();
|
|
|
+
|
|
|
+ if (this.currentSong)
|
|
|
+ window.stationNextSongTimeout = setTimeout(
|
|
|
+ this.skipSong,
|
|
|
+ this.getTimeRemaining()
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
this.socket.on("event:stations.remove", () => {
|
|
@@ -883,7 +865,7 @@ export default {
|
|
|
? this.songsList[0]
|
|
|
: null;
|
|
|
|
|
|
- this.updateNextSong(nextSong);
|
|
|
+ this.setNextSong(nextSong);
|
|
|
|
|
|
this.addPartyPlaylistSongToQueue();
|
|
|
});
|
|
@@ -897,7 +879,7 @@ export default {
|
|
|
? this.songsList[0]
|
|
|
: null;
|
|
|
|
|
|
- this.updateNextSong(nextSong);
|
|
|
+ this.setNextSong(nextSong);
|
|
|
});
|
|
|
|
|
|
this.socket.on("event:song.voteSkipSong", () => {
|
|
@@ -1011,6 +993,7 @@ export default {
|
|
|
});
|
|
|
|
|
|
clearInterval(this.activityWatchVideoDataInterval);
|
|
|
+ clearTimeout(window.stationNextSongTimeout);
|
|
|
|
|
|
this.socket.dispatch("stations.leave", this.station._id, () => {});
|
|
|
|
|
@@ -1038,6 +1021,126 @@ export default {
|
|
|
}
|
|
|
);
|
|
|
},
|
|
|
+ setNextSong(nextSong) {
|
|
|
+ if (
|
|
|
+ nextSong &&
|
|
|
+ (!this.nextSong || this.nextSong._id !== nextSong._id) &&
|
|
|
+ (!this.noSong && nextSong._id !== this.currentSong._id)
|
|
|
+ ) {
|
|
|
+ this.updateNextSong(nextSong);
|
|
|
+
|
|
|
+ this.socket.dispatch(
|
|
|
+ "stations.getNextSongInfo",
|
|
|
+ this.station._id,
|
|
|
+ nextSong._id,
|
|
|
+ data => {
|
|
|
+ if (data.status === "success") {
|
|
|
+ if (
|
|
|
+ this.nextSong &&
|
|
|
+ this.nextSong._id === nextSong._id
|
|
|
+ ) {
|
|
|
+ this.updateNextSong(data.data.nextSong);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (!nextSong) {
|
|
|
+ this.updateNextSong(null);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ skipSong() {
|
|
|
+ if (this.nextSong) {
|
|
|
+ this.setCurrentSong({
|
|
|
+ currentSong: {
|
|
|
+ ...this.nextSong,
|
|
|
+ skipVotes: 0
|
|
|
+ },
|
|
|
+ startedAt: Date.now(),
|
|
|
+ paused: this.stationPaused,
|
|
|
+ timePaused: 0,
|
|
|
+ pausedAt: 0
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setCurrentSong({
|
|
|
+ currentSong: null,
|
|
|
+ startedAt: 0,
|
|
|
+ paused: this.stationPaused,
|
|
|
+ timePaused: 0,
|
|
|
+ pausedAt: 0
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setCurrentSong(data) {
|
|
|
+ const {
|
|
|
+ currentSong,
|
|
|
+ startedAt,
|
|
|
+ paused,
|
|
|
+ timePaused,
|
|
|
+ pausedAt
|
|
|
+ } = data;
|
|
|
+
|
|
|
+ this.updateCurrentSong(currentSong || {});
|
|
|
+
|
|
|
+ if (
|
|
|
+ currentSong &&
|
|
|
+ this.nextSong &&
|
|
|
+ currentSong._id === this.nextSong._id
|
|
|
+ ) {
|
|
|
+ this.setNextSong(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ clearTimeout(window.stationNextSongTimeout);
|
|
|
+
|
|
|
+ this.startedAt = startedAt;
|
|
|
+ this.updateStationPaused(paused);
|
|
|
+ this.timePaused = timePaused;
|
|
|
+ this.pausedAt = pausedAt;
|
|
|
+
|
|
|
+ if (currentSong) {
|
|
|
+ this.updateNoSong(false);
|
|
|
+
|
|
|
+ if (!this.playerReady) this.youtubeReady();
|
|
|
+ else this.playVideo();
|
|
|
+
|
|
|
+ if (!this.stationPaused) {
|
|
|
+ window.stationNextSongTimeout = setTimeout(
|
|
|
+ this.skipSong,
|
|
|
+ this.getTimeRemaining()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ this.socket.dispatch(
|
|
|
+ "songs.getOwnSongRatings",
|
|
|
+ currentSong.youtubeId,
|
|
|
+ res => {
|
|
|
+ if (
|
|
|
+ res.status === "success" &&
|
|
|
+ this.currentSong.youtubeId === res.data.youtubeId
|
|
|
+ ) {
|
|
|
+ this.liked = res.data.liked;
|
|
|
+ this.disliked = res.data.disliked;
|
|
|
+
|
|
|
+ if (
|
|
|
+ this.autoSkipDisliked &&
|
|
|
+ res.data.disliked === true
|
|
|
+ ) {
|
|
|
+ this.voteSkipStation();
|
|
|
+ new Toast(
|
|
|
+ "Automatically voted to skip disliked song."
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ if (this.playerReady) this.player.pauseVideo();
|
|
|
+ this.updateNoSong(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.calculateTimeElapsed();
|
|
|
+ this.resizeSeekerbar();
|
|
|
+ },
|
|
|
youtubeReady() {
|
|
|
if (!this.player) {
|
|
|
this.player = new window.YT.Player("stationPlayer", {
|
|
@@ -1174,6 +1277,12 @@ export default {
|
|
|
}
|
|
|
return 0;
|
|
|
},
|
|
|
+ getTimeRemaining() {
|
|
|
+ if (this.currentSong) {
|
|
|
+ return this.currentSong.duration * 1000 - this.getTimeElapsed();
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ },
|
|
|
playVideo() {
|
|
|
if (this.playerReady) {
|
|
|
this.videoLoading = true;
|
|
@@ -1185,18 +1294,17 @@ export default {
|
|
|
if (window.stationInterval !== 0)
|
|
|
clearInterval(window.stationInterval);
|
|
|
window.stationInterval = setInterval(() => {
|
|
|
- this.resizeSeekerbar();
|
|
|
- this.calculateTimeElapsed();
|
|
|
+ if (!this.stationPaused) {
|
|
|
+ this.resizeSeekerbar();
|
|
|
+ this.calculateTimeElapsed();
|
|
|
+ }
|
|
|
}, 150);
|
|
|
}
|
|
|
},
|
|
|
resizeSeekerbar() {
|
|
|
- if (!this.stationPaused) {
|
|
|
- this.seekerbarPercentage = parseFloat(
|
|
|
- (this.getTimeElapsed() / 1000 / this.currentSong.duration) *
|
|
|
- 100
|
|
|
- );
|
|
|
- }
|
|
|
+ this.seekerbarPercentage = parseFloat(
|
|
|
+ (this.getTimeElapsed() / 1000 / this.currentSong.duration) * 100
|
|
|
+ );
|
|
|
},
|
|
|
calculateTimeElapsed() {
|
|
|
if (
|
|
@@ -1225,7 +1333,7 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!this.stationPaused && !this.localPaused) {
|
|
|
+ if (!this.stationPaused && !this.localPaused && this.playerReady) {
|
|
|
const timeElapsed = this.getTimeElapsed();
|
|
|
const currentPlayerTime =
|
|
|
Math.max(
|
|
@@ -1298,7 +1406,7 @@ export default {
|
|
|
|
|
|
const songDuration = this.currentSong.duration;
|
|
|
if (songDuration <= duration) this.player.pauseVideo();
|
|
|
- if (!this.stationPaused && duration <= songDuration)
|
|
|
+ if (duration <= songDuration)
|
|
|
this.timeElapsed = utils.formatTime(duration);
|
|
|
},
|
|
|
toggleLock() {
|
|
@@ -1560,53 +1668,16 @@ export default {
|
|
|
|
|
|
document.body.style.cssText = `--primary-color: var(--${res.data.theme})`;
|
|
|
|
|
|
- const currentSong = res.data.currentSong
|
|
|
- ? res.data.currentSong
|
|
|
- : {};
|
|
|
-
|
|
|
- this.updateCurrentSong(currentSong);
|
|
|
+ this.setCurrentSong({
|
|
|
+ currentSong: res.data.currentSong,
|
|
|
+ startedAt: res.data.startedAt,
|
|
|
+ paused: res.data.paused,
|
|
|
+ timePaused: res.data.timePaused,
|
|
|
+ pausedAt: res.data.pausedAt
|
|
|
+ });
|
|
|
|
|
|
- this.startedAt = res.data.startedAt;
|
|
|
- this.updateStationPaused(res.data.paused);
|
|
|
- this.timePaused = res.data.timePaused;
|
|
|
this.updateUserCount(res.data.userCount);
|
|
|
this.updateUsers(res.data.users);
|
|
|
- this.pausedAt = res.data.pausedAt;
|
|
|
-
|
|
|
- if (res.data.currentSong) {
|
|
|
- this.updateNoSong(false);
|
|
|
- this.youtubeReady();
|
|
|
- this.playVideo();
|
|
|
- this.socket.dispatch(
|
|
|
- "songs.getOwnSongRatings",
|
|
|
- res.data.currentSong.youtubeId,
|
|
|
- res => {
|
|
|
- if (
|
|
|
- res.status === "success" &&
|
|
|
- this.currentSong.youtubeId ===
|
|
|
- res.data.youtubeId
|
|
|
- ) {
|
|
|
- this.liked = res.data.liked;
|
|
|
- this.disliked = res.data.disliked;
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- } else {
|
|
|
- if (this.playerReady) this.player.pauseVideo();
|
|
|
- this.updateNoSong(true);
|
|
|
- }
|
|
|
-
|
|
|
- this.socket.dispatch(
|
|
|
- "stations.getStationIncludedPlaylistsById",
|
|
|
- this.station._id,
|
|
|
- res => {
|
|
|
- if (res.status === "success") {
|
|
|
- this.setIncludedPlaylists(
|
|
|
- res.data.playlists
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
|
|
|
this.socket.dispatch(
|
|
|
"stations.getStationExcludedPlaylistsById",
|
|
@@ -1629,7 +1700,7 @@ export default {
|
|
|
? this.songsList[0]
|
|
|
: null;
|
|
|
}
|
|
|
- this.updateNextSong(nextSong);
|
|
|
+ this.setNextSong(nextSong);
|
|
|
}
|
|
|
});
|
|
|
|