housekeeping, reconnect on ws break, change server

main v1.5.0
Ayush Mukherjee 4 years ago
parent 5c08c32c92
commit 9254b3b69c

@ -1,6 +1,6 @@
{ {
"name": "slapdash", "name": "slapdash",
"version": "1.4.0", "version": "1.5.0",
"author": "Ayush Mukherjee", "author": "Ayush Mukherjee",
"description": "Dashboard for APL-Nuke cum APL-Boost data manager", "description": "Dashboard for APL-Nuke cum APL-Boost data manager",
"private": false, "private": false,

@ -40,7 +40,7 @@
<table v-if="e.hosts"> <table v-if="e.hosts">
<tbody> <tbody>
<tr v-for="p in e.hosts" :key="p"> <tr v-for="p in e.hosts" :key="p">
<td>{{ store.state.hosts.filter(x => x._id === p)[0]?.name }}</td> <td>{{ store.state.casters.filter(x => x._id === p)[0]?.name }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -70,7 +70,7 @@
<button @click.prevent="addCaster()" class="block w-64 h-10 my-4 text-white bg-red-700 rounded-lg hover:bg-red-600">Add caster</button> <button @click.prevent="addCaster()" class="block w-64 h-10 my-4 text-white bg-red-700 rounded-lg hover:bg-red-600">Add caster</button>
<p class="mt-4">Hosts</p> <p class="mt-4">Hosts</p>
<select v-for="(n, i) in hosts.length" :key="i" v-model="hosts[n - 1]" class="block my-4 border border-gray-500 rounded-lg bg-white w-64 h-8 px-4"> <select v-for="(n, i) in hosts.length" :key="i" v-model="hosts[n - 1]" class="block my-4 border border-gray-500 rounded-lg bg-white w-64 h-8 px-4">
<option v-for="r in store.state.hosts" :key="r._id" :value="r._id">{{ r.name }}</option> <option v-for="r in store.state.casters" :key="r._id" :value="r._id">{{ r.name }}</option>
</select> </select>
<button @click.prevent="addHost()" class="block w-64 h-10 my-4 text-white bg-red-700 rounded-lg hover:bg-red-600">Add host</button> <button @click.prevent="addHost()" class="block w-64 h-10 my-4 text-white bg-red-700 rounded-lg hover:bg-red-600">Add host</button>
<button class="block w-64 h-10 text-white bg-red-700 rounded-lg hover:bg-red-600">Submit</button> <button class="block w-64 h-10 text-white bg-red-700 rounded-lg hover:bg-red-600">Submit</button>

@ -4,6 +4,8 @@ import { handleMsg, sendSub } from './utils/websocket'
const token = window.localStorage.getItem('token') const token = window.localStorage.getItem('token')
const server = 'slap.aplesports.com:5000'
const state = reactive({ const state = reactive({
name: '', name: '',
token: token || '', token: token || '',
@ -22,10 +24,13 @@ const state = reactive({
server: false, server: false,
}) })
let interval = 0
const methods = { const methods = {
authenticate: async (token) => { authenticate: async (token) => {
state.session = null
window.localStorage.setItem('token', token) window.localStorage.setItem('token', token)
return axios.post('http://178.79.128.135:5000/api/v1', { return axios.post(`http://${server}/api/v1`, {
token, token,
}) })
.then((res) => { .then((res) => {
@ -35,14 +40,29 @@ const methods = {
return true return true
}) })
}, },
connect: (uri) => { connect: () => {
state.ws = new WebSocket(`ws://178.79.128.135:5000/ws/${state.session}`) if (state.session !== null) {
state.ws.onopen = () => { state.ws = new WebSocket(`ws://${server}/ws/${state.session}`)
sendSub(state.ws) state.ws.onopen = () => {
} clearInterval(interval)
state.ws.onmessage = (e) => { sendSub(state.ws)
const data = JSON.parse(e.data) state.ws.onclose = () => {
handleMsg(data) console.warn('Lost connection to nuke. Attempting to reconnect every 5 seconds...')
interval = setInterval(() => {
methods.authenticate(state.token)
.then(() => {
methods.connect()
})
.catch((_) => {
console.warn('Error reconnecting! Trying again')
})
}, 5000)
}
}
state.ws.onmessage = (e) => {
const data = JSON.parse(e.data)
handleMsg(data)
}
} }
} }
} }

@ -6,8 +6,8 @@
<p class="nav-item" @click="nav = 'events'" :class="nav === 'events' ? 'active' : ''">Events</p> <p class="nav-item" @click="nav = 'events'" :class="nav === 'events' ? 'active' : ''">Events</p>
<p class="nav-item" @click="nav = 'rosters'" :class="nav === 'rosters' ? 'active' : ''">Rosters</p> <p class="nav-item" @click="nav = 'rosters'" :class="nav === 'rosters' ? 'active' : ''">Rosters</p>
<p class="nav-item" @click="nav = 'matches'" :class="nav === 'matches' ? 'active' : ''">Matches</p> <p class="nav-item" @click="nav = 'matches'" :class="nav === 'matches' ? 'active' : ''">Matches</p>
<p class="nav-item" @click="nav = 'casters'" :class="nav === 'casters' ? 'active' : ''">Casters</p> <p class="nav-item" @click="nav = 'casters'" :class="nav === 'casters' ? 'active' : ''">Casters / Hosts</p>
<p class="nav-item" @click="nav = 'hosts'" :class="nav === 'hosts' ? 'active' : ''">Hosts</p> <!-- <p class="nav-item" @click="nav = 'hosts'" :class="nav === 'hosts' ? 'active' : ''">Hosts</p> -->
<p class="nav-item" @click="nav = 'streams'" :class="nav === 'streams' ? 'active' : ''">Streams</p> <p class="nav-item" @click="nav = 'streams'" :class="nav === 'streams' ? 'active' : ''">Streams</p>
<p class="nav-item" @click="nav = 'brackets'" :class="nav === 'brackets' ? 'active' : ''">Brackets</p> <p class="nav-item" @click="nav = 'brackets'" :class="nav === 'brackets' ? 'active' : ''">Brackets</p>
<img class="block w-16 h-16 absolute bottom-10" src="https://cms.aplesports.com/storage/uploads/2020/04/23/5ea178d6570e1APL_New.png" alt="APL Logo"> <img class="block w-16 h-16 absolute bottom-10" src="https://cms.aplesports.com/storage/uploads/2020/04/23/5ea178d6570e1APL_New.png" alt="APL Logo">
@ -32,7 +32,6 @@
<Rosters v-if="nav === 'rosters'" /> <Rosters v-if="nav === 'rosters'" />
<Matches v-if="nav === 'matches'" /> <Matches v-if="nav === 'matches'" />
<Casters v-if="nav === 'casters'" /> <Casters v-if="nav === 'casters'" />
<Hosts v-if="nav === 'hosts'" />
<Streams v-if="nav === 'streams'" /> <Streams v-if="nav === 'streams'" />
<Brackets v-if="nav === 'brackets'" /> <Brackets v-if="nav === 'brackets'" />
</div> </div>

Loading…
Cancel
Save