Skip to main content

web_sys/features/
gen_WebSocket.rs

1#![allow(unused_imports)]
2#![allow(clippy::all)]
3use super::*;
4use wasm_bindgen::prelude::*;
5#[wasm_bindgen]
6extern "C" {
7    #[wasm_bindgen(
8        extends = "EventTarget",
9        extends = "::js_sys::Object",
10        js_name = "WebSocket",
11        typescript_type = "WebSocket"
12    )]
13    #[derive(Debug, Clone, PartialEq, Eq)]
14    #[doc = "The `WebSocket` class."]
15    #[doc = ""]
16    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)"]
17    #[doc = ""]
18    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
19    pub type WebSocket;
20    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "url")]
21    #[doc = "Getter for the `url` field of this object."]
22    #[doc = ""]
23    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/url)"]
24    #[doc = ""]
25    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
26    pub fn url(this: &WebSocket) -> ::alloc::string::String;
27    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "readyState")]
28    #[doc = "Getter for the `readyState` field of this object."]
29    #[doc = ""]
30    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState)"]
31    #[doc = ""]
32    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
33    pub fn ready_state(this: &WebSocket) -> u16;
34    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "bufferedAmount")]
35    #[doc = "Getter for the `bufferedAmount` field of this object."]
36    #[doc = ""]
37    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount)"]
38    #[doc = ""]
39    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
40    pub fn buffered_amount(this: &WebSocket) -> u32;
41    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "onopen")]
42    #[doc = "Getter for the `onopen` field of this object."]
43    #[doc = ""]
44    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onopen)"]
45    #[doc = ""]
46    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
47    pub fn onopen(this: &WebSocket) -> Option<::js_sys::Function>;
48    #[wasm_bindgen(method, setter, js_class = "WebSocket", js_name = "onopen")]
49    #[doc = "Setter for the `onopen` field of this object."]
50    #[doc = ""]
51    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onopen)"]
52    #[doc = ""]
53    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
54    pub fn set_onopen(this: &WebSocket, value: Option<&::js_sys::Function>);
55    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "onerror")]
56    #[doc = "Getter for the `onerror` field of this object."]
57    #[doc = ""]
58    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror)"]
59    #[doc = ""]
60    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
61    pub fn onerror(this: &WebSocket) -> Option<::js_sys::Function>;
62    #[wasm_bindgen(method, setter, js_class = "WebSocket", js_name = "onerror")]
63    #[doc = "Setter for the `onerror` field of this object."]
64    #[doc = ""]
65    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror)"]
66    #[doc = ""]
67    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
68    pub fn set_onerror(this: &WebSocket, value: Option<&::js_sys::Function>);
69    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "onclose")]
70    #[doc = "Getter for the `onclose` field of this object."]
71    #[doc = ""]
72    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onclose)"]
73    #[doc = ""]
74    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
75    pub fn onclose(this: &WebSocket) -> Option<::js_sys::Function>;
76    #[wasm_bindgen(method, setter, js_class = "WebSocket", js_name = "onclose")]
77    #[doc = "Setter for the `onclose` field of this object."]
78    #[doc = ""]
79    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onclose)"]
80    #[doc = ""]
81    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
82    pub fn set_onclose(this: &WebSocket, value: Option<&::js_sys::Function>);
83    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "extensions")]
84    #[doc = "Getter for the `extensions` field of this object."]
85    #[doc = ""]
86    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/extensions)"]
87    #[doc = ""]
88    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
89    pub fn extensions(this: &WebSocket) -> ::alloc::string::String;
90    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "protocol")]
91    #[doc = "Getter for the `protocol` field of this object."]
92    #[doc = ""]
93    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/protocol)"]
94    #[doc = ""]
95    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
96    pub fn protocol(this: &WebSocket) -> ::alloc::string::String;
97    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "onmessage")]
98    #[doc = "Getter for the `onmessage` field of this object."]
99    #[doc = ""]
100    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage)"]
101    #[doc = ""]
102    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
103    pub fn onmessage(this: &WebSocket) -> Option<::js_sys::Function>;
104    #[wasm_bindgen(method, setter, js_class = "WebSocket", js_name = "onmessage")]
105    #[doc = "Setter for the `onmessage` field of this object."]
106    #[doc = ""]
107    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage)"]
108    #[doc = ""]
109    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
110    pub fn set_onmessage(this: &WebSocket, value: Option<&::js_sys::Function>);
111    #[cfg(feature = "BinaryType")]
112    #[wasm_bindgen(method, getter, js_class = "WebSocket", js_name = "binaryType")]
113    #[doc = "Getter for the `binaryType` field of this object."]
114    #[doc = ""]
115    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType)"]
116    #[doc = ""]
117    #[doc = "*This API requires the following crate features to be activated: `BinaryType`, `WebSocket`*"]
118    pub fn binary_type(this: &WebSocket) -> BinaryType;
119    #[cfg(feature = "BinaryType")]
120    #[wasm_bindgen(method, setter, js_class = "WebSocket", js_name = "binaryType")]
121    #[doc = "Setter for the `binaryType` field of this object."]
122    #[doc = ""]
123    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType)"]
124    #[doc = ""]
125    #[doc = "*This API requires the following crate features to be activated: `BinaryType`, `WebSocket`*"]
126    pub fn set_binary_type(this: &WebSocket, value: BinaryType);
127    #[wasm_bindgen(catch, constructor, js_class = "WebSocket")]
128    #[doc = "The `new WebSocket(..)` constructor, creating a new instance of `WebSocket`."]
129    #[doc = ""]
130    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket)"]
131    #[doc = ""]
132    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
133    pub fn new(url: &str) -> Result<WebSocket, JsValue>;
134    #[wasm_bindgen(catch, constructor, js_class = "WebSocket")]
135    #[doc = "The `new WebSocket(..)` constructor, creating a new instance of `WebSocket`."]
136    #[doc = ""]
137    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket)"]
138    #[doc = ""]
139    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
140    pub fn new_with_str(url: &str, protocols: &str) -> Result<WebSocket, JsValue>;
141    #[wasm_bindgen(catch, constructor, js_class = "WebSocket")]
142    #[doc = "The `new WebSocket(..)` constructor, creating a new instance of `WebSocket`."]
143    #[doc = ""]
144    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket)"]
145    #[doc = ""]
146    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
147    pub fn new_with_str_sequence(
148        url: &str,
149        protocols: &::wasm_bindgen::JsValue,
150    ) -> Result<WebSocket, JsValue>;
151    #[wasm_bindgen(catch, method, js_class = "WebSocket")]
152    #[doc = "The `close()` method."]
153    #[doc = ""]
154    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)"]
155    #[doc = ""]
156    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
157    pub fn close(this: &WebSocket) -> Result<(), JsValue>;
158    #[wasm_bindgen(catch, method, js_class = "WebSocket", js_name = "close")]
159    #[doc = "The `close()` method."]
160    #[doc = ""]
161    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)"]
162    #[doc = ""]
163    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
164    pub fn close_with_code(this: &WebSocket, code: u16) -> Result<(), JsValue>;
165    #[wasm_bindgen(catch, method, js_class = "WebSocket", js_name = "close")]
166    #[doc = "The `close()` method."]
167    #[doc = ""]
168    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)"]
169    #[doc = ""]
170    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
171    pub fn close_with_code_and_reason(
172        this: &WebSocket,
173        code: u16,
174        reason: &str,
175    ) -> Result<(), JsValue>;
176    #[wasm_bindgen(catch, method, js_class = "WebSocket", js_name = "send")]
177    #[doc = "The `send()` method."]
178    #[doc = ""]
179    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
180    #[doc = ""]
181    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
182    pub fn send_with_str(this: &WebSocket, data: &str) -> Result<(), JsValue>;
183    #[cfg(feature = "Blob")]
184    #[wasm_bindgen(catch, method, js_class = "WebSocket", js_name = "send")]
185    #[doc = "The `send()` method."]
186    #[doc = ""]
187    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
188    #[doc = ""]
189    #[doc = "*This API requires the following crate features to be activated: `Blob`, `WebSocket`*"]
190    pub fn send_with_blob(this: &WebSocket, data: &Blob) -> Result<(), JsValue>;
191    #[wasm_bindgen(catch, method, js_class = "WebSocket", js_name = "send")]
192    #[doc = "The `send()` method."]
193    #[doc = ""]
194    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
195    #[doc = ""]
196    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
197    pub fn send_with_array_buffer(
198        this: &WebSocket,
199        data: &::js_sys::ArrayBuffer,
200    ) -> Result<(), JsValue>;
201    #[wasm_bindgen(catch, method, js_class = "WebSocket", js_name = "send")]
202    #[doc = "The `send()` method."]
203    #[doc = ""]
204    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
205    #[doc = ""]
206    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
207    pub fn send_with_array_buffer_view(
208        this: &WebSocket,
209        data: &::js_sys::Object,
210    ) -> Result<(), JsValue>;
211    #[wasm_bindgen(catch, method, js_class = "WebSocket", js_name = "send")]
212    #[doc = "The `send()` method."]
213    #[doc = ""]
214    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
215    #[doc = ""]
216    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
217    pub fn send_with_u8_array(this: &WebSocket, data: &[u8]) -> Result<(), JsValue>;
218    #[wasm_bindgen(catch, method, js_class = "WebSocket", js_name = "send")]
219    #[doc = "The `send()` method."]
220    #[doc = ""]
221    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
222    #[doc = ""]
223    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
224    pub fn send_with_js_u8_array(
225        this: &WebSocket,
226        data: &::js_sys::Uint8Array,
227    ) -> Result<(), JsValue>;
228}
229impl WebSocket {
230    #[doc = "The `WebSocket.CONNECTING` const."]
231    #[doc = ""]
232    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
233    pub const CONNECTING: u16 = 0i64 as u16;
234    #[doc = "The `WebSocket.OPEN` const."]
235    #[doc = ""]
236    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
237    pub const OPEN: u16 = 1u64 as u16;
238    #[doc = "The `WebSocket.CLOSING` const."]
239    #[doc = ""]
240    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
241    pub const CLOSING: u16 = 2u64 as u16;
242    #[doc = "The `WebSocket.CLOSED` const."]
243    #[doc = ""]
244    #[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
245    pub const CLOSED: u16 = 3u64 as u16;
246}