forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
16 changed files
with
593 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:https://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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -645,6 +645,12 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter | |
auto @cpp_name@ = @js_name@@[email protected]_u32(global_object); | ||
if (vm.exception()) | ||
@return_statement@ | ||
)~~~"); | ||
} else if (parameter.type.name == "unsigned short") { | ||
scoped_generator.append(R"~~~( | ||
auto @cpp_name@ = (u16)@js_name@@[email protected]_u32(global_object); | ||
if (vm.exception()) | ||
@return_statement@ | ||
)~~~"); | ||
} else if (parameter.type.name == "EventHandler") { | ||
// x.onfoo = function() { ... } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2021, Dex♪ <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <LibWeb/DOM/Event.h> | ||
|
||
namespace Web::HTML { | ||
|
||
class CloseEvent : public DOM::Event { | ||
public: | ||
using WrapperType = Bindings::CloseEventWrapper; | ||
|
||
static NonnullRefPtr<CloseEvent> create(const FlyString& event_name, bool was_clean, u16 code, const String& reason) | ||
{ | ||
return adopt_ref(*new CloseEvent(event_name, was_clean, code, reason)); | ||
} | ||
|
||
virtual ~CloseEvent() override = default; | ||
|
||
bool was_clean() { return m_was_clean; } | ||
u16 code() const { return m_code; } | ||
String reason() const { return m_reason; } | ||
|
||
protected: | ||
CloseEvent(const FlyString& event_name, bool was_clean, u16 code, const String& reason) | ||
: Event(event_name) | ||
, m_was_clean(was_clean) | ||
, m_code(code) | ||
, m_reason(reason) | ||
{ | ||
} | ||
|
||
bool m_was_clean { false }; | ||
u16 m_code { 0 }; | ||
String m_reason; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface CloseEvent : Event { | ||
|
||
readonly attribute boolean wasClean; | ||
readonly attribute unsigned short code; | ||
readonly attribute USVString reason; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2021, Dex♪ <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <LibWeb/DOM/Event.h> | ||
|
||
namespace Web::HTML { | ||
|
||
class MessageEvent : public DOM::Event { | ||
public: | ||
using WrapperType = Bindings::MessageEventWrapper; | ||
|
||
static NonnullRefPtr<MessageEvent> create(const FlyString& event_name, const String& data, const String& origin) | ||
{ | ||
return adopt_ref(*new MessageEvent(event_name, data, origin)); | ||
} | ||
|
||
virtual ~MessageEvent() override = default; | ||
|
||
const String& data() const { return m_data; } | ||
const String& origin() const { return m_origin; } | ||
|
||
protected: | ||
MessageEvent(const FlyString& event_name, const String& data, const String& origin) | ||
: DOM::Event(event_name) | ||
, m_data(data) | ||
, m_origin(origin) | ||
{ | ||
} | ||
|
||
String m_data; | ||
String m_origin; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface MessageEvent : Event { | ||
|
||
// FIXME: This should be of type "any" instead of "USVString" | ||
readonly attribute USVString data; | ||
readonly attribute USVString origin; | ||
|
||
}; |
Oops, something went wrong.