#![allow(clippy::rc_buffer)]
#![warn(clippy::complexity)]
#![warn(clippy::style)]
#![warn(clippy::perf)]
#![warn(clippy::correctness)]
macro_rules! spawn_scoped {
($e:expr) => {
crossbeam_utils::thread::scope(|s| {
s.spawn(|_| $e);
})
.unwrap();
};
}
pub mod asynchronous;
mod callback;
pub mod client;
pub mod header;
pub mod packet;
pub(self) mod socket;
pub mod transport;
pub mod transports;
pub const ENGINE_IO_VERSION: i32 = 4;
pub mod error;
pub use client::{Client, ClientBuilder};
pub use error::Error;
pub use packet::{Packet, PacketId};
#[cfg(test)]
pub(crate) mod test {
use super::*;
use native_tls::TlsConnector;
const CERT_PATH: &str = "../ci/cert/ca.crt";
use native_tls::Certificate;
use std::fs::File;
use std::io::Read;
pub(crate) fn tls_connector() -> error::Result<TlsConnector> {
let cert_path = std::env::var("CA_CERT_PATH").unwrap_or_else(|_| CERT_PATH.to_owned());
let mut cert_file = File::open(cert_path)?;
let mut buf = vec![];
cert_file.read_to_end(&mut buf)?;
let cert: Certificate = Certificate::from_pem(&buf[..]).unwrap();
Ok(TlsConnector::builder()
.danger_accept_invalid_hostnames(true)
.add_root_certificate(cert)
.build()
.unwrap())
}
const SERVER_URL: &str = "http://localhost:4201";
const SERVER_POLLING_URL: &str = "http://localhost:4203";
const SERVER_URL_SECURE: &str = "https://localhost:4202";
use url::Url;
pub(crate) fn engine_io_server() -> crate::error::Result<Url> {
let url = std::env::var("ENGINE_IO_SERVER").unwrap_or_else(|_| SERVER_URL.to_owned());
Ok(Url::parse(&url)?)
}
pub(crate) fn engine_io_polling_server() -> crate::error::Result<Url> {
let url = std::env::var("ENGINE_IO_POLLING_SERVER")
.unwrap_or_else(|_| SERVER_POLLING_URL.to_owned());
Ok(Url::parse(&url)?)
}
pub(crate) fn engine_io_server_secure() -> crate::error::Result<Url> {
let url = std::env::var("ENGINE_IO_SECURE_SERVER")
.unwrap_or_else(|_| SERVER_URL_SECURE.to_owned());
Ok(Url::parse(&url)?)
}
}