|
67 | 67 | import Navigation from '../core/Navigation'; |
68 | 68 | import ProgressBar from './components/ProgressBar'; |
69 | 69 | import {mapState} from 'vuex'; |
70 | | -
|
| 70 | + import { mapState } from 'vuex'; |
| 71 | + import VueSocketio from 'vue-socket.io-extended'; |
71 | 72 | import io from 'socket.io-client'; |
| 73 | + import Vue from 'vue'; |
| 74 | +
|
| 75 | + import PowerButtons from './components/PowerButtons'; |
72 | 76 |
|
73 | 77 | export default { |
74 | 78 | components: { |
75 | | - ProgressBar, Navigation, TerminalIcon, FolderIcon, UsersIcon, |
76 | | - CalendarIcon, DatabaseIcon, GlobeIcon, SettingsIcon |
| 79 | + PowerButtons, ProgressBar, Navigation, |
| 80 | + TerminalIcon, FolderIcon, UsersIcon, CalendarIcon, DatabaseIcon, GlobeIcon, SettingsIcon |
77 | 81 | }, |
78 | 82 |
|
79 | 83 | computed: { |
80 | 84 | ...mapState('server', ['server', 'credentials']), |
| 85 | + ...mapState('socket', ['connected', 'connectionError']), |
81 | 86 | }, |
82 | 87 |
|
83 | 88 | mounted: function () { |
84 | 89 | this.loadServer(); |
85 | | -
|
86 | | - this.$on('send-command', data => { |
87 | | - this.socket.emit('send command', data); |
88 | | - }); |
89 | | -
|
90 | | - this.$on('send-initial-log', () => { |
91 | | - this.socket.emit('send server log'); |
92 | | - }) |
93 | 90 | }, |
94 | 91 |
|
95 | 92 | data: function () { |
96 | 93 | return { |
97 | | - socket: null, |
98 | 94 | loadingServerData: true, |
99 | 95 | }; |
100 | 96 | }, |
|
109 | 105 | this.$store.dispatch('server/getCredentials', {server: this.$route.params.id}) |
110 | 106 | ]) |
111 | 107 | .then(() => { |
| 108 | + // Configure the socket.io implementation. This is a really ghetto way of handling things |
| 109 | + // but all of these plugins assume you have some constant connection, which we don't. |
| 110 | + const socket = io(`${this.credentials.node}/v1/ws/${this.server.uuid}`, { |
| 111 | + query: `token=${this.credentials.key}`, |
| 112 | + }); |
| 113 | +
|
| 114 | + Vue.use(VueSocketio, socket, { store: this.$store }); |
112 | 115 | this.loadingServerData = false; |
113 | | - this.initalizeWebsocket(); |
114 | 116 | }) |
115 | 117 | .catch(console.error); |
116 | 118 | }, |
117 | | -
|
118 | | - initalizeWebsocket: function () { |
119 | | - this.socket = io(this.credentials.node + '/v1/ws/' + this.server.uuid, { |
120 | | - query: 'token=' + this.credentials.key, |
121 | | - }); |
122 | | -
|
123 | | - this.socket.on('error', this._socket_error); |
124 | | - this.socket.on('connect', this._socket_connect); |
125 | | - this.socket.on('status', this._socket_status); |
126 | | - this.socket.on('initial status', this._socket_status); |
127 | | - this.socket.on('server log', this._socket_serverLog); |
128 | | - this.socket.on('console', this._socket_consoleLine); |
129 | | - }, |
130 | | -
|
131 | | - _socket_error: function (err) { |
132 | | - this.$emit('socket::error', {err}); |
133 | | - }, |
134 | | -
|
135 | | - _socket_connect: function () { |
136 | | - this.$emit('socket::connected'); |
137 | | - }, |
138 | | -
|
139 | | - _socket_status: function (data) { |
140 | | - this.$emit('socket::status', {data}); |
141 | | - }, |
142 | | -
|
143 | | - _socket_serverLog: function (data) { |
144 | | - data.split(/\n/g).forEach(item => { |
145 | | - this.$emit('console', item); |
146 | | - }); |
147 | | - }, |
148 | | -
|
149 | | - _socket_consoleLine: function (data) { |
150 | | - if(data.line) { |
151 | | - data.line.split(/\n/g).forEach(item => { |
152 | | - this.$emit('console', item); |
153 | | - }); |
154 | | - } |
155 | | - }, |
156 | 119 | }, |
157 | 120 | } |
158 | 121 | </script> |
0 commit comments