use super::super::Client;
use crate::events::{Error, Result};
use crate::types::{AudioCodec, ChannelId};
use teamtalk_sys as ffi;
impl Client {
pub fn start_recording_muxed(
&self,
codec: &AudioCodec,
file_path: &str,
format: ffi::AudioFileFormat,
) -> bool {
self.backend()
.start_recording_muxed(self.ptr.0, codec, file_path, format)
}
pub fn start_recording_channel(
&self,
channel_id: i32,
file_path: &str,
format: ffi::AudioFileFormat,
) -> bool {
self.backend()
.start_recording_channel(self.ptr.0, channel_id, file_path, format)
}
pub fn start_recording_streams(
&self,
stream_types: u32,
codec: &AudioCodec,
file_path: &str,
format: ffi::AudioFileFormat,
) -> bool {
self.backend()
.start_recording_streams(self.ptr.0, stream_types, codec, file_path, format)
}
pub fn stop_recording(&self) -> bool {
self.backend().stop_recording(self.ptr.0)
}
pub fn stop_recording_channel(&self, channel_id: i32) -> bool {
self.backend()
.stop_recording_channel(self.ptr.0, channel_id)
}
}
pub struct RecordSession<'a> {
client: &'a Client,
channel_id: ChannelId,
active: bool,
}
impl<'a> RecordSession<'a> {
pub fn start_channel(
client: &'a Client,
channel_id: ChannelId,
file_path: &str,
format: ffi::AudioFileFormat,
) -> Result<Self> {
if client.start_recording_channel(channel_id.0, file_path, format) {
Ok(Self {
client,
channel_id,
active: true,
})
} else {
Err(Error::CommandFailed {
code: -1,
message: "Recording start failed".to_string(),
})
}
}
pub fn stop(mut self) -> bool {
let ok = self.client.stop_recording_channel(self.channel_id.0);
self.active = false;
ok
}
}
impl Drop for RecordSession<'_> {
fn drop(&mut self) {
if self.active {
let _ = self.client.stop_recording_channel(self.channel_id.0);
}
}
}