44use std:: ops:: DerefMut ;
55use std:: pin:: Pin ;
66use std:: task:: { Context , Poll } ;
7+ use std:: time:: Duration ;
78
89#[ cfg( all( feature = "tor" , not( target_arch = "wasm32" ) ) ) ]
910use arti_client:: DataStream ;
@@ -12,10 +13,11 @@ use futures_util::{Sink, Stream};
1213use tokio:: net:: TcpStream ;
1314#[ cfg( not( target_arch = "wasm32" ) ) ]
1415use tokio_tungstenite:: { MaybeTlsStream , WebSocketStream } ;
16+ use url:: Url ;
1517
1618#[ cfg( target_arch = "wasm32" ) ]
1719use crate :: wasm:: WsStream ;
18- use crate :: { Error , Message } ;
20+ use crate :: { ConnectionMode , Error , Message } ;
1921
2022#[ cfg( not( target_arch = "wasm32" ) ) ]
2123type WsStream < T > = WebSocketStream < MaybeTlsStream < T > > ;
@@ -29,6 +31,22 @@ pub enum WebSocket {
2931 Wasm ( WsStream ) ,
3032}
3133
34+ impl WebSocket {
35+ pub async fn connect (
36+ url : & Url ,
37+ _mode : & ConnectionMode ,
38+ timeout : Duration ,
39+ ) -> Result < Self , Error > {
40+ #[ cfg( not( target_arch = "wasm32" ) ) ]
41+ let socket: WebSocket = crate :: native:: connect ( url, _mode, timeout) . await ?;
42+
43+ #[ cfg( target_arch = "wasm32" ) ]
44+ let socket: WebSocket = crate :: wasm:: connect ( url, timeout) . await ?;
45+
46+ Ok ( socket)
47+ }
48+ }
49+
3250impl Sink < Message > for WebSocket {
3351 type Error = Error ;
3452
0 commit comments