diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/xpcshell/node-ws/examples/server-stats | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
3 files changed, 105 insertions, 0 deletions
diff --git a/testing/xpcshell/node-ws/examples/server-stats/index.js b/testing/xpcshell/node-ws/examples/server-stats/index.js new file mode 100644 index 0000000000..e8754b5b28 --- /dev/null +++ b/testing/xpcshell/node-ws/examples/server-stats/index.js @@ -0,0 +1,33 @@ +'use strict'; + +const express = require('express'); +const path = require('path'); +const { createServer } = require('http'); + +const { WebSocketServer } = require('../..'); + +const app = express(); +app.use(express.static(path.join(__dirname, '/public'))); + +const server = createServer(app); +const wss = new WebSocketServer({ server }); + +wss.on('connection', function (ws) { + const id = setInterval(function () { + ws.send(JSON.stringify(process.memoryUsage()), function () { + // + // Ignore errors. + // + }); + }, 100); + console.log('started client interval'); + + ws.on('close', function () { + console.log('stopping client interval'); + clearInterval(id); + }); +}); + +server.listen(8080, function () { + console.log('Listening on http://localhost:8080'); +}); diff --git a/testing/xpcshell/node-ws/examples/server-stats/package.json b/testing/xpcshell/node-ws/examples/server-stats/package.json new file mode 100644 index 0000000000..20e2029133 --- /dev/null +++ b/testing/xpcshell/node-ws/examples/server-stats/package.json @@ -0,0 +1,9 @@ +{ + "author": "", + "name": "serverstats", + "version": "0.0.0", + "repository": "websockets/ws", + "dependencies": { + "express": "^4.16.4" + } +} diff --git a/testing/xpcshell/node-ws/examples/server-stats/public/index.html b/testing/xpcshell/node-ws/examples/server-stats/public/index.html new file mode 100644 index 0000000000..a82815af6f --- /dev/null +++ b/testing/xpcshell/node-ws/examples/server-stats/public/index.html @@ -0,0 +1,63 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>Server stats</title> + <style> + table, td { + border: 1px solid #333; + } + + thead { + background-color: #333; + color: #fff; + } + </style> + </head> + <body> + <h1>Server stats</h1> + <table> + <thead> + <tr> + <th colspan="2">Memory usage</th> + </tr> + </thead> + <tbody> + <tr> + <td>RSS</td> + <td id="rss"></td> + </tr> + <tr> + <td>Heap total</td> + <td id="heapTotal"></td> + </tr> + <tr> + <td>Heap used</td> + <td id="heapUsed"></td> + </tr> + <tr> + <td>External</td> + <td id="external"></td> + </tr> + </tbody> + </table> + <script> + (function() { + const rss = document.getElementById('rss'); + const heapTotal = document.getElementById('heapTotal'); + const heapUsed = document.getElementById('heapUsed'); + const external = document.getElementById('external'); + const ws = new WebSocket(`ws://${location.host}`); + + ws.onmessage = function(event) { + const data = JSON.parse(event.data); + + rss.textContent = data.rss; + heapTotal.textContent = data.heapTotal; + heapUsed.textContent = data.heapUsed; + external.textContent = data.external; + }; + })(); + </script> + </body> +</html> |