| skipped 2 lines |
3 | 3 | | use std::io::{self, BufRead}; |
4 | 4 | | use sysinfo::{PidExt, ProcessExt, SystemExt}; |
5 | 5 | | use sysinfo::{ProcessRefreshKind, RefreshKind, System}; |
6 | | - | use websocket::{ClientBuilder, Message}; |
| 6 | + | use websocket::{ClientBuilder, Message, OwnedMessage}; |
7 | 7 | | |
8 | 8 | | mod protocol; |
9 | 9 | | |
| skipped 109 lines |
119 | 119 | | /// Execute a custom request payload, use '-' to read from stdin. |
120 | 120 | | #[clap(long)] |
121 | 121 | | custom_payload: Option<String>, |
| 122 | + | /// Poll variable by name at regular intervals. |
| 123 | + | #[clap(long)] |
| 124 | + | poll_variable: Option<String>, |
122 | 125 | | } |
123 | 126 | | |
124 | 127 | | fn main() { |
| skipped 103 lines |
228 | 231 | | println!("payload sent!"); |
229 | 232 | | |
230 | 233 | | println!("reading events, press ctrl+c to exit ...\n"); |
| 234 | + | |
| 235 | + | let varialble_payload = args.poll_variable.map(|name| { |
| 236 | + | serde_json::to_string(&protocol::requests::RuntimeEval::new(&format!( |
| 237 | + | "JSON.stringify({})", |
| 238 | + | name |
| 239 | + | ))) |
| 240 | + | .unwrap() |
| 241 | + | }); |
| 242 | + | |
231 | 243 | | loop { |
232 | | - | println!("{:?}", client.recv_message().unwrap()); |
| 244 | + | if let Some(poll_payload) = &varialble_payload { |
| 245 | + | client.send_message(&Message::text(poll_payload)).unwrap(); |
| 246 | + | |
| 247 | + | let resp = client.recv_message().unwrap(); |
| 248 | + | if let OwnedMessage::Text(data) = resp { |
| 249 | + | println!("{}", data); |
| 250 | + | } else { |
| 251 | + | println!("got non text message: {:?}", resp); |
| 252 | + | } |
| 253 | + | |
| 254 | + | std::thread::sleep(std::time::Duration::from_secs(1)); |
| 255 | + | } else { |
| 256 | + | println!("{:?}", client.recv_message().unwrap()); |
| 257 | + | } |
233 | 258 | | } |
234 | 259 | | } |
235 | 260 | | |