diff --git a/Cargo.lock b/Cargo.lock index 50a31f25e888d22c01983f86543489ead9bb232e..3642b1300d96b812711ceb957e3bd28c8ac2126a 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 ffb08bb1b9c8c32b47173235253fbfda817a4a24..c1c0aacdd94b599475e646250b5c36daa2c061e7 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 ca523b244fed6c6ccfdde62ad75592390481ccee..ec68d66fb4936f00424f5081451b09dabd7b115a 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 e5ebe039610ea40c2de3216a293c35472ef7ca50..973da0eccb97ac7c3da5d9f539a0b832893e4cb4 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 d57e25d367b633b364e67b8cd8520efff18cb0c0..f80eaa19a18defb98459c542851fb8a647643dab 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 8749f5b2565bcfa3e52f9ab5017108cc3022451c..4d25be888dc5e496e3d9f9e2b50446f3677c35f2 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 3593b270a5602cff8ab4c45b6658382064f1423d..577eb242902138544630ce38df9f78643bf4317d 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';