X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=sockets.js;h=11fe91ccc8079e07c91e899c7c62608b1d217fcb;hb=0596f5e7f9a87acbb13445f1bb93e803e9f5ea3c;hp=c130dd78d76681ecf48cf2acc26899e467aba0b8;hpb=56a683cd685eceeff44560c060c9c97605429ee1;p=vchess.git diff --git a/sockets.js b/sockets.js index c130dd78..11fe91cc 100644 --- a/sockets.js +++ b/sockets.js @@ -1,6 +1,17 @@ const url = require('url'); const sqlite3 = require('sqlite3'); -const db = new sqlite3.Database('db/vchess.sqlite'); +const db = new sqlite3.Database(__dirname + "/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() { @@ -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]) {