Client: WIP GUI
This commit is contained in:
parent
88aacacb19
commit
c14f3c4558
3 changed files with 32 additions and 12 deletions
5
src/client/events.rs
Normal file
5
src/client/events.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum ChatAppEvent {
|
||||||
|
ConnectButtonPress,
|
||||||
|
HostTextInputChanged(String)
|
||||||
|
}
|
|
@ -1,10 +1,11 @@
|
||||||
mod websocket;
|
mod websocket;
|
||||||
|
mod events;
|
||||||
|
|
||||||
use iced::widget::{column, Column, button, text_input, text};
|
use iced::widget::{column, Column, button, text_input, text};
|
||||||
use iced::{Application, Command, Element, Pixels, settings::Settings};
|
use iced::{Application, Command, Element, Pixels, settings::Settings};
|
||||||
use iced_futures::Subscription;
|
use iced_futures::Subscription;
|
||||||
use websocket::websocket;
|
use websocket::{websocket, AppWebsocketConfig};
|
||||||
use crate::websocket::AppWebsocketConfig;
|
use events::ChatAppEvent;
|
||||||
|
|
||||||
fn main() -> iced::Result {
|
fn main() -> iced::Result {
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
|
@ -25,12 +26,6 @@ struct ChatApp {
|
||||||
host: String
|
host: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
enum ChatAppEvent {
|
|
||||||
ConnectButtonPress,
|
|
||||||
HostTextInputChanged(String)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ChatApp {
|
impl ChatApp {
|
||||||
fn view_auth(&self) -> Element<<ChatApp as Application>::Message> {
|
fn view_auth(&self) -> Element<<ChatApp as Application>::Message> {
|
||||||
column![
|
column![
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
|
use futures_util::stream::{SplitSink, SplitStream};
|
||||||
|
use futures_util::StreamExt;
|
||||||
use iced::subscription::{Subscription, channel};
|
use iced::subscription::{Subscription, channel};
|
||||||
|
use tokio::net::TcpStream;
|
||||||
|
use tokio_tungstenite::{connect_async, MaybeTlsStream, WebSocketStream};
|
||||||
|
use crate::events::ChatAppEvent;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug)]
|
||||||
pub enum AppWebsocketState {
|
pub enum AppWebsocketState {
|
||||||
Disconnected,
|
Disconnected,
|
||||||
Connected
|
Error(String),
|
||||||
|
Connected(SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, tokio_tungstenite::tungstenite::Message>, SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
@ -23,7 +29,7 @@ impl AppWebsocketConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn websocket(config: AppWebsocketConfig) -> Subscription<super::ChatAppEvent> {
|
pub fn websocket(config: AppWebsocketConfig) -> Subscription<ChatAppEvent> {
|
||||||
struct Websocket;
|
struct Websocket;
|
||||||
|
|
||||||
channel(
|
channel(
|
||||||
|
@ -33,7 +39,21 @@ pub fn websocket(config: AppWebsocketConfig) -> Subscription<super::ChatAppEvent
|
||||||
let mut state = AppWebsocketState::Disconnected;
|
let mut state = AppWebsocketState::Disconnected;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
match &state {
|
||||||
|
AppWebsocketState::Disconnected => {
|
||||||
|
match connect_async(&config.host).await {
|
||||||
|
Ok((conn, res)) => {
|
||||||
|
let (ws_recv, ws_send) = conn.split();
|
||||||
|
state = AppWebsocketState::Connected(ws_recv, ws_send);
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
state = AppWebsocketState::Error(err.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AppWebsocketState::Connected(ws_recv, ws_send) => {}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue