Fix compiling for WASM with websockets disabled (#934)

* Fix compiling for WASM with websockets disabled

* Comment about usage
This commit is contained in:
Pierre Krieger
2019-02-11 17:45:22 +01:00
committed by GitHub
parent eeed66707b
commit e377a58b49
3 changed files with 125 additions and 2 deletions

View File

@ -244,8 +244,10 @@ struct CommonTransport {
type InnerImplementation = core::transport::OrTransport<dns::DnsConfig<tcp::TcpConfig>, websocket::WsConfig<dns::DnsConfig<tcp::TcpConfig>>>;
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), not(feature = "libp2p-websocket")))]
type InnerImplementation = dns::DnsConfig<tcp::TcpConfig>;
#[cfg(any(target_os = "emscripten", target_os = "unknown"))]
#[cfg(all(any(target_os = "emscripten", target_os = "unknown"), feature = "libp2p-websocket"))]
type InnerImplementation = websocket::BrowserWsConfig;
#[cfg(all(any(target_os = "emscripten", target_os = "unknown"), not(feature = "libp2p-websocket")))]
type InnerImplementation = core::transport::dummy::DummyTransport;
#[derive(Debug, Clone)]
struct CommonTransportInner {
@ -272,13 +274,23 @@ impl CommonTransport {
/// Initializes the `CommonTransport`.
#[inline]
#[cfg(any(target_os = "emscripten", target_os = "unknown"))]
#[cfg(all(any(target_os = "emscripten", target_os = "unknown"), feature = "libp2p-websocket"))]
pub fn new() -> CommonTransport {
let inner = websocket::BrowserWsConfig::new();
CommonTransport {
inner: CommonTransportInner { inner }
}
}
/// Initializes the `CommonTransport`.
#[inline]
#[cfg(all(any(target_os = "emscripten", target_os = "unknown"), not(feature = "libp2p-websocket")))]
pub fn new() -> CommonTransport {
let inner = core::transport::dummy::DummyTransport::new();
CommonTransport {
inner: CommonTransportInner { inner }
}
}
}
impl Transport for CommonTransport {