File size: 1,249 Bytes
4d70170 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import io from 'socket.io-client'
import { initDevTools } from '@front'
import { Bridge } from '@vue-devtools/shared-utils'
const port = window.process.env.PORT || 8098
const socket = io(`http://localhost:${port}`)
const $ = document.querySelector.bind(document)
const $intro = $('#intro')
let reload = null
let introTimer
socket.on('vue-devtools-disconnect-devtools', () => {
introTimer = setTimeout(() => {
$intro.classList.remove('hidden')
}, 2000)
})
socket.on('vue-devtools-init', () => {
clearTimeout(introTimer)
$intro.classList.add('hidden')
// Reset attached listeners
socket.off('vue-message')
// If new page is opened reload devtools
if (reload) {
return reload()
}
initDevTools({
connect(callback) {
const wall = {
listen(fn) {
socket.on('vue-message', data => fn(data))
},
send(data) {
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.log('%cdevtools -> backend', 'color:#888;', data)
}
socket.emit('vue-message', data)
},
}
const bridge = new Bridge(wall)
callback(bridge)
},
onReload(fn) {
reload = fn
},
})
})
|