1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
use super::*;
/// The WebSocket class.
/// [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct WebSocket {
inner: EventTarget,
}
impl FromVal for WebSocket {
fn from_val(v: &Any) -> Self {
WebSocket {
inner: EventTarget::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for WebSocket {
type Target = EventTarget;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for WebSocket {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for WebSocket {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for WebSocket {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<WebSocket> for Any {
fn from(s: WebSocket) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&WebSocket> for Any {
fn from(s: &WebSocket) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(WebSocket);
impl WebSocket {
/// Getter of the `url` attribute.
/// [`WebSocket.url`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/url)
pub fn url(&self) -> JsString {
self.inner.get("url").as_::<JsString>()
}
}
impl WebSocket {
/// Getter of the `readyState` attribute.
/// [`WebSocket.readyState`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState)
pub fn ready_state(&self) -> u16 {
self.inner.get("readyState").as_::<u16>()
}
}
impl WebSocket {
/// Getter of the `bufferedAmount` attribute.
/// [`WebSocket.bufferedAmount`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount)
pub fn buffered_amount(&self) -> u64 {
self.inner.get("bufferedAmount").as_::<u64>()
}
}
impl WebSocket {
/// Getter of the `onopen` attribute.
/// [`WebSocket.onopen`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onopen)
pub fn onopen(&self) -> Any {
self.inner.get("onopen").as_::<Any>()
}
/// Setter of the `onopen` attribute.
/// [`WebSocket.onopen`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onopen)
pub fn set_onopen(&mut self, value: &Any) {
self.inner.set("onopen", value);
}
}
impl WebSocket {
/// Getter of the `onerror` attribute.
/// [`WebSocket.onerror`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror)
pub fn onerror(&self) -> Any {
self.inner.get("onerror").as_::<Any>()
}
/// Setter of the `onerror` attribute.
/// [`WebSocket.onerror`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror)
pub fn set_onerror(&mut self, value: &Any) {
self.inner.set("onerror", value);
}
}
impl WebSocket {
/// Getter of the `onclose` attribute.
/// [`WebSocket.onclose`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onclose)
pub fn onclose(&self) -> Any {
self.inner.get("onclose").as_::<Any>()
}
/// Setter of the `onclose` attribute.
/// [`WebSocket.onclose`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onclose)
pub fn set_onclose(&mut self, value: &Any) {
self.inner.set("onclose", value);
}
}
impl WebSocket {
/// Getter of the `extensions` attribute.
/// [`WebSocket.extensions`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/extensions)
pub fn extensions(&self) -> JsString {
self.inner.get("extensions").as_::<JsString>()
}
}
impl WebSocket {
/// Getter of the `protocol` attribute.
/// [`WebSocket.protocol`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/protocol)
pub fn protocol(&self) -> JsString {
self.inner.get("protocol").as_::<JsString>()
}
}
impl WebSocket {
/// Getter of the `onmessage` attribute.
/// [`WebSocket.onmessage`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage)
pub fn onmessage(&self) -> Any {
self.inner.get("onmessage").as_::<Any>()
}
/// Setter of the `onmessage` attribute.
/// [`WebSocket.onmessage`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage)
pub fn set_onmessage(&mut self, value: &Any) {
self.inner.set("onmessage", value);
}
}
impl WebSocket {
/// Getter of the `binaryType` attribute.
/// [`WebSocket.binaryType`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType)
pub fn binary_type(&self) -> BinaryType {
self.inner.get("binaryType").as_::<BinaryType>()
}
/// Setter of the `binaryType` attribute.
/// [`WebSocket.binaryType`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType)
pub fn set_binary_type(&mut self, value: &BinaryType) {
self.inner.set("binaryType", value);
}
}
impl WebSocket {
/// The `new WebSocket(..)` constructor, creating a new WebSocket instance
pub fn new(url: &JsString) -> WebSocket {
Self {
inner: Any::global("WebSocket")
.new(&[url.into()])
.as_::<EventTarget>(),
}
}
}
impl WebSocket {
/// The `new WebSocket(..)` constructor, creating a new WebSocket instance
pub fn new_with_protocols(url: &JsString, protocols: &Any) -> WebSocket {
Self {
inner: Any::global("WebSocket")
.new(&[url.into(), protocols.into()])
.as_::<EventTarget>(),
}
}
}
impl WebSocket {
/// The close method.
/// [`WebSocket.close`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)
pub fn close(&self) -> Undefined {
self.inner.call("close", &[]).as_::<Undefined>()
}
}
impl WebSocket {
/// The close method.
/// [`WebSocket.close`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)
pub fn close_with_code(&self, code: u16) -> Undefined {
self.inner.call("close", &[code.into()]).as_::<Undefined>()
}
}
impl WebSocket {
/// The close method.
/// [`WebSocket.close`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)
pub fn close_with_code_and_reason(&self, code: u16, reason: &JsString) -> Undefined {
self.inner
.call("close", &[code.into(), reason.into()])
.as_::<Undefined>()
}
}
impl WebSocket {
/// The send method.
/// [`WebSocket.send`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)
pub fn send(&self, data: &Any) -> Undefined {
self.inner.call("send", &[data.into()]).as_::<Undefined>()
}
}