wip
This commit is contained in:
parent
b5902d67ea
commit
e866009491
3 changed files with 32 additions and 11 deletions
1
.vscode/settings.json
vendored
Normal file
1
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
|
@ -3,9 +3,11 @@
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
- [x] send messages from one client to another
|
- [x] send messages from one client to another
|
||||||
- [ ] save messages to database
|
- [ ] rooms
|
||||||
|
- [ ] permission model
|
||||||
|
- [ ] save connection info to local storage db
|
||||||
- [ ] get rid of unwraps
|
- [ ] get rid of unwraps
|
||||||
- [ ] handle disconnect correctly
|
- [x] handle disconnect correctly
|
||||||
- [ ] user accounts
|
- [ ] user accounts
|
||||||
- [ ] retrieve history
|
- [ ] retrieve history
|
||||||
- [ ] notifications
|
- [ ] notifications
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
|
#[allow(unused_imports, dead_code)]
|
||||||
mod prisma;
|
mod prisma;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -20,7 +21,10 @@ use common::{ClientMessage, Message};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use prisma::PrismaClient;
|
use prisma::PrismaClient;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use tokio::sync::broadcast::{self, Sender};
|
use tokio::{
|
||||||
|
select,
|
||||||
|
sync::broadcast::{self, Sender},
|
||||||
|
};
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref AUTH_CHALLENGES: DashMap<String, String> = DashMap::new();
|
static ref AUTH_CHALLENGES: DashMap<String, String> = DashMap::new();
|
||||||
|
@ -35,7 +39,7 @@ struct AppState {
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let client = PrismaClient::_builder().build().await?;
|
let client = PrismaClient::_builder().build().await?;
|
||||||
let (room_tx, room_rx) = broadcast::channel::<Message>(10_000);
|
let (room_tx, _room_rx) = broadcast::channel::<Message>(10_000);
|
||||||
|
|
||||||
let state = AppState {
|
let state = AppState {
|
||||||
client: Arc::new(client),
|
client: Arc::new(client),
|
||||||
|
@ -96,9 +100,11 @@ async fn event_stream(
|
||||||
let mut room_rx = room_tx.subscribe();
|
let mut room_rx = room_tx.subscribe();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let result = room_rx.recv().await.unwrap();
|
select! {
|
||||||
println!("Received message: {result:?}");
|
result = room_rx.recv() => {
|
||||||
let payload = serde_json::to_string(&result).unwrap();
|
let whatever = result.unwrap();
|
||||||
|
println!("Received message: {whatever:?}");
|
||||||
|
let payload = serde_json::to_string(&whatever).unwrap();
|
||||||
match socket.send(WsMessage::Text(payload)).await {
|
match socket.send(WsMessage::Text(payload)).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -106,4 +112,16 @@ async fn event_stream(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
socket_read = socket.recv() => {
|
||||||
|
match socket_read {
|
||||||
|
Some(_) => {}
|
||||||
|
None => {
|
||||||
|
// The client disconnected, handle gracefully
|
||||||
|
// TODO: Is there any cleanup to do here
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue