last try tungstenite
This commit is contained in:
parent
6976c72cbf
commit
75dc95aeb6
@ -9,7 +9,7 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
tokio-tungstenite = "*"
|
tungstenite = "0.9.2"
|
||||||
url = "2.1.1"
|
url = "2.1.1"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
rand = "0.7.3"
|
rand = "0.7.3"
|
||||||
|
31
src/main.rs
31
src/main.rs
@ -7,10 +7,9 @@ use std::i64;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::net;
|
use std::net;
|
||||||
use std::thread;
|
use std::thread::spawn;
|
||||||
use std::thread::sleep;
|
use std::time::Instant;
|
||||||
use std::time::{Duration, Instant};
|
use tungstenite::{connect, Error, Message};
|
||||||
use tungstenite::{connect, Error, Message, Result};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
fn listen(socket: &net::UdpSocket) {
|
fn listen(socket: &net::UdpSocket) {
|
||||||
@ -145,22 +144,22 @@ fn main() {
|
|||||||
connect(Url::parse("ws://localhost:4444/").unwrap()).expect("Could not connect to OBS");
|
connect(Url::parse("ws://localhost:4444/").unwrap()).expect("Could not connect to OBS");
|
||||||
let source_id = "LAPTIME";
|
let source_id = "LAPTIME";
|
||||||
|
|
||||||
// Setup the UDP Socket
|
spawn(move || loop {
|
||||||
let udpsocket = net::UdpSocket::bind("0.0.0.0:0").expect("failed to bind host udp socket"); // local bind port
|
|
||||||
udpsocket.set_nonblocking(true).unwrap();
|
|
||||||
|
|
||||||
let msg = String::from("ok").into_bytes();
|
|
||||||
udpsocket
|
|
||||||
.send_to(&msg, "192.168.0.141:9000")
|
|
||||||
.expect("cannot send");
|
|
||||||
|
|
||||||
loop {
|
|
||||||
listen(&udpsocket);
|
|
||||||
|
|
||||||
if let Ok(msg) = obssocket.read_message() {
|
if let Ok(msg) = obssocket.read_message() {
|
||||||
let text = msg.into_text().unwrap_or("".to_string());
|
let text = msg.into_text().unwrap_or("".to_string());
|
||||||
println!("{}", text);
|
println!("{}", text);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Setup the UDP Socket
|
||||||
|
let udpsocket = net::UdpSocket::bind("0.0.0.0:0").expect("failed to bind host udp socket"); // local bind port
|
||||||
|
udpsocket.set_nonblocking(true).unwrap();
|
||||||
|
let msg = String::from("ok").into_bytes();
|
||||||
|
udpsocket
|
||||||
|
.send_to(&msg, "192.168.0.141:9000")
|
||||||
|
.expect("cannot send");
|
||||||
|
loop {
|
||||||
|
listen(&udpsocket);
|
||||||
|
|
||||||
if now.elapsed().as_secs() >= 5 {
|
if now.elapsed().as_secs() >= 5 {
|
||||||
let request = json!({"request-type":"SetTextFreetype2Properties", "source":source_id,"message-id": random::<f64>().to_string(), "text": now.elapsed().as_millis().to_string() });
|
let request = json!({"request-type":"SetTextFreetype2Properties", "source":source_id,"message-id": random::<f64>().to_string(), "text": now.elapsed().as_millis().to_string() });
|
||||||
|
Loading…
Reference in New Issue
Block a user