|
@@ -5,28 +5,48 @@ import PropTypes from "prop-types";
|
|
import { translate, Trans } from "react-i18next";
|
|
import { translate, Trans } from "react-i18next";
|
|
|
|
|
|
import Player from "./Player";
|
|
import Player from "./Player";
|
|
-import Time from "./Time";
|
|
|
|
import Seekerbar from "./Seekerbar";
|
|
import Seekerbar from "./Seekerbar";
|
|
import VolumeSlider from "./VolumeSlider";
|
|
import VolumeSlider from "./VolumeSlider";
|
|
|
|
|
|
import { changeVolume } from "actions/volume";
|
|
import { changeVolume } from "actions/volume";
|
|
|
|
+import { changeSong, setTimeElapsed, timePaused } from "actions/songPlayer";
|
|
|
|
+import { pauseStation, resumeStation } from "actions/station";
|
|
|
|
|
|
import { connect } from "react-redux";
|
|
import { connect } from "react-redux";
|
|
|
|
|
|
import io from "io";
|
|
import io from "io";
|
|
import config from "config";
|
|
import config from "config";
|
|
|
|
+import {updateTimePaused} from "../../actions/songPlayer";
|
|
|
|
|
|
const Aux = (props) => {
|
|
const Aux = (props) => {
|
|
return props.children;
|
|
return props.children;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+const formatTime = (duration) => {
|
|
|
|
+ let d = moment.duration(duration, "seconds");
|
|
|
|
+ if (duration < 0) return "0:00";
|
|
|
|
+ return ((d.hours() > 0) ? (d.hours() < 10 ? ("0" + d.hours() + ":") : (d.hours() + ":")) : "") + (d.minutes() + ":") + (d.seconds() < 10 ? ("0" + d.seconds()) : d.seconds());
|
|
|
|
+};
|
|
|
|
+
|
|
@connect(state => ({
|
|
@connect(state => ({
|
|
user: {
|
|
user: {
|
|
userId: state.user.get("userId"),
|
|
userId: state.user.get("userId"),
|
|
role: state.user.get("role"),
|
|
role: state.user.get("role"),
|
|
},
|
|
},
|
|
loggedIn: state.user.get("loggedIn"),
|
|
loggedIn: state.user.get("loggedIn"),
|
|
- volume: state.volume.get("volume"),
|
|
|
|
|
|
+ songTitle: state.songPlayer.get("title"),
|
|
|
|
+ songDuration: state.songPlayer.get("duration"),
|
|
|
|
+ songTimeElapsed: state.songPlayer.get("timeElapsed"),
|
|
|
|
+ songArtists: state.songPlayer.get("artists"),
|
|
|
|
+ simpleSong: state.songPlayer.get("simple"),
|
|
|
|
+ songExists: state.songPlayer.get("exists"),
|
|
|
|
+ station: {
|
|
|
|
+ stationId: state.station.get("id"),
|
|
|
|
+ name: state.station.get("name"),
|
|
|
|
+ displayName: state.station.get("displayName"),
|
|
|
|
+ paused: state.station.get("paused"),
|
|
|
|
+ pausedAt: state.station.get("pausedAt"),
|
|
|
|
+ },
|
|
}))
|
|
}))
|
|
|
|
|
|
@translate(["station"], { wait: true })
|
|
@translate(["station"], { wait: true })
|
|
@@ -39,88 +59,46 @@ export default class Station extends Component {
|
|
t: () => {},
|
|
t: () => {},
|
|
};
|
|
};
|
|
|
|
|
|
- constructor() {
|
|
|
|
|
|
+ constructor(props) {
|
|
super();
|
|
super();
|
|
|
|
|
|
- let temp = window.props;
|
|
|
|
- let stationName = temp.stationName;
|
|
|
|
-
|
|
|
|
- this.state = {
|
|
|
|
- station: temp.stationData,
|
|
|
|
- currentSongExists: false,
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
io.getSocket(socket => {
|
|
io.getSocket(socket => {
|
|
- socket.emit("stations.join", stationName, res => {
|
|
|
|
|
|
+ socket.emit("stations.join", props.station.name, res => {
|
|
console.log(res);
|
|
console.log(res);
|
|
if (res.status === 'success') {
|
|
if (res.status === 'success') {
|
|
- this.setState({
|
|
|
|
- station: { //TODO Refactor this to be better optimized
|
|
|
|
- _id: res.data._id,
|
|
|
|
- name: stationName,
|
|
|
|
- displayName: res.data.displayName,
|
|
|
|
- description: res.data.description,
|
|
|
|
- privacy: res.data.privacy,
|
|
|
|
- locked: res.data.locked,
|
|
|
|
- partyMode: res.data.partyMode,
|
|
|
|
- owner: res.data.owner,
|
|
|
|
- privatePlaylist: res.data.privatePlaylist,
|
|
|
|
- type: res.data.type,
|
|
|
|
- paused: res.data.paused,
|
|
|
|
- },
|
|
|
|
- currentSong: (res.data.currentSong) ? res.data.currentSong : {},
|
|
|
|
- currentSongExists: !!res.data.currentSong,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- if (res.data.paused) this.player.pause(); //TODO Add async getPlayer here
|
|
|
|
- else this.player.resume();
|
|
|
|
-
|
|
|
|
if (res.data.currentSong) {
|
|
if (res.data.currentSong) {
|
|
res.data.currentSong.startedAt = res.data.startedAt;
|
|
res.data.currentSong.startedAt = res.data.startedAt;
|
|
res.data.currentSong.timePaused = res.data.timePaused;
|
|
res.data.currentSong.timePaused = res.data.timePaused;
|
|
}
|
|
}
|
|
- this.changeSong(res.data.currentSong);
|
|
|
|
|
|
+ this.props.dispatch(changeSong(res.data.currentSong));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ socket.on('event:songs.next', data => {
|
|
|
|
+ if (data.currentSong) {
|
|
|
|
+ data.currentSong.startedAt = res.data.startedAt;
|
|
|
|
+ data.currentSong.timePaused = res.data.timePaused;
|
|
|
|
+ }
|
|
|
|
+ this.props.dispatch(changeSong(data.currentSong));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ socket.on('event:stations.pause', pausedAt => {
|
|
|
|
+ this.props.dispatch(pauseStation(pausedAt));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ socket.on('event:stations.resume', data => {
|
|
|
|
+ this.props.dispatch(updateTimePaused(data.timePaused));
|
|
|
|
+ this.props.dispatch(resumeStation());
|
|
|
|
+ });
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
setInterval(() => {
|
|
setInterval(() => {
|
|
- if (this.state.currentSongExists) {
|
|
|
|
- this.time.setTime(this.player.getTimeElapsed() / 1000);
|
|
|
|
- this.seekerbar.setTimeElapsed(this.player.getTimeElapsed() / 1000);
|
|
|
|
|
|
+ if (this.props.songExists) {
|
|
|
|
+ this.props.dispatch(setTimeElapsed(this.props.station.paused, this.props.station.pausedAt)); // TODO Fix
|
|
}
|
|
}
|
|
}, 1000);
|
|
}, 1000);
|
|
}
|
|
}
|
|
|
|
|
|
- changeSong = (newSongObject) => {
|
|
|
|
- let currentSongExists = !!newSongObject;
|
|
|
|
- let state = {
|
|
|
|
- currentSongExists,
|
|
|
|
- currentSong: newSongObject,
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- if (currentSongExists) {
|
|
|
|
- state.timeTotal = Time.formatTime(newSongObject.duration);
|
|
|
|
- state.simpleSong = (newSongObject.likes === -1 && newSongObject.dislikes === -1);
|
|
|
|
- if (state.simpleSong) {
|
|
|
|
- state.currentSong.skipDuration = 0;
|
|
|
|
- newSongObject.skipDuration = 0;// Do this better
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.seekerbar.setTime(newSongObject.duration);
|
|
|
|
-
|
|
|
|
- this.player.playSong(newSongObject.songId, newSongObject.skipDuration, newSongObject.timePaused, newSongObject.startedAt, () => {
|
|
|
|
- this.seekerbar.setTimeElapsed(this.player.getTimeElapsed() / 1000);
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- this.player.clearSong();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.setState(state, () => {
|
|
|
|
- this.getOwnRatings();
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
getOwnRatings = () => {
|
|
getOwnRatings = () => {
|
|
io.getSocket((socket) => {
|
|
io.getSocket((socket) => {
|
|
if (!this.state.currentSongExists) return;
|
|
if (!this.state.currentSongExists) return;
|
|
@@ -147,20 +125,28 @@ export default class Station extends Component {
|
|
return false;
|
|
return false;
|
|
};
|
|
};
|
|
|
|
|
|
- changeId = () => {
|
|
|
|
- this.player.playSong("jbZXYhjh3ms", 0, 0, Date.now());
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
addSongTemp = () => {
|
|
addSongTemp = () => {
|
|
io.getSocket(socket => {
|
|
io.getSocket(socket => {
|
|
- socket.emit('stations.addToQueue', this.state.station._id, '60ItHLz5WEA', data => {
|
|
|
|
|
|
+ socket.emit('stations.addToQueue', this.props.station.stationId, '60ItHLz5WEA', data => {
|
|
console.log("ATQ Res", data);
|
|
console.log("ATQ Res", data);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
- changeVolume = () => {
|
|
|
|
- this.props.dispatch(changeVolume(32))
|
|
|
|
|
|
+ resumeStation = () => {
|
|
|
|
+ io.getSocket(socket => {
|
|
|
|
+ socket.emit('stations.resume', this.props.station.stationId, data => {
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ pauseStation = () => {
|
|
|
|
+ io.getSocket(socket => {
|
|
|
|
+ socket.emit('stations.pause', this.props.station.stationId, data => {
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ });
|
|
};
|
|
};
|
|
|
|
|
|
render() {
|
|
render() {
|
|
@@ -170,38 +156,36 @@ export default class Station extends Component {
|
|
|
|
|
|
return (
|
|
return (
|
|
<main id="station">
|
|
<main id="station">
|
|
- <h1>{ this.state.station.displayName }</h1>
|
|
|
|
-
|
|
|
|
|
|
+ <h1>{ this.props.station.displayName }</h1>
|
|
|
|
|
|
- <button onClick={ this.changeVolume }>Change volume</button>
|
|
|
|
|
|
+ { (this.props.station.paused) ? <button onClick={ this.resumeStation }>Resume</button> : <button onClick={ this.pauseStation }>Pause</button>}
|
|
|
|
|
|
- <button onClick={ this.changeId }>Change ID</button>
|
|
|
|
- <button onClick={ () => { this.player.pause() } }>Pause</button>
|
|
|
|
- <button onClick={ () => { this.player.resume() } }>Resume</button>
|
|
|
|
|
|
+ <button onClick={ this.addSongTemp }>Add song to queue TEMP</button>
|
|
|
|
|
|
- <div className={(!this.state.currentSongExists) ? "hidden" : ""}>
|
|
|
|
|
|
+ <hr/>
|
|
|
|
+ <div className={(!this.props.songExists) ? "hidden" : ""}>
|
|
<Player onRef={ ref => (this.player = ref) }/>
|
|
<Player onRef={ ref => (this.player = ref) }/>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
- { (this.state.currentSongExists) ? (
|
|
|
|
|
|
+ { (this.props.songExists) ? (
|
|
[
|
|
[
|
|
- <span key="title">{ this.state.currentSong.title }</span>,
|
|
|
|
- <br key="br1"/>,
|
|
|
|
- <span key="artists">{ this.state.currentSong.artists.join(", ") }</span>,
|
|
|
|
- <span key="time">
|
|
|
|
- <Time onRef={ ref => (this.time = ref) }/> - { Time.formatTime(this.state.currentSong.duration) }
|
|
|
|
- </span>,
|
|
|
|
- <div key="seekerbar" className="seekerbar-container" style={{"width": "100%", "background-color": "yellow", "height": "20px", "display": "block"}}>
|
|
|
|
- <Seekerbar onRef={ ref => (this.seekerbar = ref) }/>
|
|
|
|
|
|
+ <div key="content">
|
|
|
|
+ <h1>Title: { this.props.songTitle }</h1>
|
|
|
|
+ <br/>
|
|
|
|
+ Paused: { (this.props.station.paused) ? "true" : "false" }
|
|
|
|
+ <br/>
|
|
|
|
+ <span>Artists: { this.props.songArtists.join(", ") }</span>
|
|
|
|
+ <span key="time">
|
|
|
|
+ { formatTime(this.props.songTimeElapsed) } - { formatTime(this.props.songDuration) }
|
|
|
|
+ </span>
|
|
|
|
+ <div key="seekerbar" className="seekerbar-container" style={{"width": "100%", "background-color": "yellow", "height": "20px", "display": "block"}}>
|
|
|
|
+ <Seekerbar/>
|
|
|
|
+ </div>
|
|
|
|
+ <VolumeSlider key="volumeSlider"/>
|
|
</div>,
|
|
</div>,
|
|
]) : (
|
|
]) : (
|
|
<h1>No song playing</h1>
|
|
<h1>No song playing</h1>
|
|
) }
|
|
) }
|
|
-
|
|
|
|
-
|
|
|
|
- <VolumeSlider key="volumeSlider"/>,
|
|
|
|
-
|
|
|
|
- <button onClick={ this.addSongTemp }>Add song to queue TEMP</button>
|
|
|
|
</main>
|
|
</main>
|
|
);
|
|
);
|
|
}
|
|
}
|