pub async fn from_stream_and_sink(
        stream: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
        mut sink: SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>,
        config: WebOsClientConfig,
    ) -> Result<WebosClient, String> {
        let next_command_id = Arc::from(Mutex::from(0));
        let ongoing_requests = Arc::from(Mutex::from(HashMap::new()));
        let requests_to_process = ongoing_requests.clone();
        let (registration_promise, registration_pinky) = PinkySwear::<Option<String>>::new();
        tokio::spawn(async move {
            process_messages_from_server(stream, requests_to_process, registration_pinky).await
        });

        let mut handshake = get_handshake();
        // Check to see if the config has a key, if it does, add it to the handshake.
        if let Some(key) = config.key {
            handshake["payload"]["client-key"] = Value::from(key);
        }
        let formatted_handshake = format!("{}", handshake);
        sink.send(Message::text(formatted_handshake)).await.unwrap();
        let key = registration_promise.await;
        Ok(WebosClient {
            write: RefCell::new(sink),
            next_command_id,
            ongoing_requests,
            key,
        })
    }
/// Creates client using provided stream and sink
Creates client using provided stream and sink
Creates client using provided stream and sink
pub async fn from_stream_and_sink(
        stream: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
        mut sink: SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>,
        config: WebOsClientConfig,
    ) -> Result<WebosClient, String> {
        let next_command_id = Arc::from(Mutex::from(0));
        let ongoing_requests = Arc::from(Mutex::from(HashMap::new()));
        let requests_to_process = ongoing_requests.clone();
        let (registration_promise, registration_pinky) = PinkySwear::<Option<String>>::new();
        tokio::spawn(async move {
            process_messages_from_server(stream, requests_to_process, registration_pinky).await
        });
        let mut handshake = get_handshake();
        // Check to see if the config has a key, if it does, add it to the handshake.
        if let Some(key) = config.key {
            handshake["payload"]["client-key"] = Value::from(key);
        }
        let formatted_handshake = format!("{}", handshake);
        sink.send(Message::text(formatted_handshake)).await.unwrap();
        let key = registration_promise.await;
        Ok(WebosClient {
            write: RefCell::new(sink),
            next_command_id,
            ongoing_requests,
            key,
        })
    }
pub async fn from_stream_and_sink ( stream : SplitStream < WebSocketStream < MaybeTlsStream < TcpStream > > > , mut sink : SplitSink < WebSocketStream < MaybeTlsStream < TcpStream > > , Message > , config : WebOsClientConfig , ) -> Result < WebosClient , String > { let next_command_id = Arc :: from ( Mutex :: from ( 0 ) ) ; let ongoing_requests = Arc :: from ( Mutex :: from ( HashMap :: new ( ) ) ) ; let requests_to_process = ongoing_requests . clone ( ) ; let ( registration_promise , registration_pinky ) = PinkySwear :: < Option < String > > :: new ( ) ; tokio :: spawn ( async move { process_messages_from_server ( stream , requests_to_process , registration_pinky ) . await } ) ; let mut handshake = get_handshake ( ) ; // Check to see if the config has a key, if it does, add it to the handshake. if let Some ( key ) = config . key { handshake [ " " ] [ " " ] = Value :: from ( key ) ; } let formatted_handshake = format ! ( " " handshake ) ; sink . send ( Message :: text ( formatted_handshake ) ) . await . unwrap ( ) ; let key = registration_promise . await ; Ok ( WebosClient { write : RefCell :: new ( sink ) , next_command_id , ongoing_requests , key , } ) }
Creates client using provided stream and sink
Creates client using provided stream and sink
stream
SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>
sink
SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>
config
WebOsClientConfig
stream
SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>
sink
SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>
config
WebOsClientConfig