initial commit. WIP
commit
fd0d9127c8
|
@ -0,0 +1,9 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = false
|
||||
insert_final_newline = true
|
|
@ -0,0 +1 @@
|
|||
/target
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "watch-party-2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
axum = { version = "0.6.12", features = ["ws"] }
|
||||
confique = "0.2.3"
|
||||
miette = { version = "5.7.0", features = ["fancy"] }
|
||||
serde = { version = "1.0.160", features = ["derive"] }
|
||||
tokio = { version = "1.27.0", features = ["full"] }
|
||||
tower-http = { version = "0.4.0", features = ["fs"] }
|
||||
futures = "0.3"
|
||||
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
|
||||
uuid = { version = "1.3.1", features = ["v4", "serde"] }
|
||||
once_cell = "1.17.1"
|
|
@ -0,0 +1,54 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
use axum::{
|
||||
extract::{ws::WebSocket, Query, WebSocketUpgrade},
|
||||
response::{IntoResponse, Response},
|
||||
routing::get,
|
||||
Router, Server,
|
||||
};
|
||||
use confique::Config;
|
||||
use miette::{Context, IntoDiagnostic, Result};
|
||||
use serde::Deserialize;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
mod rooms;
|
||||
mod sources;
|
||||
|
||||
#[derive(Config)]
|
||||
struct WatchPartyConfig {
|
||||
#[config(env = "PORT", default = 3000)]
|
||||
port: u16,
|
||||
#[config(default = "127.0.0.1")]
|
||||
address: IpAddr,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct WsQuery {
|
||||
room: String,
|
||||
}
|
||||
|
||||
async fn handle_socket(socket: WebSocket, room: String) {}
|
||||
|
||||
async fn ws_handler(ws: WebSocketUpgrade, Query(q): Query<WsQuery>) -> Response {
|
||||
ws.on_upgrade(move |s| handle_socket(s, q.room))
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let conf = WatchPartyConfig::builder()
|
||||
.env()
|
||||
.file("watch-party.toml")
|
||||
.load()
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to load the application config.")?;
|
||||
|
||||
let app = Router::new()
|
||||
.fallback_service(ServeDir::new("public"))
|
||||
.route("/api/ws", get(ws_handler));
|
||||
|
||||
let bind_address: SocketAddr = (conf.address, conf.port).into();
|
||||
Server::bind(&bind_address)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.into_diagnostic()
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use axum::extract::ws::WebSocket;
|
||||
use miette::Result;
|
||||
use once_cell::sync::Lazy;
|
||||
use serde::Serialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::sources::MediaSource;
|
||||
|
||||
// TODO: How do we store the active rooms?
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Room {
|
||||
pub id: Uuid,
|
||||
pub playlist: Vec<MediaSource>,
|
||||
// TODO: Currently playing information
|
||||
#[serde(skip)]
|
||||
pub members: Vec<Member>,
|
||||
}
|
||||
|
||||
pub struct Member {
|
||||
pub id: Uuid,
|
||||
pub nickname: Option<String>,
|
||||
pub socket: WebSocket,
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct DirectMediaSource {
|
||||
pub video_url: String,
|
||||
pub tracks: Vec<DirectMediaTrack>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct DirectMediaTrack {
|
||||
pub name: String,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct YouTubeMediaSource {
|
||||
pub video_id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(tag = "type", content = "data")]
|
||||
pub enum MediaSource {
|
||||
Direct(DirectMediaSource),
|
||||
YouTube(YouTubeMediaSource),
|
||||
}
|
Loading…
Reference in New Issue