From 70dd1cbeb154ca308728d3d50a7e8c451d227024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Mon, 18 Nov 2019 17:30:26 +0100 Subject: [PATCH] Player? --- frontend/components/player/Player.vue | 42 ++++++ frontend/components/player/SoundCloud.vue | 3 + frontend/components/player/YouTube.vue | 166 ++++++++++++++++++++++ frontend/mixins/Socket.js | 81 +++++++++++ 4 files changed, 292 insertions(+) create mode 100644 frontend/components/player/Player.vue create mode 100644 frontend/components/player/SoundCloud.vue create mode 100644 frontend/components/player/YouTube.vue create mode 100644 frontend/mixins/Socket.js diff --git a/frontend/components/player/Player.vue b/frontend/components/player/Player.vue new file mode 100644 index 00000000..c8c51045 --- /dev/null +++ b/frontend/components/player/Player.vue @@ -0,0 +1,42 @@ + + + + + + \ No newline at end of file diff --git a/frontend/components/player/SoundCloud.vue b/frontend/components/player/SoundCloud.vue new file mode 100644 index 00000000..6c578299 --- /dev/null +++ b/frontend/components/player/SoundCloud.vue @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/frontend/components/player/YouTube.vue b/frontend/components/player/YouTube.vue new file mode 100644 index 00000000..5e93a6a0 --- /dev/null +++ b/frontend/components/player/YouTube.vue @@ -0,0 +1,166 @@ + + + + + \ No newline at end of file diff --git a/frontend/mixins/Socket.js b/frontend/mixins/Socket.js new file mode 100644 index 00000000..c75016d0 --- /dev/null +++ b/frontend/mixins/Socket.js @@ -0,0 +1,81 @@ +import store from "@/store"; +import io from "socket.io-client"; + +export default { + data() { + return { + socket: null, + alreadyCreated: false + }; + }, + created() { + if (this.alreadyCreated) { + console.log("we already exist"); + return; + } + this.socket = io("localhost:8080"); + console.log("mounted"); + this.addListeners(); + this.alreadyCreated = true; + }, + computed: { + nowPlaying: function() { + return store.getters["playerModule/nowPlaying"]; + }, + channel: function() { + return store.getters["playerModule/channel"]; + } + }, + methods: { + emitToBackend(event, msg) { + this.socket.emit(event, msg); + }, + songEnd() { + this.socket.emit("end", { id: this.nowPlaying, channel: this.channel }); + }, + getPosition() { + this.socket.emit("pos", { channel: this.channel }); + }, + addListeners() { + this.socket.on("channel", msg => { + console.log("list", msg); + if (msg.type == "list") { + store.dispatch("playerModule/setPlaylist", msg.playlist); + } + }); + + this.socket.on("conf", msg => { + console.log("conf", msg); + if (msg.length == 1) { + store.dispatch("playerModule/setChannelSettings", msg[0]); + } + }); + this.socket.on("np", msg => { + if (msg.np.length == 0) { + return; + } + if (msg.conf.length == 0) { + return; + } + let nowPlaying = msg.np[0]; + let channelSettings = msg.conf[0]; + let timeSinceStart = + msg.time - channelSettings.startTime + nowPlaying.start; + nowPlaying.seek = timeSinceStart; + + store.dispatch("playerModule/setNowPlaying", nowPlaying); + store.dispatch("playerModule/setChannelSettings", channelSettings); + }); + + this.socket.on("update_required", msg => { + console.log("update required"); + }); + this.socket.on("connect", msg => { + this.socket.emit("list", { + version: 6, + channel: this.channel + }); + }); + } + } +};