From: Benjamin Auder Date: Thu, 20 Dec 2018 08:55:16 +0000 (+0100) Subject: Fix promotion bug on smartphones X-Git-Url: https://git.auder.net/img/scripts/%7B%7B%20asset%28%27mixstore/doc/html/index.html?a=commitdiff_plain;h=2807f530f7d9d7675497974fa95aa7ecdd5d144c;p=vchess.git Fix promotion bug on smartphones --- diff --git a/package-lock.json b/package-lock.json index 555c0d82..cc552a26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1948,12 +1948,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1968,17 +1970,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2095,7 +2100,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2107,6 +2113,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2121,6 +2128,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2128,12 +2136,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2152,6 +2162,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2232,7 +2243,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2244,6 +2256,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2365,6 +2378,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index a17876da..17f3b18d 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -257,7 +257,11 @@ Vue.component('my-game', { attrs: { "src": '/images/pieces/' + VariantRules.getPpath(m.appear[0].c+m.appear[0].p) + '.svg' }, 'class': { 'choice-piece': true }, - on: { "click": e => { this.play(m); this.choices=[]; } }, + on: { + "click": e => { this.play(m); this.choices=[]; }, + // NOTE: add 'touchstart' event to fix a problem on smartphones + "touchstart": e => { this.play(m); this.choices=[]; }, + }, }) ] ); diff --git a/sockets.js b/sockets.js index c130dd78..2d9117d2 100644 --- a/sockets.js +++ b/sockets.js @@ -2,6 +2,17 @@ const url = require('url'); const sqlite3 = require('sqlite3'); const db = new sqlite3.Database('db/vchess.sqlite'); +// Node version in Ubuntu 16.04 does not know about URL class +function getJsonFromUrl(url) { + var query = url.substr(2); //starts with "/?" + var result = {}; + query.split("&").forEach(function(part) { + var item = part.split("="); + result[item[0]] = decodeURIComponent(item[1]); + }); + return result; +} + module.exports = function(wss) { db.serialize(function() { db.all("SELECT * FROM Variants", (err,variants) => { @@ -12,9 +23,12 @@ module.exports = function(wss) { // No-op function as a callback when sending messages const noop = () => { }; wss.on("connection", (socket, req) => { - const params = new URL("http://localhost" + req.url).searchParams; - const sid = params.get("sid"); - const page = params.get("page"); +// const params = new URL("http://localhost" + req.url).searchParams; +// const sid = params.get("sid"); +// const page = params.get("page"); + var query = getJsonFromUrl(req.url); + const sid = query["sid"]; + const page = query["page"]; // Ignore duplicate connections: if (!!clients[page][sid]) {