|
@@ -2,16 +2,17 @@
|
|
|
import io from 'socket.io-client';
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
|
-const SERVER_URL = process.env.VUE_APP_SERVER_CONN + '://' + process.env.VUE_APP_SERVER_HOST;
|
|
|
+const SERVER_URL =
|
|
|
+ process.env.VUE_APP_SERVER_CONN + '://' + process.env.VUE_APP_SERVER_HOST;
|
|
|
const SERVER_PORT = process.env.VUE_APP_SERVER_PORT;
|
|
|
|
|
|
export default function SocketService(socketEventBus, vuexStore) {
|
|
|
let store = vuexStore;
|
|
|
let ioClient = null;
|
|
|
- let connect = function (name) {
|
|
|
+ let connect = function(name) {
|
|
|
let promise = new Promise((resolve, reject) => {
|
|
|
let serverUrl = SERVER_URL;
|
|
|
- if (SERVER_PORT != "") {
|
|
|
+ if (SERVER_PORT != '') {
|
|
|
serverUrl += ':' + SERVER_PORT;
|
|
|
}
|
|
|
ioClient = io(serverUrl, {
|
|
@@ -27,7 +28,7 @@ export default function SocketService(socketEventBus, vuexStore) {
|
|
|
|
|
|
ioClient.on('connect', () => {
|
|
|
console.log('Connected to server');
|
|
|
- ioClient.emit('auth', name, function (response) {
|
|
|
+ ioClient.emit('auth', name, function(response) {
|
|
|
if (response.res === 'ok') {
|
|
|
resolve(response.message);
|
|
|
} else {
|
|
@@ -61,7 +62,7 @@ export default function SocketService(socketEventBus, vuexStore) {
|
|
|
return promise;
|
|
|
};
|
|
|
|
|
|
- let checkConnection = function (playername) {
|
|
|
+ let checkConnection = function(playername) {
|
|
|
if (ioClient && ioClient.connected === false) {
|
|
|
return connect(playername);
|
|
|
} else {
|
|
@@ -69,15 +70,15 @@ export default function SocketService(socketEventBus, vuexStore) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- let disconnect = function () {
|
|
|
+ let disconnect = function() {
|
|
|
console.log('Manual client disconnect');
|
|
|
ioClient.close();
|
|
|
};
|
|
|
- let getGamesList = function (playername) {
|
|
|
+ let getGamesList = function(playername) {
|
|
|
return checkConnection(playername).then(
|
|
|
() => {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- ioClient.emit('games-list', playername, function (response) {
|
|
|
+ ioClient.emit('games-list', playername, function(response) {
|
|
|
if (response.res === 'ok') {
|
|
|
resolve(response.message);
|
|
|
} else {
|
|
@@ -90,11 +91,11 @@ export default function SocketService(socketEventBus, vuexStore) {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- let createGame = function (game) {
|
|
|
+ let createGame = function(game) {
|
|
|
return checkConnection(game.player1).then(
|
|
|
() => {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- ioClient.emit('create-game', game, function (response) {
|
|
|
+ ioClient.emit('create-game', game, function(response) {
|
|
|
if (response.res === 'ok') {
|
|
|
resolve(response.message);
|
|
|
} else {
|
|
@@ -106,11 +107,11 @@ export default function SocketService(socketEventBus, vuexStore) {
|
|
|
error => Promise.reject(error)
|
|
|
);
|
|
|
};
|
|
|
- let joinGame = function (username, gameId, joinCreatedGame) {
|
|
|
+ let joinGame = function(username, gameId, joinCreatedGame) {
|
|
|
return checkConnection(username).then(
|
|
|
() => {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- ioClient.emit('join-game', { id: gameId, joinCreatedGame }, function (
|
|
|
+ ioClient.emit('join-game', { id: gameId, joinCreatedGame }, function(
|
|
|
response
|
|
|
) {
|
|
|
if (response.res === 'ok') {
|
|
@@ -124,11 +125,11 @@ export default function SocketService(socketEventBus, vuexStore) {
|
|
|
error => Promise.reject(error)
|
|
|
);
|
|
|
};
|
|
|
- let leaveGame = function (username) {
|
|
|
+ let leaveGame = function(username) {
|
|
|
return checkConnection(username).then(
|
|
|
() => {
|
|
|
return new Promise(resolve => {
|
|
|
- ioClient.emit('leave-game', username, function (response) {
|
|
|
+ ioClient.emit('leave-game', username, function(response) {
|
|
|
resolve(response);
|
|
|
});
|
|
|
});
|
|
@@ -136,7 +137,7 @@ export default function SocketService(socketEventBus, vuexStore) {
|
|
|
error => Promise.reject(error)
|
|
|
);
|
|
|
};
|
|
|
- let endTurn = function (payload) {
|
|
|
+ let endTurn = function(payload) {
|
|
|
return checkConnection(payload.username).then(
|
|
|
() => {
|
|
|
return new Promise(resolve => {
|
|
@@ -148,7 +149,7 @@ export default function SocketService(socketEventBus, vuexStore) {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- let chat = function (message) {
|
|
|
+ let chat = function(message) {
|
|
|
ioClient.emit('chat', message);
|
|
|
};
|
|
|
return {
|