#![cfg_attr(
feature = "server",
doc = "Feature `server`: [`server::Connection`], a session driver that turns
incoming text frames into [`jmap_server::Dispatcher`] calls and writes
the answers and push notifications back, over any `Stream` and `Sink`
of messages, so it fits axum, tokio-tungstenite or another stack. Also
[`server::PushHub`], an in-memory state-change source with `pushState`
replay, and [`server::ExtensionHandler`], the hook for the extension
message types of the JMAP Chat, VTC and Scene WebSocket drafts.
"
)]
#![cfg_attr(
not(feature = "server"),
doc = "Feature `server`: `server::Connection`, a session driver that turns
incoming text frames into `jmap_server::Dispatcher` calls and writes
the answers and push notifications back, over any `Stream` and `Sink`
of messages, so it fits axum, tokio-tungstenite or another stack. Also
`server::PushHub`, an in-memory state-change source with `pushState`
replay, and `server::ExtensionHandler`, the hook for the extension
message types of the JMAP Chat, VTC and Scene WebSocket drafts.
"
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code)]
mod capability;
mod frame;
#[cfg(feature = "server")]
pub mod server;
#[cfg(feature = "tungstenite")]
pub mod tungstenite;
pub use capability::WebSocketCapability;
pub use frame::{
ClientMessage, ServerMessage, WebSocketPushDisable, WebSocketPushEnable, WsRequest,
WsRequestError, WsResponse, WsStateChange,
};
pub use jmap_types;
#[cfg(feature = "server")]
pub use futures;
#[cfg(feature = "server")]
pub use jmap_server;
#[cfg(feature = "tungstenite")]
pub use tokio_tungstenite;
pub const CAPABILITY: &str = "urn:ietf:params:jmap:websocket";
pub const SUBPROTOCOL: &str = "jmap";
pub fn offers_jmap(header_value: &str) -> bool {
header_value.split(',').any(|t| t.trim() == SUBPROTOCOL)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn constants_match_rfc_8887() {
assert_eq!(CAPABILITY, "urn:ietf:params:jmap:websocket");
assert_eq!(SUBPROTOCOL, "jmap");
}
#[test]
fn offers_jmap_reads_the_token_list() {
assert!(offers_jmap("jmap"));
assert!(offers_jmap("soap,jmap"));
assert!(offers_jmap(" soap , jmap "));
assert!(!offers_jmap("soap"));
assert!(!offers_jmap("jmapx"));
assert!(!offers_jmap(""));
}
}