1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const CONNECTING_STATUS = ['IDLE', 'CONNECTING', 'WAITING']
|
12 | const TUNNEL_STATE = ['CONNECTING', 'CONNECTED', 'CLOSED']
|
13 | const CLIENT_STATE = ['IDLE', 'CONNECTING', 'WAITING', 'CONNECTED', 'DISCONNECTING', 'DISCONNECTED']
|
14 |
|
15 | import Vue from 'vue'
|
16 | import GuacErrors from './GuacErrors'
|
17 |
|
18 | export default {
|
19 | methods: {
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | initErrorHandlers () {
|
27 | this.tunnel.onerror = this.client.onerror = (error) => {
|
28 | this.disconnect()
|
29 | const guacError = GuacErrors.ERRORS[error.code]
|
30 | this.error = guacError ? guacError : {reconnect: false, message: `An unknown error occurred. Code ${error.code}`}
|
31 | }
|
32 | },
|
33 |
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | initStateChangeHandlers () {
|
41 | this.tunnel.onstatechange = (state) => {
|
42 | Vue.set(this.options, 'tunnelState', TUNNEL_STATE[state])
|
43 | }
|
44 |
|
45 |
|
46 | this.client.onstatechange = (clientState) => {
|
47 | Vue.set(this.options, 'clientState', CLIENT_STATE[clientState])
|
48 | this.$emit('clientStateChanged', CLIENT_STATE[clientState])
|
49 | }
|
50 | }
|
51 | },
|
52 | computed: {
|
53 |
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | status () {
|
61 | const options = this.options
|
62 | if (options.tunnelState === 'Not Connected' || options.clientState === 'Not Connected') return 'Not Connected'
|
63 |
|
64 | if (options.tunnelState === 'CLOSED') return 'Disconnected'
|
65 | if (options.tunnelState === 'CONNECTING') return 'Connecting'
|
66 |
|
67 | if (CONNECTING_STATUS.includes(options.clientState)) return 'Connecting'
|
68 | if (options.clientState === 'CONNECTED') return 'Connected'
|
69 | if (options.clientState === 'DISCONNECTING') return 'Disconnecting'
|
70 | if (options.clientState === 'DISCONNECTED') return 'Disconnected'
|
71 |
|
72 | return options.clientState
|
73 | }
|
74 | }
|
75 | }
|