diff --git a/src/static/js/pad.js b/src/static/js/pad.js index 485a4b2fe..ec156eb46 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -218,7 +218,14 @@ const sendClientReady = (isReconnect, messageType) => { }; const handshake = () => { + let padId = document.location.pathname.substring(document.location.pathname.lastIndexOf('/') + 1); + // unescape neccesary due to Safari and Opera interpretation of spaces + padId = decodeURIComponent(padId); + + // padId is used here for sharding / scaling. We prefix the padId with padId: so it's clear + // to the proxy/gateway/whatever that this is a pad connection and should be treated as such socket = pad.socket = socketio.connect(exports.baseURL, '/', { + query: {padId}, reconnectionAttempts: 5, reconnection: true, reconnectionDelay: 1000, diff --git a/src/static/js/timeslider.js b/src/static/js/timeslider.js index 74aaf4f5d..47246b4a1 100644 --- a/src/static/js/timeslider.js +++ b/src/static/js/timeslider.js @@ -52,7 +52,7 @@ const init = () => { Cookies.set('token', token, {expires: 60}); } - socket = socketio.connect(exports.baseURL); + socket = socketio.connect(exports.baseURL, '/', {query: {padId}}); // send the ready message once we're connected socket.on('connect', () => { diff --git a/src/tests/backend/specs/socketio.js b/src/tests/backend/specs/socketio.js index fdb578b55..dbd633add 100644 --- a/src/tests/backend/specs/socketio.js +++ b/src/tests/backend/specs/socketio.js @@ -52,12 +52,13 @@ const connect = async (res) => { ([name, cookie]) => `${name}=${encodeURIComponent(cookie.value)}`).join('; '); logger.debug('socket.io connecting...'); + const padId = res.req.path.split('/p/')[1]; const socket = io(`${common.baseUrl}/`, { forceNew: true, // Different tests will have different query parameters. path: '/socket.io', // socketio.js-client on node.js doesn't support cookies (see https://git.io/JU8u9), so the // express_sid cookie must be passed as a query parameter. - query: {cookie: reqCookieHdr}, + query: {cookie: reqCookieHdr, padId}, }); try { await getSocketEvent(socket, 'connect');