Browse Source

refactor: extract websocket and path based on axios baseurl

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

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

@ -13,8 +13,12 @@ export default function({
if (socket) { if (socket) {
socket.disconnect() socket.disconnect()
} }
const isUrl = $axios.defaults.baseURL.startsWith('http')
const url = isUrl ? $axios.defaults.baseURL : window.location.href.split(/[?#]/)[0]
const path = isUrl ? undefined : $axios.defaults.baseURL
socket = io($axios.defaults.baseURL, { socket = io(url, {
path,
extraHeaders: { 'xc-auth': token } extraHeaders: { 'xc-auth': token }
}) })
@ -81,7 +85,9 @@ export default function({
}) })
store.watch(state => state.project.projectInfo && state.project.projectInfo.teleEnabled && state.users.token, (token) => { store.watch(state => state.project.projectInfo && state.project.projectInfo.teleEnabled && state.users.token, (token) => {
if (token) { init(token) } else if (socket) { if (token) {
init(token)
} else if (socket) {
socket.disconnect() socket.disconnect()
socket = null socket = null
} }

Loading…
Cancel
Save