-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathdevtools.js
52 lines (44 loc) · 1.26 KB
/
devtools.js
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
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 host = window.process.env.HOST || 'localhost'
const socket = io(`http://${host}:${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
},
})
})