resonator 0.1.0

This crate allows 2 devices to send live PCM audio data to each other through a server
Documentation
use std::collections::HashMap;

use crate::common::audiobuffer::AudioBuffer;

pub struct Client {
    pub id: i32,
    pub queued_incoming_buffers: Vec<AudioBuffer>,
}

impl Client {
    pub fn get_next_buffer(&mut self) -> Option<AudioBuffer> {
        if self.queued_incoming_buffers.len() > 0 {
            Some(self.queued_incoming_buffers.remove(0))
        } else {
            None
        }
    }

    pub fn enqueue_buffer(&mut self, buffer: AudioBuffer) {
        self.queued_incoming_buffers.push(buffer);
    }
}

pub struct ClientManager {
    clients: HashMap<i32, Client>,
}

impl ClientManager {
    pub fn new() -> ClientManager {
        ClientManager {
            clients: HashMap::new(),
        }
    }

    pub fn get_by_id(&mut self, id: i32) -> Option<&mut Client> {
        self.clients.get_mut(&id)
    }

    pub fn add(&mut self, id: i32) {
        self.clients.insert(id, Client {
            id,
            queued_incoming_buffers: Vec::new(),
        });
    }

    pub fn remove(&mut self, id: i32) {
        self.clients.remove(&id);
    }
}