From 6a40a8d2414d228d99c3f62ace2d59c5377aee8d Mon Sep 17 00:00:00 2001 From: MagicalCodeMonkey Date: Wed, 11 Mar 2020 11:08:33 -0400 Subject: [PATCH] Updates servers handling - Allow users to override the custom server entry - Allow users to set their own servers - Update some styling If the user sets a their own server list, it will ignore the customServer setting --- SettingsHelper.js | 4 ++ example_settings.json | 4 +- src/App.vue | 63 +++++++++++++++++++++++ src/components/application/joinroom.vue | 67 +++++++++++-------------- 4 files changed, 100 insertions(+), 38 deletions(-) diff --git a/SettingsHelper.js b/SettingsHelper.js index aa06bbb2..452fb8bb 100644 --- a/SettingsHelper.js +++ b/SettingsHelper.js @@ -10,6 +10,8 @@ const defaults = { autoJoinServer: '', autoJoinRoom: '', autoJoinPassword: '', + servers: '', + customServer: '', }; module.exports = function () { @@ -21,6 +23,8 @@ module.exports = function () { 'autoJoinServer', 'autoJoinRoom', 'autoJoinPassword', + 'servers', + 'customServer', ]; // Load and export our settings in preference of ENV -> args const output = {}; diff --git a/example_settings.json b/example_settings.json index 83ed2df2..90b3a91e 100644 --- a/example_settings.json +++ b/example_settings.json @@ -5,5 +5,7 @@ "autoJoin": false, "autoJoinServer": "", "autoJoinRoom": "", - "autoJoinPassword": "" + "autoJoinPassword": "", + "servers": "", + "customServer": "" } \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 802f9c7f..13666c5a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -189,6 +189,69 @@ export default { } } + let servers = [ + { + location: 'Sydney, Australia', + text: 'SyncLounge AU1', + value: 'https://v2au1.synclounge.tv/server', + flag: 'flags/aus.png', + }, + { + location: 'Amsterdam, Netherlands', + text: 'SyncLounge EU1', + value: 'https://v2eu1.synclounge.tv/server', + flag: 'flags/eu.png', + }, + { + location: 'Miami, United States', + text: 'SyncLounge US1', + value: 'https://v2us1.synclounge.tv/server', + flag: 'flags/usa.png', + }, + ]; + let customServer = { + location: 'Anywhere!', + text: 'Custom Server', + value: 'custom', + flag: 'synclounge-white.png', + } + + if (this.config && this.config.servers) { + servers = this.config.servers + if(this.config.customServer) { + console.error(`'customServer' setting provided with 'servers' setting. Ignoring 'customServer' setting.`); + } + } + else if (settings && settings.servers) { + servers = settings.servers; + if(settings.customServer) { + console.error(`'customServer' setting provided with 'servers' setting. Ignoring 'customServer' setting.`); + } + } + else if (this.config && this.config.customServer) { + servers.push(this.config.customServer); + } + else if (this.config && this.settings.customServer) { + servers.push(this.settings.customServer); + } + else { + servers.push(customServer); + } + + this.$store.commit('setSetting', ['SERVERS', servers]); + + if (servers.length == 1 && !this.$store.autoJoinServer) { + let server = servers[0]; + this.$store.commit('SET_AUTOJOIN', true); + this.$store.commit('SET_AUTOJOINURL', server.value); + if(!this.$store.autoJoinRoom && server.defaultRoom) { + this.$store.commit('SET_AUTOJOINROOM', server.defaultRoom); + } + if(!this.$store.autoJoinPassword && server.defaultPassword) { + this.$store.commit('SET_AUTOJOINPASSWORD', server.defaultPassword); + } + } + window.EventBus.$on('notification', (msg) => { this.snackbarMsg = msg; this.snackbar = true; diff --git a/src/components/application/joinroom.vue b/src/components/application/joinroom.vue index af65b81c..d1faeeb4 100644 --- a/src/components/application/joinroom.vue +++ b/src/components/application/joinroom.vue @@ -52,11 +52,11 @@ Select a server - + - +

{{ server.text }}

@@ -82,13 +82,13 @@
- + Connect @@ -168,34 +168,7 @@ export default { results: {}, - destroyed: false, - - ptservers: [ - { - location: 'Sydney, Australia', - text: 'SyncLounge AU1', - value: 'https://v2au1.synclounge.tv/server', - flag: 'flags/aus.png', - }, - { - location: 'Amsterdam, Netherlands', - text: 'SyncLounge EU1', - value: 'https://v2eu1.synclounge.tv/server', - flag: 'flags/eu.png', - }, - { - location: 'Miami, United States', - text: 'SyncLounge US1', - value: 'https://v2us1.synclounge.tv/server', - flag: 'flags/usa.png', - }, - { - location: 'Anywhere!', - text: 'Custom Server', - value: 'custom', - flag: 'synclounge-white.png', - }, - ], + destroyed: false }; }, mounted() { @@ -253,8 +226,15 @@ export default { return ['white--text']; }, serverSelected(server) { - this.selectedServer = server.value; - if (this.selectedServer !== 'custom') { + this.selectedServer = server; + if(this.selectedServer.defaultRoom) { + this.room = this.selectedServer.defaultRoom; + + if(this.selectedServer.defaultPassword) { + this.password = this.selectedServer.defaultPassword; + } + } + if (this.selectedServer.value !== 'custom') { this.attemptConnect(); } }, @@ -284,12 +264,17 @@ export default { // Attempt the connection return new Promise((resolve, reject) => { this.serverError = null; - if (this.selectedServer !== 'custom') { + if (this.selectedServer.value !== 'custom') { this.connectionPending = true; - this.$store.dispatch('socketConnect', { address: this.selectedServer }) + this.$store.dispatch('socketConnect', { address: this.selectedServer.value }) .then((result) => { this.connectionPending = false; if (result) { + if(this.room) { + this.joinRoom().then(() => { + }).catch((e) => { + }); + } resolve(); } else { this.serverError = null; @@ -298,7 +283,7 @@ export default { }) .catch((e) => { this.connectionPending = false; - this.serverError = `Failed to connect to ${this.selectedServer}`; + this.serverError = `Failed to connect to ${this.selectedServer.value}`; reject(e); }); } else { @@ -403,6 +388,14 @@ export default { this.$store.commit('setSetting', ['CUSTOMSERVER', value]); }, }, + ptservers() { + return this.$store.getters.getSettings.SERVERS; + }, + ptserversClass() { + let serversCount = this.$store.getters.getSettings.SERVERS.length; + let classNum = 12/serversCount; + return `md${classNum}`; + }, }, };