From 791abadab5847e03d34e3a287042f816c3c16acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 18 Sep 2020 16:58:53 +0300 Subject: [PATCH] Add creation date and number of listeners to the room listing --- Cargo.lock | 39 +++++++++++++++++++++++++++++++++++---- common/Cargo.toml | 1 + common/src/api.rs | 3 +++ server/Cargo.toml | 1 + server/src/api.rs | 2 ++ server/src/rooms.rs | 7 ++++++- server/static/index.html | 2 ++ server/static/scripts.js | 17 +++++++++++++++-- 8 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50a31f2..3642b13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,7 +143,7 @@ dependencies = [ "serde_urlencoded", "sha-1", "slab", - "time", + "time 0.2.18", ] [[package]] @@ -330,7 +330,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "socket2", - "time", + "time 0.2.18", "tinyvec", "url", ] @@ -595,6 +595,18 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "chrono" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" +dependencies = [ + "num-integer", + "num-traits", + "serde", + "time 0.1.44", +] + [[package]] name = "clap" version = "2.33.3" @@ -632,7 +644,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1373a16a4937bc34efec7b391f9c1500c30b8478a701a4f44c9165cc0475a6e0" dependencies = [ "percent-encoding", - "time", + "time 0.2.18", "version_check 0.9.2", ] @@ -921,7 +933,7 @@ checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", ] [[package]] @@ -2115,6 +2127,17 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi 0.3.9", +] + [[package]] name = "time" version = "0.2.18" @@ -2453,6 +2476,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasm-bindgen" version = "0.2.68" @@ -2533,6 +2562,7 @@ dependencies = [ name = "webrtc-audio-publishing" version = "0.1.0" dependencies = [ + "chrono", "serde", "uuid", ] @@ -2548,6 +2578,7 @@ dependencies = [ "actix-web", "actix-web-actors", "anyhow", + "chrono", "env_logger", "futures", "glib", diff --git a/common/Cargo.toml b/common/Cargo.toml index ffb08bb..c1c0aac 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -8,4 +8,5 @@ license = "MIT" [dependencies] serde = "1" uuid = { version = "0.8", features = ["serde"] } +chrono = { version = "0.4", features = ["serde"] } diff --git a/common/src/api.rs b/common/src/api.rs index ca523b2..ec68d66 100644 --- a/common/src/api.rs +++ b/common/src/api.rs @@ -16,4 +16,7 @@ pub struct Room { pub id: uuid::Uuid, pub name: String, pub description: Option, + pub number_of_subscribers: u32, + #[serde(with = "chrono::serde::ts_seconds")] + pub creation_date: chrono::DateTime, } diff --git a/server/Cargo.toml b/server/Cargo.toml index e5ebe03..973da0e 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -27,4 +27,5 @@ serde = "1" serde_json = "1" structopt = "0.3" uuid = { version = "0.8", features = ["v4"] } +chrono = "0.4" webrtc-audio-publishing = { path = "../common" } diff --git a/server/src/api.rs b/server/src/api.rs index d57e25d..f80eaa1 100644 --- a/server/src/api.rs +++ b/server/src/api.rs @@ -34,6 +34,8 @@ pub async fn rooms(rooms: web::Data>) -> Result, - // TODO: creation date, number of listeners + pub number_of_subscribers: u32, + pub creation_date: chrono::DateTime, } impl Message for RoomInformationMessage { @@ -185,6 +186,7 @@ pub struct Room { id: RoomId, name: String, description: Option, + creation_date: chrono::DateTime, rooms: WeakAddr, @@ -205,6 +207,7 @@ impl Room { id: RoomId(uuid::Uuid::new_v4()), name, description, + creation_date: chrono::Utc::now(), publisher, subscribers: HashSet::new(), } @@ -305,6 +308,8 @@ impl Handler for Room { id: self.id, name: self.name.clone(), description: self.description.clone(), + number_of_subscribers: self.subscribers.len() as u32, + creation_date: self.creation_date, }) } } diff --git a/server/static/index.html b/server/static/index.html index 8749f5b..4d25be8 100644 --- a/server/static/index.html +++ b/server/static/index.html @@ -14,6 +14,8 @@ Name Description + Creation Date + Listeners diff --git a/server/static/scripts.js b/server/static/scripts.js index 3593b27..577eb24 100644 --- a/server/static/scripts.js +++ b/server/static/scripts.js @@ -37,6 +37,8 @@ function updateRooms() { const tbody = document.createElement('tbody'); var found_playing_room = false; + // TODO: Sort rooms by name, include number of listeners and + // creation date rooms.forEach(room => { const tr = document.createElement('tr'); tr.id = room.id; @@ -49,6 +51,16 @@ function updateRooms() { td_description.textContent = room.description; tr.appendChild(td_description); + const td_creation_date = document.createElement('td'); + const date = new Date(0); + date.setUTCSeconds(room.creation_date); + td_creation_date.textContent = date.toISOString(); + tr.appendChild(td_creation_date); + + const td_number_of_subscribers = document.createElement('td'); + td_number_of_subscribers.textContent = room.number_of_subscribers; + tr.appendChild(td_number_of_subscribers); + const td_play = document.createElement('td'); const play_button = document.createElement('button'); play_button.type = 'button'; @@ -99,11 +111,12 @@ function updateRooms() { function playRoom(id) { if (playing_room != null && playing_room != id) { pauseRoom(); + // TODO: Wait until this is actually done } console.debug('playing ' + id); websocket.send(JSON.stringify({ - 'join_room': { + 'joinroom': { 'id': id } })); @@ -126,7 +139,7 @@ function pauseRoom() { // TODO: Stop playback - websocket.send(JSON.stringify('leave_room')); + websocket.send(JSON.stringify('leaveroom')); const play_button = document.getElementById('playButton-' + playing_room); play_button.textContent = 'Play'; -- GitLab