gossamer/web_socket
Types
Values
pub fn binary_type(socket: WebSocket) -> binary_type.BinaryType
Returns a value that indicates how binary data from the WebSocket object is exposed to scripts.
pub fn buffered_amount(socket: WebSocket) -> Int
Returns the number of bytes of application data (UTF-8 text and binary
data) that have been queued using send but not yet been transmitted to
the network.
If the WebSocket connection is closed, this attribute’s value will only
increase with each call to the send method. (The number does not reset
to zero once the connection closes.)
pub fn close_with(
socket: WebSocket,
code: Int,
reason: String,
) -> Nil
Closes the WebSocket connection, using the given code as the WebSocket connection close code and reason as the WebSocket connection close reason.
pub fn extensions(socket: WebSocket) -> String
Returns the extensions selected by the server, if any.
pub fn new(url: String) -> WebSocket
Creates a new WebSocket connection to the given URL.
Examples
let ws = web_socket.new("ws://localhost:8080")
pub fn new_with_protocols(
url: String,
protocols: List(String),
) -> WebSocket
Creates a new WebSocket connection to the given URL with the
specified sub-protocols.
Examples
let ws = web_socket.new_with_protocols("ws://localhost:8080", ["json"])
pub fn on_close(
socket: WebSocket,
handler: fn(close_event.CloseEvent) -> Nil,
) -> Nil
pub fn on_message(
socket: WebSocket,
handler: fn(message_event.MessageEvent) -> Nil,
) -> Nil
pub fn protocol(socket: WebSocket) -> String
Returns the subprotocol selected by the server, if any. It can be used in conjunction with the protocols parameter to perform subprotocol negotiation.
pub fn ready_state(socket: WebSocket) -> Int
Returns the state of the WebSocket object’s connection.
pub fn send(socket: WebSocket, data: String) -> Nil
Transmits string data using the WebSocket connection.
pub fn send_dynamic(
socket: WebSocket,
data: dynamic.Dynamic,
) -> Nil
Transmits data using the WebSocket connection. Data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
pub fn set_binary_type(
socket: WebSocket,
value: binary_type.BinaryType,
) -> Nil
Can be set, to change how binary data is returned. The default is Blob.