use tokio::net::TcpStream;
use crate::{
connect::{DnsConfig, ServerConnector},
proto::XmppStream,
Client, Component, Error,
};
pub type TcpComponent = Component<TcpServerConnector>;
pub type TcpClient = Client<TcpServerConnector>;
#[derive(Debug, Clone)]
pub struct TcpServerConnector(pub DnsConfig);
impl From<DnsConfig> for TcpServerConnector {
fn from(dns_config: DnsConfig) -> TcpServerConnector {
Self(dns_config)
}
}
impl ServerConnector for TcpServerConnector {
type Stream = TcpStream;
async fn connect(
&self,
jid: &xmpp_parsers::jid::Jid,
ns: &str,
) -> Result<XmppStream<Self::Stream>, Error> {
let stream = self.0.resolve().await?;
Ok(XmppStream::start(stream, jid.clone(), ns.to_owned()).await?)
}
}