+ Json-API now pushes proper new-message event to rtc server correctly
+ Rtc server takes in new-message correctly but with basically no ux/auth for now This should be fine as we can layer on security afterwards with no issue
This commit is contained in:
parent
291505201b
commit
5bbc57313f
@ -37,6 +37,7 @@ mod members;
|
|||||||
mod perms;
|
mod perms;
|
||||||
mod messages;
|
mod messages;
|
||||||
mod admin;
|
mod admin;
|
||||||
|
mod rtc;
|
||||||
|
|
||||||
mod http;
|
mod http;
|
||||||
mod testing;
|
mod testing;
|
||||||
|
@ -108,7 +108,12 @@ pub async fn send_message(pool: &Pool, response: &mut Response<Body>, body: Body
|
|||||||
else {
|
else {
|
||||||
// ctype safe unwrap
|
// ctype safe unwrap
|
||||||
match db::Message::send(pool, &content, ctype.unwrap(), channel_id.unwrap(), uid).await {
|
match db::Message::send(pool, &content, ctype.unwrap(), channel_id.unwrap(), uid).await {
|
||||||
Ok(Empty) => {/* TODO: put something here to notify the rtc server if its there*/},
|
#[cfg(feature = "rtc")]
|
||||||
|
Ok(Row(msg)) => {
|
||||||
|
use crate::rtc;
|
||||||
|
rtc::new_message(msg).await;
|
||||||
|
},
|
||||||
|
Ok(Empty) => { }, // idk anymore
|
||||||
Ok(RestrictedInput(_msg)) => *response.status_mut() = StatusCode::BAD_REQUEST,
|
Ok(RestrictedInput(_msg)) => *response.status_mut() = StatusCode::BAD_REQUEST,
|
||||||
Ok(Other(msg)) => {
|
Ok(Other(msg)) => {
|
||||||
eprintln!("{}", msg);
|
eprintln!("{}", msg);
|
||||||
|
41
json-api/src/rtc.rs
Normal file
41
json-api/src/rtc.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This whole module contains functions that are optionally built for those
|
||||||
|
* (((weirdos))) that don't want rtc capabilities.
|
||||||
|
*
|
||||||
|
* General configuration things
|
||||||
|
* RTC server should run on the same system
|
||||||
|
*
|
||||||
|
* Features TODO: make this fully module so that rtc & api can run on seperate
|
||||||
|
* servers if need be. This can be configured with .env most likely and the rtc
|
||||||
|
* private api can probably be a really simple auth'd REST API,
|
||||||
|
* prolly don't even need much in the way of authentication as long as the API key
|
||||||
|
* is sufficiently large & securely transferred on both parties behalf
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(feature = "rtc")]
|
||||||
|
pub async fn new_message(message: db::Message) {
|
||||||
|
use hyper::{Body, Request};
|
||||||
|
use hyper::client::Client;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
let payload = json!({
|
||||||
|
"event": "new-message",
|
||||||
|
"message": message
|
||||||
|
});
|
||||||
|
println!("Sending event payload => {}", payload);
|
||||||
|
let request = Request::builder()
|
||||||
|
.method("POST")
|
||||||
|
.uri("http://localhost:6750/")
|
||||||
|
.body(Body::from(payload.to_string()))
|
||||||
|
.expect("[ERROR] Couldn't make event request");
|
||||||
|
|
||||||
|
println!("[INFO] Notifying RTC -> new-message");
|
||||||
|
|
||||||
|
let client = Client::new();
|
||||||
|
// capturing both ok/err for loggin purposes
|
||||||
|
match client.request(request).await {
|
||||||
|
Ok(response) => println!("[RTC-NOTIFY] All good id-{}", message.id),
|
||||||
|
Err(e) => eprintln!("{}", e)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user