Skip to main content

web_wt_sys/webtransport/
web_transport_options.rs

1//! [`WebTransportOptions`]
2//!
3//! <https://w3c.github.io/webtransport/#dictdef-webtransportoptions>
4
5use wasm_bindgen::prelude::*;
6
7extern crate alloc;
8
9use super::*;
10
11crate::dictionary_type! {
12    /// ```webidl
13    /// dictionary WebTransportOptions {
14    ///   boolean allowPooling = false;
15    ///   boolean requireUnreliable = false;
16    ///   HeadersInit headers = {};
17    ///   sequence<WebTransportHash> serverCertificateHashes = [];
18    ///   WebTransportCongestionControl congestionControl = "default";
19    ///   [EnforceRange] unsigned short? anticipatedConcurrentIncomingUnidirectionalStreams = null;
20    ///   [EnforceRange] unsigned short? anticipatedConcurrentIncomingBidirectionalStreams = null;
21    ///   sequence<DOMString> protocols = [];
22    ///   ReadableStreamType datagramsReadableType;
23    /// };
24    /// ```
25    ///
26    /// <https://w3c.github.io/webtransport/#dictdef-webtransportoptions>
27    pub type WebTransportOptions {
28        allow_pooling: bool => allowPooling
29        require_unreliable: bool => requireUnreliable
30        headers_raw: JsValue => headers
31        server_certificate_hashes: alloc::vec::Vec<WebTransportHash>  => serverCertificateHashes
32        congestion_control: WebTransportCongestionControl => congestionControl
33        anticipated_concurrent_incoming_unidirectional_streams: u16 => anticipatedConcurrentIncomingUnidirectionalStreams
34        anticipated_concurrent_incoming_bidirectional_streams: u16 => anticipatedConcurrentIncomingBidirectionalStreams
35        protocols: alloc::vec::Vec<js_sys::JsString> => protocols
36        datagrams_readable_type: web_sys::ReadableStreamType => datagramsReadableType
37    }
38}
39
40impl WebTransportOptions {
41    /// Set the `headers` field from a [`web_sys::Headers`] object.
42    ///
43    /// The `headers` field is a `HeadersInit`, so it can also be set to
44    /// a sequence of header name/value pairs or a string record via
45    /// [`Self::set_headers_raw`].
46    pub fn set_headers(&self, val: &web_sys::Headers) {
47        self.set_headers_raw(val.clone().into())
48    }
49}