From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- .../examples/express-session-parse/public/app.js | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 testing/xpcshell/node-ws/examples/express-session-parse/public/app.js (limited to 'testing/xpcshell/node-ws/examples/express-session-parse/public/app.js') diff --git a/testing/xpcshell/node-ws/examples/express-session-parse/public/app.js b/testing/xpcshell/node-ws/examples/express-session-parse/public/app.js new file mode 100644 index 0000000000..f70dc21835 --- /dev/null +++ b/testing/xpcshell/node-ws/examples/express-session-parse/public/app.js @@ -0,0 +1,67 @@ +(function () { + const messages = document.querySelector('#messages'); + const wsButton = document.querySelector('#wsButton'); + const wsSendButton = document.querySelector('#wsSendButton'); + const logout = document.querySelector('#logout'); + const login = document.querySelector('#login'); + + function showMessage(message) { + messages.textContent += `\n${message}`; + messages.scrollTop = messages.scrollHeight; + } + + function handleResponse(response) { + return response.ok + ? response.json().then((data) => JSON.stringify(data, null, 2)) + : Promise.reject(new Error('Unexpected response')); + } + + login.onclick = function () { + fetch('/login', { method: 'POST', credentials: 'same-origin' }) + .then(handleResponse) + .then(showMessage) + .catch(function (err) { + showMessage(err.message); + }); + }; + + logout.onclick = function () { + fetch('/logout', { method: 'DELETE', credentials: 'same-origin' }) + .then(handleResponse) + .then(showMessage) + .catch(function (err) { + showMessage(err.message); + }); + }; + + let ws; + + wsButton.onclick = function () { + if (ws) { + ws.onerror = ws.onopen = ws.onclose = null; + ws.close(); + } + + ws = new WebSocket(`ws://${location.host}`); + ws.onerror = function () { + showMessage('WebSocket error'); + }; + ws.onopen = function () { + showMessage('WebSocket connection established'); + }; + ws.onclose = function () { + showMessage('WebSocket connection closed'); + ws = null; + }; + }; + + wsSendButton.onclick = function () { + if (!ws) { + showMessage('No WebSocket connection'); + return; + } + + ws.send('Hello World!'); + showMessage('Sent "Hello World!"'); + }; +})(); -- cgit v1.2.3