#![allow(unused_imports)]
#![allow(clippy::all)]
use super::config::*;
use super::*;
use std::result::Result;
use wasm_bindgen::prelude::*;
use workflow_core::runtime::*;
use workflow_wasm::options::OptionsTrait;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: web_sys :: EventTarget , extends = :: js_sys :: Object , js_name = WebSocket , typescript_type = "WebSocket")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `WebSocket` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub type WebSocket;
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = url)]
#[doc = "Getter for the `url` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/url)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn url(this: &WebSocket) -> String;
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = readyState)]
#[doc = "Getter for the `readyState` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn ready_state(this: &WebSocket) -> u16;
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = bufferedAmount)]
#[doc = "Getter for the `bufferedAmount` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn buffered_amount(this: &WebSocket) -> u32;
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = onopen)]
#[doc = "Getter for the `onopen` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onopen)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn onopen(this: &WebSocket) -> Option<::js_sys::Function>;
# [wasm_bindgen (structural , method , setter , js_class = "WebSocket" , js_name = onopen)]
#[doc = "Setter for the `onopen` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onopen)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn set_onopen(this: &WebSocket, value: Option<&::js_sys::Function>);
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = onerror)]
#[doc = "Getter for the `onerror` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn onerror(this: &WebSocket) -> Option<::js_sys::Function>;
# [wasm_bindgen (structural , method , setter , js_class = "WebSocket" , js_name = onerror)]
#[doc = "Setter for the `onerror` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn set_onerror(this: &WebSocket, value: Option<&::js_sys::Function>);
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = onclose)]
#[doc = "Getter for the `onclose` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onclose)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn onclose(this: &WebSocket) -> Option<::js_sys::Function>;
# [wasm_bindgen (structural , method , setter , js_class = "WebSocket" , js_name = onclose)]
#[doc = "Setter for the `onclose` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onclose)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn set_onclose(this: &WebSocket, value: Option<&::js_sys::Function>);
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = extensions)]
#[doc = "Getter for the `extensions` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/extensions)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn extensions(this: &WebSocket) -> String;
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = protocol)]
#[doc = "Getter for the `protocol` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/protocol)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn protocol(this: &WebSocket) -> String;
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = onmessage)]
#[doc = "Getter for the `onmessage` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn onmessage(this: &WebSocket) -> Option<::js_sys::Function>;
# [wasm_bindgen (structural , method , setter , js_class = "WebSocket" , js_name = onmessage)]
#[doc = "Setter for the `onmessage` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn set_onmessage(this: &WebSocket, value: Option<&::js_sys::Function>);
# [wasm_bindgen (structural , method , getter , js_class = "WebSocket" , js_name = binaryType)]
#[doc = "Getter for the `binaryType` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `BinaryType`, `WebSocket`*"]
pub fn binary_type(this: &WebSocket) -> web_sys::BinaryType;
# [wasm_bindgen (method , setter , js_class = "WebSocket" , js_name = binaryType)]
#[doc = "Setter for the `binaryType` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `BinaryType`, `WebSocket`*"]
pub fn set_binary_type(this: &WebSocket, value: web_sys::BinaryType);
#[wasm_bindgen(catch, constructor, js_class = "WebSocket")]
#[doc = "The `new WebSocket(..)` constructor, creating a new instance of `WebSocket`."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn new(url: &str) -> Result<WebSocket, JsValue>;
#[wasm_bindgen(catch, constructor, js_class = "WebSocket")]
#[doc = "The `new WebSocket(..)` constructor, creating a new instance of `WebSocket`."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn new_with_str(url: &str, protocols: &str) -> Result<WebSocket, JsValue>;
#[wasm_bindgen(catch, constructor, js_class = "WebSocket")]
#[doc = "The `new WebSocket(..)` constructor, creating a new instance of `WebSocket`."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn new_with_str_sequence(
url: &str,
protocols: &::wasm_bindgen::JsValue,
) -> Result<WebSocket, JsValue>;
# [wasm_bindgen (catch , method , structural , js_class = "WebSocket" , js_name = close)]
#[doc = "The `close()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn close(this: &WebSocket) -> Result<(), JsValue>;
# [wasm_bindgen (catch , method , structural , js_class = "WebSocket" , js_name = close)]
#[doc = "The `close()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn close_with_code(this: &WebSocket, code: u16) -> Result<(), JsValue>;
# [wasm_bindgen (catch , method , structural , js_class = "WebSocket" , js_name = close)]
#[doc = "The `close()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn close_with_code_and_reason(
this: &WebSocket,
code: u16,
reason: &str,
) -> Result<(), JsValue>;
# [wasm_bindgen (catch , method , structural , js_class = "WebSocket" , js_name = send)]
#[doc = "The `send()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn send_with_str(this: &WebSocket, data: &str) -> Result<(), JsValue>;
# [wasm_bindgen (catch , method , structural , js_class = "WebSocket" , js_name = send)]
#[doc = "The `send()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Blob`, `WebSocket`*"]
pub fn send_with_blob(this: &WebSocket, data: &web_sys::Blob) -> Result<(), JsValue>;
# [wasm_bindgen (catch , method , structural , js_class = "WebSocket" , js_name = send)]
#[doc = "The `send()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn send_with_array_buffer(
this: &WebSocket,
data: &::js_sys::ArrayBuffer,
) -> Result<(), JsValue>;
# [wasm_bindgen (catch , method , structural , js_class = "WebSocket" , js_name = send)]
#[doc = "The `send()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn send_with_array_buffer_view(
this: &WebSocket,
data: &::js_sys::Object,
) -> Result<(), JsValue>;
# [wasm_bindgen (catch , method , structural , js_class = "WebSocket" , js_name = send)]
#[doc = "The `send()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn send_with_u8_array(this: &WebSocket, data: &[u8]) -> Result<(), JsValue>;
#[wasm_bindgen(catch, constructor, js_class = "WebSocket")]
#[doc = "The `new WebSocket(..)` constructor, creating a new instance of `WebSocket`."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub fn new_with_nodejs_config_impl(
url: &str,
protocols: JsValue,
origin: JsValue,
headers: JsValue,
request_options: JsValue,
client_config: JsValue,
) -> std::result::Result<WebSocket, JsValue>;
}
impl WebSocket {
#[doc = "The `WebSocket.CONNECTING` const."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub const CONNECTING: u16 = 0i64 as u16;
#[doc = "The `WebSocket.OPEN` const."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub const OPEN: u16 = 1u64 as u16;
#[doc = "The `WebSocket.CLOSING` const."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub const CLOSING: u16 = 2u64 as u16;
#[doc = "The `WebSocket.CLOSED` const."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebSocket`*"]
pub const CLOSED: u16 = 3u64 as u16;
pub fn new_with_config(
url: &str,
config: &WebSocketConfig,
) -> super::result::Result<WebSocket> {
if is_node() {
let WebSocketNodeJsConfig {
protocols,
origin,
headers,
request_options,
client_config,
} = WebSocketNodeJsConfig::try_from(config)?;
Ok(Self::new_with_nodejs_config_impl(
url,
protocols,
origin,
headers,
request_options,
client_config,
)?)
} else {
Ok(Self::new(url)?)
}
}
pub fn close_if_open(&self) -> super::result::Result<()> {
let ready_state = self.ready_state();
if ready_state != Self::CLOSED && ready_state != Self::CLOSING {
self.close()?;
}
Ok(())
}
}