Browse Source

refactor: ignore socket event emit if undefined

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1668/head
Pranav C 3 years ago
parent
commit
55a19bdcab
  1. 12
      packages/nc-gui/plugins/tele.js

12
packages/nc-gui/plugins/tele.js

@ -9,7 +9,7 @@ export default function({
}, inject) {
let socket
const init = (token) => {
const init = async(token) => {
if (socket) {
socket.disconnect()
}
@ -30,7 +30,7 @@ export default function({
app.router.onReady(() => {
app.router.afterEach(function(to, from) {
if (socket || (to.path === from.path && (to.query && to.query.type) === (from.query && from.query.type))) {
if (!socket || (to.path === from.path && (to.query && to.query.type) === (from.query && from.query.type))) {
return
}
socket.emit('page', {
@ -38,10 +38,12 @@ export default function({
path: to.matched[0].path + (to.query && to.query.type ? `?type=${to.query.type}` : '')
})
})
if (socket) {
socket.emit('page', {
id: store.state.users.user && store.state.users.user.id,
path: route.matched[0].path + (route.query && route.query.type ? `?type=${route.query.type}` : '')
})
}
})
const tele = {
@ -61,11 +63,11 @@ export default function({
function getListener(binding) {
return function(e) {
if (!socket) { return }
const cat = window.location.hash.replace(/\d+\/(?=dashboard)/, '')
const event = binding.value && binding.value[0]
const data = binding.value && binding.value[1]
const extra = binding.value && binding.value.slice(2)
tele.emit(event,
{
cat,
@ -87,14 +89,14 @@ export default function({
store.watch(state => state.project.projectInfo && state.project.projectInfo.teleEnabled && state.users.token, (token) => {
if (token) {
init(token)
init(token).then(() => {})
} else if (socket) {
socket.disconnect()
socket = null
}
})
if (store.state.project.projectInfo && store.state.project.projectInfo.teleEnabled && store.state.users.token) {
init(store.state.users.token)
init(store.state.users.token).then(() => {})
}
}

Loading…
Cancel
Save