I think its ready to test!

This commit is contained in:
Ryan Voots 2020-08-26 11:49:15 -07:00
parent c8d1a6fc80
commit d28d583b19
3 changed files with 38 additions and 14 deletions

View file

@ -7,24 +7,26 @@ use js_int::{uint, UInt};
use matrix_sdk::{
self,
api::r0::{
room::{create_room::Request as CreateRoomRequest, Visibility, create_room::RoomPreset::*,},
room::{
create_room::{Request as CreateRoomRequest, RoomPreset::*},
Visibility,
},
voip,
},
events::{AnyMessageEventContent,
room::{
message::{MessageEventContent, TextMessageEventContent},
},
events::{
room::message::{MessageEventContent, TextMessageEventContent},
AnyMessageEventContent,
},
identifiers::{UserId, RoomId},
identifiers::{RoomId, UserId},
Client,
};
use matrix_sdk_common::events::call::{
answer::*, candidates::*, hangup::*, invite::*, SessionDescription, SessionDescriptionType,
};
use std::convert::TryFrom;
use tokio::time::{delay_for, Duration};
use tracing::error;
use uuid::Uuid; // get the functions i need from my gstream module
use std::convert::TryFrom;
#[derive(Debug)]
@ -264,8 +266,8 @@ impl CallManager {
let mut room_create_request = CreateRoomRequest::new();
// TODO find out if there's a way to find an existing room
// Setup the room, we want to invite the target, make this a direct room, and make it as private as possible
// the trusted part lets them control it as much as us.
// Setup the room, we want to invite the target, make this a direct room, and make it as private as
// possible the trusted part lets them control it as much as us.
room_create_request.invite = &invitee;
room_create_request.is_direct = true;
room_create_request.topic = Some("Temporary Room Created for Call");
@ -281,7 +283,7 @@ impl CallManager {
self.gst_channel.sender.send(CallManagerToGst::CreateCall(turn_url))?;
let message = AnyMessageEventContent::RoomMessage(MessageEventContent::Text(TextMessageEventContent {
body: format!("I'm calling you!"), /* This is renderng weirdly in vscode,
* ignore the spaces for my sanity */
* ignore the spaces for my sanity */
formatted: None,
relates_to: None,
}));

View file

@ -61,7 +61,7 @@ async fn main() -> Result<(), anyhow::Error> {
let (matrix_cm_sender, matrix_cm_receiver) = cm_matrix_channels.get_pair_right();
let matrix_client = matrixbot::login(&botname).await.unwrap();
let matrix_client = matrixbot::login(&botname, matrix_cm_sender.clone()).await.unwrap();
let looping_client = matrix_client.clone();

View file

@ -40,10 +40,11 @@ struct CommandBot {
/// This clone of the `Client` will send requests to the server,
/// while the other keeps us in sync with the server using `sync_forever`.
client: Client,
callmanager: Sender<MatrixToCallManager>,
}
impl CommandBot {
pub fn new(client: Client) -> Self { Self { client } }
pub fn new(client: Client, callmanager: Sender<MatrixToCallManager>) -> Self { Self { client, callmanager } }
// TODO figure out a better way to refer to this type
async fn handle_command(&self, room: Arc<RwLock<Room>>, sender: String, message: String) {
@ -61,6 +62,27 @@ impl CommandBot {
println!("sending");
self
.client
// send our message to the room we found the "!party" command in
// the last parameter is an optional Uuid which we don't care about.
.room_send(&room_id, content, None)
.await
.unwrap();
println!("message sent");
} else if message.contains("!callme") {
let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text(TextMessageEventContent {
body: "Checking if I'm dressed".to_string(),
formatted: None,
relates_to: None,
}));
// we clone here to hold the lock for as little time as possible.
let room_id = room.read().await.room_id.clone();
println!("sending");
self
.client
// send our message to the room we found the "!party" command in
@ -267,7 +289,7 @@ impl EventEmitter for CommandBot {
}
}
pub async fn login(botname: &String) -> Result<Client, anyhow::Error> {
pub async fn login(botname: &String, callmanager: Sender<MatrixToCallManager>) -> Result<Client, anyhow::Error> {
// the location for `JsonStore` to save files to
// homeserver_url: String, username: String, password: String
//let {homeserver_url: String, username: String, password: String} = config.matrix;
@ -284,7 +306,7 @@ pub async fn login(botname: &String) -> Result<Client, anyhow::Error> {
// create a new Client with the given homeserver url and config
let mut client = Client::new_with_config(homeserver_url, client_config).unwrap();
let commandbot = CommandBot::new(client.clone());
let commandbot = CommandBot::new(client.clone(), callmanager.clone());
let commandbox = Box::new(commandbot);
client