summaryrefslogtreecommitdiff
path: root/Base
diff options
context:
space:
mode:
authorDexesTTP <dexes.ttp@gmail.com>2021-04-24 13:54:24 +0200
committerLinus Groh <mail@linusgroh.de>2021-04-25 19:04:34 +0200
commit22413ef729ffe995c5ef3a9f8fb69567ed913980 (patch)
tree5c8c539ea68d32b18d3db961a2912879e8361d03 /Base
parent68bfb46a6fef9aa1b6617382ae4cf10042658e26 (diff)
downloadserenity-22413ef729ffe995c5ef3a9f8fb69567ed913980.zip
LibWeb: Add WebSocket bindings
The WebSocket bindings match the original specification from the WHATWG living standard, but do not match the later update of the standard that involves FETCH. The FETCH update will be handled later since the changes would also affect XMLHttpRequest.
Diffstat (limited to 'Base')
-rw-r--r--Base/res/html/misc/websocket.html42
-rw-r--r--Base/res/html/misc/welcome.html1
2 files changed, 43 insertions, 0 deletions
diff --git a/Base/res/html/misc/websocket.html b/Base/res/html/misc/websocket.html
new file mode 100644
index 0000000000..f3263bedeb
--- /dev/null
+++ b/Base/res/html/misc/websocket.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>WebSocket Test</title>
+ </head>
+ <body>
+ <h2>WebSocket Test</h2>
+ <div id="output"></div>
+ <script type="text/javascript">
+ var output = document.getElementById('output');
+
+ function println(message) {
+ const p = document.createElement('p');
+ p.innerHTML = message;
+ output.appendChild(p);
+ }
+
+ // Websocket echo server, provided from https://www.websocket.org/echo.html
+ var targetUrl = 'wss://echo.websocket.org';
+ var messageContent = 'Hello friends :^)';
+ println('<span style="color: blue;">Connecting to:</span> ' + targetUrl);
+ websocket = new WebSocket(targetUrl);
+ websocket.onopen = function() {
+ println('<span style="color: green;">Connected to:</span> ' + targetUrl);
+ println('<span style="color: blue;">Sending Message:</span> ' + messageContent);
+ websocket.send(messageContent);
+ };
+ websocket.onmessage = function(event) {
+ println('<span style="color: green;">Received Response:</span> ' + event.data);
+ println('<span style="color: blue;">Closing connection...</span> ');
+ websocket.close();
+ };
+ websocket.onerror = function(evt) {
+ println('<span style="color: red;">ERROR:</span> ' + evt.data);
+ };
+ websocket.onclose = function() {
+ println('<span style="color: green;">Connection closed!</span>');
+ };
+ </script>
+ </body>
+</html>
diff --git a/Base/res/html/misc/welcome.html b/Base/res/html/misc/welcome.html
index 65b4dbfc08..e3d3a1d939 100644
--- a/Base/res/html/misc/welcome.html
+++ b/Base/res/html/misc/welcome.html
@@ -38,6 +38,7 @@ span#loadtime {
<p>This page loaded in <b><span id="loadtime"></span></b> ms</p>
<p>Some small test pages:</p>
<ul>
+ <li><a href="websocket.html">WebSocket API Test</a></li>
<li><a href="cookie.html">document.cookie</a></li>
<li><a href="last-of-type.html">CSS :last-of-type selector</a></li>
<li><a href="first-of-type.html">CSS :first-of-type selector</a></li>