use crate::rfcomm::RfcommChannel;
use futures_core::Stream;
use webbluetooth_core::{AvrcpPassThrough, Result};
pub struct AvrcpSession {
channel: RfcommChannel,
}
impl AvrcpSession {
pub fn new(channel: RfcommChannel) -> Self {
Self { channel }
}
pub fn send(&self, command: AvrcpPassThrough) -> Result<()> {
let frame = command
.encode()
.map_err(|error| webbluetooth_core::Error::InvalidModification(error.to_string()))?;
self.channel.send(&frame)
}
pub fn parse(&self, bytes: &[u8]) -> Result<AvrcpPassThrough> {
AvrcpPassThrough::decode(bytes)
.map_err(|error| webbluetooth_core::Error::InvalidModification(error.to_string()))
}
pub fn take_incoming(&self) -> Option<impl Stream<Item = Vec<u8>>> {
self.channel.take_incoming()
}
pub fn channel(&self) -> &RfcommChannel {
&self.channel
}
pub fn close(&self) {
self.channel.close();
}
}