summaryrefslogtreecommitdiffstats
path: root/src/teamspeak.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/teamspeak.rs')
-rw-r--r--src/teamspeak.rs73
1 files changed, 41 insertions, 32 deletions
diff --git a/src/teamspeak.rs b/src/teamspeak.rs
index 785eba2..2cd87e7 100644
--- a/src/teamspeak.rs
+++ b/src/teamspeak.rs
@@ -1,15 +1,13 @@
-use futures::{
- compat::Future01CompatExt,
-};
+use futures::compat::Future01CompatExt;
use futures01::{future::Future, sink::Sink};
-use tsclientlib::{Connection, ConnectOptions, events::Event, ClientId, MessageTarget};
-use tsclientlib::Event::ConEvents;
use crate::{ApplicationMessage, Message};
use std::sync::mpsc::Sender;
-use std::sync::{Mutex, Arc};
+use std::sync::{Arc, Mutex};
+use tsclientlib::Event::ConEvents;
+use tsclientlib::{events::Event, ClientId, ConnectOptions, Connection, MessageTarget};
-use log::{error};
+use log::error;
pub struct TeamSpeakConnection {
conn: Connection,
@@ -21,19 +19,20 @@ fn get_message<'a>(event: &Event) -> Option<Message> {
from: target,
invoker: sender,
message: msg,
- } => {
- Some(Message {
- target: target.clone(),
- invoker: sender.clone(),
- text: msg.clone(),
- })
- }
+ } => Some(Message {
+ target: target.clone(),
+ invoker: sender.clone(),
+ text: msg.clone(),
+ }),
_ => None,
}
}
impl TeamSpeakConnection {
- pub async fn new(tx: Arc<Mutex<Sender<ApplicationMessage>>>, options: ConnectOptions) -> Result<TeamSpeakConnection, tsclientlib::Error> {
+ pub async fn new(
+ tx: Arc<Mutex<Sender<ApplicationMessage>>>,
+ options: ConnectOptions,
+ ) -> Result<TeamSpeakConnection, tsclientlib::Error> {
let conn = Connection::new(options).compat().await?;
let packet = conn.lock().server.set_subscribed(true);
conn.send_packet(packet).compat().await.unwrap();
@@ -52,21 +51,19 @@ impl TeamSpeakConnection {
}),
);
- Ok(TeamSpeakConnection {
- conn,
- })
+ Ok(TeamSpeakConnection { conn })
}
pub fn send_audio_packet(&self, samples: &[u8]) {
- let packet = tsproto_packets::packets::OutAudio::new(
- &tsproto_packets::packets::AudioData::C2S {
+ let packet =
+ tsproto_packets::packets::OutAudio::new(&tsproto_packets::packets::AudioData::C2S {
id: 0,
codec: tsproto_packets::packets::CodecType::OpusMusic,
data: samples,
- },
- );
+ });
- let send_packet = self.conn
+ let send_packet = self
+ .conn
.get_packet_sink()
.send(packet)
.map(|_| ())
@@ -76,24 +73,32 @@ impl TeamSpeakConnection {
}
pub fn join_channel_of_user(&self, id: ClientId) {
- let channel = self.conn.lock()
+ let channel = self
+ .conn
+ .lock()
.clients
.get(&id)
.expect("can find poke sender")
.channel;
- tokio::spawn(self.conn.lock().to_mut()
+ tokio::spawn(
+ self.conn
+ .lock()
+ .to_mut()
.get_client(&self.conn.lock().own_client)
.expect("can get myself")
.set_channel(channel)
- .map_err(|e| error!("Failed to switch channel: {}", e)));
+ .map_err(|e| error!("Failed to switch channel: {}", e)),
+ );
}
pub fn set_nickname(&self, name: &str) {
- tokio::spawn(self.conn
+ tokio::spawn(
+ self.conn
.lock()
.to_mut()
.set_name(name)
- .map_err(|e| error!("Failed to set nickname: {}", e)));
+ .map_err(|e| error!("Failed to set nickname: {}", e)),
+ );
}
pub fn set_description(&self, desc: &str) {
@@ -104,13 +109,17 @@ impl TeamSpeakConnection {
.get_client(&self.conn.lock().own_client)
.expect("Can get myself")
.set_description(desc)
- .map_err(|e| error!("Failed to change description: {}", e)));
+ .map_err(|e| error!("Failed to change description: {}", e)),
+ );
}
pub fn send_message_to_channel(&self, text: &str) {
- tokio::spawn(self.conn.lock().to_mut()
+ tokio::spawn(
+ self.conn
+ .lock()
+ .to_mut()
.send_message(MessageTarget::Channel, text)
- .map_err(|e| error!("Failed to send message: {}", e)));
-
+ .map_err(|e| error!("Failed to send message: {}", e)),
+ );
}
}