I think I might be sending the first command over the socket.

master
Tom Alexander 2 years ago
parent 41d5f980ef
commit d56a7f32b6
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -10,3 +10,5 @@ walkdir = "2.3.2"
sqlx = { version = "0.5", features = [ "runtime-tokio-rustls", "sqlite", "migrate" ] }
tokio = { version = "1.16.1", features = ["full"] }
dirs = "4.0.0"
serde_json = "1.0.79"
serde = { version = "1.0.136", features= ["derive"] }

@ -8,6 +8,8 @@ use tokio::process::Command;
use walkdir::DirEntry;
use walkdir::WalkDir;
mod mpvctl;
use crate::mpvctl::MpvCtl;
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -43,6 +45,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
launch_mpv().await?;
sleep(Duration::from_secs(10)).await;
let mut mpvctl = MpvCtl::connect("/tmp/recordwatchsocket").await?;
mpvctl.get_client_name().await?;
println!("done");
Ok(())
}

@ -1,9 +1,35 @@
use serde::ser::SerializeMap;
use serde::{Deserialize, Serialize, Serializer};
pub struct Command {
command: Vec<String>,
request_id: Option<u64>,
asynchronous: bool,
}
impl Command {
pub fn new(command: Vec<String>) -> Self {
Command { command: command }
pub fn new(command: Vec<String>, request_id: Option<u64>) -> Self {
Command {
command,
request_id,
asynchronous: false,
}
}
}
impl Serialize for Command {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("command", &self.command)?;
self.request_id
.map(|reqid| map.serialize_entry("request_id", &reqid))
.map_or(Ok(None), |x| x.map(Some))?;
if self.asynchronous {
map.serialize_entry("async", &self.asynchronous)?;
}
map.end()
}
}

@ -1,5 +1,8 @@
use std::collections::HashMap;
use std::io::Read;
use std::os::unix::prelude::OsStrExt;
use std::{collections::BTreeMap, path::Path};
use tokio::io::AsyncWriteExt;
use tokio::net::UnixStream;
use super::command::Command;
@ -26,14 +29,17 @@ impl MpvCtl {
ret
}
async fn send_command(&self, cmd: Command) {
//
// let serialized =
async fn send_command(&mut self, cmd: Command) -> Result<(), Box<dyn std::error::Error>> {
let serialized = serde_json::to_string(&cmd)?;
println!("Sending {}", serialized);
self.socket.write_all(serialized.as_bytes()).await?;
Ok(())
}
pub async fn get_client_name(&mut self) -> Result<(), Box<dyn std::error::Error>> {
let request_id = self.grab_request_id();
let cmd = Command::new(vec!["client_name".to_string()]);
let cmd = Command::new(vec!["client_name".to_string()], Some(request_id));
self.send_command(cmd).await?;
Ok(())
}
}

Loading…
Cancel
Save