diff --git a/crates/recording/src/camera.rs b/crates/recording/src/camera.rs new file mode 100644 index 0000000000..98ff59a770 --- /dev/null +++ b/crates/recording/src/camera.rs @@ -0,0 +1,48 @@ +// File: crates/recording/src/camera.rs +use cap_recording::CameraFeed; +use cap_utils::Url; +use std::collections::HashMap; + +pub struct Camera { + pub feed: CameraFeed, + pub deeplink_handler: DeeplinkHandler, +} + +impl Camera { + pub fn new() -> Self { + Self { + feed: CameraFeed::new(), + deeplink_handler: DeeplinkHandler::new(), + } + } + + pub fn start_recording(&self) { + let deeplink = self.deeplink_handler.handle_deeplink("recording_start".to_string()).unwrap(); + println!("{}", deeplink.recording_start()); + } + + pub fn stop_recording(&self) { + let deeplink = self.deeplink_handler.handle_deeplink("recording_stop".to_string()).unwrap(); + println!("{}", deeplink.recording_stop()); + } + + pub fn pause_recording(&self) { + let deeplink = self.deeplink_handler.handle_deeplink("recording_pause".to_string()).unwrap(); + println!("{}", deeplink.recording_pause()); + } + + pub fn resume_recording(&self) { + let deeplink = self.deeplink_handler.handle_deeplink("recording_resume".to_string()).unwrap(); + println!("{}", deeplink.recording_resume()); + } + + pub fn switch_camera(&self) { + let deeplink = self.deeplink_handler.handle_deeplink("camera_switch".to_string()).unwrap(); + println!("{}", deeplink.camera_switch()); + } + + pub fn switch_microphone(&self) { + let deeplink = self.deeplink_handler.handle_deeplink("microphone_switch".to_string()).unwrap(); + println!("{}", deeplink.microphone_switch()); + } +} \ No newline at end of file diff --git a/crates/recording/src/cap_recording.rs b/crates/recording/src/cap_recording.rs new file mode 100644 index 0000000000..4e170a2e7b --- /dev/null +++ b/crates/recording/src/cap_recording.rs @@ -0,0 +1,8 @@ +// File: crates/recording/src/cap_recording.rs + +use cap_recording::CameraFeed; +use cap_utils::Url; +use std::collections::HashMap; + +// Removed the unnecessary and circular module declaration +// pub mod cap_recording; \ No newline at end of file diff --git a/crates/recording/src/cap_utils.rs b/crates/recording/src/cap_utils.rs new file mode 100644 index 0000000000..8b32e5c8ae --- /dev/null +++ b/crates/recording/src/cap_utils.rs @@ -0,0 +1,31 @@ +// File: crates/recording/src/cap_utils.rs +use std::collections::HashMap; + +pub struct Url { + url: String, +} + +impl Url { + pub fn parse(s: &str) -> Result { + // Simplified parsing logic + if s.is_empty() || !s.contains("://") { + return Err(std::fmt::Error); + } + Ok(Url { url: s.to_string() }) + } + + pub fn join(&self, path: &str) -> Result { + if path.is_empty() { + return Ok(Url { + url: self.url.clone(), + }); + } + let sep = if self.url.ends_with('/') || path.starts_with('/') { + "" + } else { + "/" + }; + let joined = format!("{}{}{}", self.url, sep, path); + Url::parse(&joined) + } +} \ No newline at end of file diff --git a/crates/recording/src/deeplink.rs b/crates/recording/src/deeplink.rs new file mode 100644 index 0000000000..df1680f107 --- /dev/null +++ b/crates/recording/src/deeplink.rs @@ -0,0 +1,37 @@ +// File: crates/recording/src/deeplink.rs +use cap_utils::Url; +use std::collections::HashMap; + +pub struct Deeplink { + pub url: Url, +} + +impl Deeplink { + pub fn new(url: Url) -> Self { + Self { url } + } + + pub fn recording_start(&self) -> Url { + self.url.join("recording/start").unwrap() + } + + pub fn recording_stop(&self) -> Url { + self.url.join("recording/stop").unwrap() + } + + pub fn recording_pause(&self) -> Url { + self.url.join("recording/pause").unwrap() + } + + pub fn recording_resume(&self) -> Url { + self.url.join("recording/resume").unwrap() + } + + pub fn camera_switch(&self) -> Url { + self.url.join("camera/switch").unwrap() + } + + pub fn microphone_switch(&self) -> Url { + self.url.join("microphone/switch").unwrap() + } +} \ No newline at end of file diff --git a/crates/recording/src/deeplink_handler.rs b/crates/recording/src/deeplink_handler.rs new file mode 100644 index 0000000000..8f8bdc13dd --- /dev/null +++ b/crates/recording/src/deeplink_handler.rs @@ -0,0 +1,23 @@ +use cap_recording::CameraFeed; +use cap_utils::Url; +use std::collections::HashMap; + +pub struct DeeplinkHandler { + pub deeplinks: HashMap, +} + +impl DeeplinkHandler { + pub fn new() -> Self { + Self { + deeplinks: HashMap::new(), + } + } + + pub fn register_deeplink(&mut self, name: String, deeplink: Deeplink) { + self.deeplinks.insert(name, deeplink); + } + + pub fn handle_deeplink(&self, name: String) -> Option<&Deeplink> { + self.deeplinks.get(&name) + } +} \ No newline at end of file diff --git a/crates/recording/src/main.rs b/crates/recording/src/main.rs new file mode 100644 index 0000000000..6c75f0869e --- /dev/null +++ b/crates/recording/src/main.rs @@ -0,0 +1,13 @@ +use cap_recording::CameraFeed; +use cap_utils::Url; +use std::collections::HashMap; + +pub fn main() { + let camera = Camera::new(); + camera.start_recording(); + camera.stop_recording(); + camera.pause_recording(); + camera.resume_recording(); + camera.switch_camera(); + camera.switch_microphone(); +} \ No newline at end of file