Loading common/src/api.rs +4 −4 Original line number Diff line number Diff line Loading @@ -7,13 +7,13 @@ use serde::{Deserialize, Serialize}; /// Response of the `rooms` endpoint. #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub struct Rooms(Vec<Room>); pub struct Rooms(pub Vec<Room>); /// Information for one `Room #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub struct Room { id: uuid::Uuid, name: String, description: Option<String>, pub id: uuid::Uuid, pub name: String, pub description: Option<String>, } server/src/api.rs 0 → 100644 +43 −0 Original line number Diff line number Diff line // Copyright (C) 2020 Sebastian Dröge <sebastian@centricular.com> // // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> use crate::rooms::{self, Rooms}; use actix::Addr; use actix_web::{web, HttpResponse}; use log::{error, trace}; use webrtc_audio_publishing::api; pub async fn rooms(rooms: web::Data<Addr<Rooms>>) -> Result<HttpResponse, actix_web::Error> { let room_addrs = rooms.send(rooms::ListRoomsMessage).await.map_err(|err| { error!("Failed to list rooms: {}", err); HttpResponse::InternalServerError() })?; let mut room_descs = Vec::with_capacity(room_addrs.len()); for room in room_addrs { let room_desc = match room.send(rooms::RoomInformationMessage).await { Err(err) => { error!( "Failed to retrieve room information for {:?}: {:?}", room, err ); continue; } Ok(desc) => desc, }; room_descs.push(api::Room { id: room_desc.id.0, name: room_desc.name.clone(), description: room_desc.description.clone(), }); } trace!("Returning room descriptions {:?}", room_descs); Ok(HttpResponse::Ok().json(api::Rooms(room_descs))) } server/src/main.rs +1 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ // // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> mod api; mod config; mod publisher; mod rooms; Loading server/src/server.rs +4 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ // // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> use crate::api; use crate::config::Config; use crate::publisher::Publisher; use crate::rooms::Rooms; Loading @@ -9,7 +10,7 @@ use crate::subscriber::Subscriber; use actix::{Actor, Addr}; use actix_files::NamedFile; use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder}; use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer}; use actix_web_actors::ws; use log::error; Loading @@ -30,7 +31,7 @@ async fn ws( path: web::Path<String>, req: HttpRequest, stream: web::Payload, ) -> impl Responder { ) -> Result<HttpResponse, actix_web::Error> { match path.as_str() { "publish" => { let publisher = Publisher::new( Loading Loading @@ -90,6 +91,7 @@ pub async fn run(cfg: Config) -> Result<(), anyhow::Error> { .route("/", web::get().to(index)) .route("/ws/{mode:(publish|subscribe)}", web::get().to(ws)) .route("/static/{filename:.*}", web::get().to(static_file)) .route("/api/rooms", web::get().to(api::rooms)) }); let server = if cfg.use_tls { Loading server/src/subscriber.rs +3 −2 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use actix::{Actor, Addr, Handler, Message, StreamHandler, WeakAddr}; use actix_web::dev::ConnectionInfo; use actix_web_actors::ws; use log::{debug, trace}; use log::{debug, trace, warn}; /// Actor that represents a WebRTC subscriber. #[derive(Debug)] Loading Loading @@ -59,7 +59,8 @@ impl Actor for Subscriber { } impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Subscriber { fn handle(&mut self, _msg: Result<ws::Message, ws::ProtocolError>, _ctx: &mut Self::Context) { fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, _ctx: &mut Self::Context) { warn!("received {:?}", msg); // TODO } } Loading Loading
common/src/api.rs +4 −4 Original line number Diff line number Diff line Loading @@ -7,13 +7,13 @@ use serde::{Deserialize, Serialize}; /// Response of the `rooms` endpoint. #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub struct Rooms(Vec<Room>); pub struct Rooms(pub Vec<Room>); /// Information for one `Room #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub struct Room { id: uuid::Uuid, name: String, description: Option<String>, pub id: uuid::Uuid, pub name: String, pub description: Option<String>, }
server/src/api.rs 0 → 100644 +43 −0 Original line number Diff line number Diff line // Copyright (C) 2020 Sebastian Dröge <sebastian@centricular.com> // // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> use crate::rooms::{self, Rooms}; use actix::Addr; use actix_web::{web, HttpResponse}; use log::{error, trace}; use webrtc_audio_publishing::api; pub async fn rooms(rooms: web::Data<Addr<Rooms>>) -> Result<HttpResponse, actix_web::Error> { let room_addrs = rooms.send(rooms::ListRoomsMessage).await.map_err(|err| { error!("Failed to list rooms: {}", err); HttpResponse::InternalServerError() })?; let mut room_descs = Vec::with_capacity(room_addrs.len()); for room in room_addrs { let room_desc = match room.send(rooms::RoomInformationMessage).await { Err(err) => { error!( "Failed to retrieve room information for {:?}: {:?}", room, err ); continue; } Ok(desc) => desc, }; room_descs.push(api::Room { id: room_desc.id.0, name: room_desc.name.clone(), description: room_desc.description.clone(), }); } trace!("Returning room descriptions {:?}", room_descs); Ok(HttpResponse::Ok().json(api::Rooms(room_descs))) }
server/src/main.rs +1 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ // // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> mod api; mod config; mod publisher; mod rooms; Loading
server/src/server.rs +4 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ // // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> use crate::api; use crate::config::Config; use crate::publisher::Publisher; use crate::rooms::Rooms; Loading @@ -9,7 +10,7 @@ use crate::subscriber::Subscriber; use actix::{Actor, Addr}; use actix_files::NamedFile; use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder}; use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer}; use actix_web_actors::ws; use log::error; Loading @@ -30,7 +31,7 @@ async fn ws( path: web::Path<String>, req: HttpRequest, stream: web::Payload, ) -> impl Responder { ) -> Result<HttpResponse, actix_web::Error> { match path.as_str() { "publish" => { let publisher = Publisher::new( Loading Loading @@ -90,6 +91,7 @@ pub async fn run(cfg: Config) -> Result<(), anyhow::Error> { .route("/", web::get().to(index)) .route("/ws/{mode:(publish|subscribe)}", web::get().to(ws)) .route("/static/{filename:.*}", web::get().to(static_file)) .route("/api/rooms", web::get().to(api::rooms)) }); let server = if cfg.use_tls { Loading
server/src/subscriber.rs +3 −2 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use actix::{Actor, Addr, Handler, Message, StreamHandler, WeakAddr}; use actix_web::dev::ConnectionInfo; use actix_web_actors::ws; use log::{debug, trace}; use log::{debug, trace, warn}; /// Actor that represents a WebRTC subscriber. #[derive(Debug)] Loading Loading @@ -59,7 +59,8 @@ impl Actor for Subscriber { } impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Subscriber { fn handle(&mut self, _msg: Result<ws::Message, ws::ProtocolError>, _ctx: &mut Self::Context) { fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, _ctx: &mut Self::Context) { warn!("received {:?}", msg); // TODO } } Loading