diff --git a/package.json b/package.json
index 56ca96b5c..9069d7a7e 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
"vue": "^2.5.7",
"vue-axios": "^2.1.1",
"vue-router": "^3.0.1",
+ "vue-socket.io-extended": "^3.1.0",
"vuex": "^3.0.1",
"vuex-i18n": "^1.10.5",
"vuex-router-sync": "^5.0.0",
diff --git a/resources/assets/scripts/components/server/Server.vue b/resources/assets/scripts/components/server/Server.vue
index 651a2fd59..b48297f6f 100644
--- a/resources/assets/scripts/components/server/Server.vue
+++ b/resources/assets/scripts/components/server/Server.vue
@@ -67,34 +67,30 @@
import Navigation from '../core/Navigation';
import ProgressBar from './components/ProgressBar';
import {mapState} from 'vuex';
-
+ import { mapState } from 'vuex';
+ import VueSocketio from 'vue-socket.io-extended';
import io from 'socket.io-client';
+ import Vue from 'vue';
+
+ import PowerButtons from './components/PowerButtons';
export default {
components: {
- ProgressBar, Navigation, TerminalIcon, FolderIcon, UsersIcon,
- CalendarIcon, DatabaseIcon, GlobeIcon, SettingsIcon
+ PowerButtons, ProgressBar, Navigation,
+ TerminalIcon, FolderIcon, UsersIcon, CalendarIcon, DatabaseIcon, GlobeIcon, SettingsIcon
},
computed: {
...mapState('server', ['server', 'credentials']),
+ ...mapState('socket', ['connected', 'connectionError']),
},
mounted: function () {
this.loadServer();
-
- this.$on('send-command', data => {
- this.socket.emit('send command', data);
- });
-
- this.$on('send-initial-log', () => {
- this.socket.emit('send server log');
- })
},
data: function () {
return {
- socket: null,
loadingServerData: true,
};
},
@@ -109,50 +105,17 @@
this.$store.dispatch('server/getCredentials', {server: this.$route.params.id})
])
.then(() => {
+ // Configure the socket.io implementation. This is a really ghetto way of handling things
+ // but all of these plugins assume you have some constant connection, which we don't.
+ const socket = io(`${this.credentials.node}/v1/ws/${this.server.uuid}`, {
+ query: `token=${this.credentials.key}`,
+ });
+
+ Vue.use(VueSocketio, socket, { store: this.$store });
this.loadingServerData = false;
- this.initalizeWebsocket();
})
.catch(console.error);
},
-
- initalizeWebsocket: function () {
- this.socket = io(this.credentials.node + '/v1/ws/' + this.server.uuid, {
- query: 'token=' + this.credentials.key,
- });
-
- this.socket.on('error', this._socket_error);
- this.socket.on('connect', this._socket_connect);
- this.socket.on('status', this._socket_status);
- this.socket.on('initial status', this._socket_status);
- this.socket.on('server log', this._socket_serverLog);
- this.socket.on('console', this._socket_consoleLine);
- },
-
- _socket_error: function (err) {
- this.$emit('socket::error', {err});
- },
-
- _socket_connect: function () {
- this.$emit('socket::connected');
- },
-
- _socket_status: function (data) {
- this.$emit('socket::status', {data});
- },
-
- _socket_serverLog: function (data) {
- data.split(/\n/g).forEach(item => {
- this.$emit('console', item);
- });
- },
-
- _socket_consoleLine: function (data) {
- if(data.line) {
- data.line.split(/\n/g).forEach(item => {
- this.$emit('console', item);
- });
- }
- },
},
}
diff --git a/resources/assets/scripts/components/server/components/PowerButtons.vue b/resources/assets/scripts/components/server/components/PowerButtons.vue
new file mode 100644
index 000000000..ad65f4a86
--- /dev/null
+++ b/resources/assets/scripts/components/server/components/PowerButtons.vue
@@ -0,0 +1,61 @@
+
+