Compare commits

..

1 Commits

Author SHA1 Message Date
kozabrada123 543fbd1ab1
Merge feb2b1b64c into cb3551dcd4 2024-07-24 21:55:15 +02:00
3 changed files with 10 additions and 17 deletions

View File

@ -34,13 +34,8 @@ use wasmtimer::tokio::sleep;
#[derive(Debug)] #[derive(Debug)]
pub struct ExampleObserver {} pub struct ExampleObserver {}
// This struct can observe GatewayReady events when subscribed, because it implements the trait Subscriber<GatewayReady>. // This struct can observe GatewayReady events when subscribed, because it implements the trait Observer<GatewayReady>.
// The Subscriber trait can be implemented for a struct for a given websocketevent to handle observing it // The Observer trait can be implemented for a struct for a given websocketevent to handle observing it
//
// Note that this trait is quite generic and can be use to observe any type.
//
// It is just used for WebSocketEvents in chorus.
//
// One struct can be an observer of multiple websocketevents, if needed // One struct can be an observer of multiple websocketevents, if needed
#[async_trait] #[async_trait]
impl Subscriber<GatewayReady> for ExampleObserver { impl Subscriber<GatewayReady> for ExampleObserver {

View File

@ -22,9 +22,11 @@ use simplelog::{TermLogger, Config, WriteLogger};
use std::{net::SocketAddrV4, sync::Arc, fs::File, time::Duration}; use std::{net::SocketAddrV4, sync::Arc, fs::File, time::Duration};
use chorus::{ use chorus::{
gateway::{Gateway, GatewayOptions, Observer}, gateway::{Observer, Gateway},
types::{ types::{
GatewayIdentifyPayload, GatewayReady, SelectProtocol, SelectProtocolData, SessionDescription, Snowflake, Speaking, SpeakingBitflags, SsrcDefinition, UpdateVoiceState, VoiceEncryptionMode, VoiceIdentify, VoiceProtocol, VoiceReady, VoiceServerUpdate GatewayReady, SelectProtocol, SelectProtocolData, SessionDescription, Snowflake, Speaking,
SpeakingBitflags, SsrcDefinition, VoiceEncryptionMode, VoiceIdentify, VoiceProtocol,
VoiceReady, VoiceServerUpdate, GatewayIdentifyPayload, UpdateVoiceState,
}, },
voice::{ voice::{
gateway::{VoiceGateway, VoiceGatewayHandle}, gateway::{VoiceGateway, VoiceGatewayHandle},
@ -217,7 +219,7 @@ impl Observer<Speaking> for VoiceHandler {
println!( println!(
"Received Speaking! (SRRC: {}, flags: {:?})", "Received Speaking! (SRRC: {}, flags: {:?})",
data.ssrc, data.ssrc,
SpeakingBitflags::from_bits(data.speaking.into()).unwrap() SpeakingBitflags::from_bits(data.speaking).unwrap()
); );
} }
} }
@ -251,7 +253,7 @@ async fn main() {
]) ])
.unwrap(); .unwrap();
let gateway = Gateway::spawn(GATEWAY_URL.to_string(), GatewayOptions::default()) let gateway = Gateway::spawn(GATEWAY_URL.to_string())
.await .await
.unwrap(); .unwrap();

View File

@ -19,7 +19,7 @@ pub use message::*;
pub use options::*; pub use options::*;
use crate::errors::GatewayError; use crate::errors::GatewayError;
use crate::types::Snowflake; use crate::types::{Snowflake};
use std::any::Any; use std::any::Any;
use std::collections::HashMap; use std::collections::HashMap;
@ -77,10 +77,6 @@ const GATEWAY_LAZY_REQUEST: u8 = 14;
pub type ObservableObject = dyn Send + Sync + Any; pub type ObservableObject = dyn Send + Sync + Any;
/// Note: this is a reexport of [pubserve::Subscriber],
/// exported not to break the public api and make development easier
pub use pubserve::Subscriber as Observer;
/// An entity type which is supposed to be updateable via the Gateway. This is implemented for all such types chorus supports, implementing it for your own types is likely a mistake. /// An entity type which is supposed to be updateable via the Gateway. This is implemented for all such types chorus supports, implementing it for your own types is likely a mistake.
pub trait Updateable: 'static + Send + Sync { pub trait Updateable: 'static + Send + Sync {
fn id(&self) -> Snowflake; fn id(&self) -> Snowflake;