|
@@ -1,17 +1,18 @@
|
|
|
-import { API_ROUTES, buildURI } from '../functions'
|
|
|
+import Vue from 'vue'
|
|
|
+import { API_ROUTES, buildURI, buildWsURI } from '../functions'
|
|
|
|
|
|
export default {
|
|
|
resetApp({ commit }, { hostConfig = false, progression = false }) {
|
|
|
commit('resetApp', { hostConfig, progression })
|
|
|
},
|
|
|
|
|
|
- async setHostConfig({ commit }, { protocol, host, port }) {
|
|
|
+ async setHostConfig({ commit }, { ssl, host, port }) {
|
|
|
// Timeout after 1s
|
|
|
const controller = new AbortController()
|
|
|
const signal = controller.signal
|
|
|
setTimeout(() => controller.abort(), 1500)
|
|
|
|
|
|
- const URI = buildURI(protocol, host, port, API_ROUTES.ping())
|
|
|
+ const URI = buildURI(ssl, host, port, API_ROUTES.ping())
|
|
|
return fetch(URI, { signal })
|
|
|
.then(async res => {
|
|
|
if (res.status !== 200) throw new Error(`Received wrong HTTP status code : ${res.status} (Need 200).`)
|
|
@@ -19,8 +20,10 @@ export default {
|
|
|
const content = await res.text()
|
|
|
if (content !== 'pong') throw new Error('Received wrong web content (Need to receive "pong").')
|
|
|
|
|
|
+ this._vm.$connect(buildWsURI(ssl, host, port))
|
|
|
+
|
|
|
// Configuration is valid
|
|
|
- commit('setHostConfig', { protocol, host, port })
|
|
|
+ commit('setHostConfig', { ssl, host, port })
|
|
|
})
|
|
|
.catch(err => {
|
|
|
// Host not reachable or invalid HTTP status code
|
|
@@ -28,6 +31,18 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ async connectToWs({ state, getters }) {
|
|
|
+ if (state.socket.isConnected) return /*eslint-disable-line */
|
|
|
+ else if (getters.isHostConfigured) {
|
|
|
+ this._vm.$connect(getters.getHostWsURI)
|
|
|
+ }
|
|
|
+ else throw new Error('Could not connect to WebSocket server. Host is not configured.')
|
|
|
+ },
|
|
|
+
|
|
|
+ sendMessage(_, message) {
|
|
|
+ Vue.prototype.$socket.send(JSON.stringify(message) || message)
|
|
|
+ },
|
|
|
+
|
|
|
async loadScenesList({ getters: { isHostConfigured, getHostURI }, commit }) {
|
|
|
if (!isHostConfigured) throw new Error('Host is not configured.')
|
|
|
|