Compare commits

..

6 Commits

Author SHA1 Message Date
kozabrada123 938dce6061
Merge a27b488f61 into cb3551dcd4 2024-07-25 09:49:48 +00:00
kozabrada123 a27b488f61
Publically reexport Subscriber as Observer (#530)
Fixes the compile errors in the `voice_simple` example, updates the docs
in the `gateway_observers` example and adds a public reexport of
`Subscriber` as `Observer`, to make development easier and introduce
less breaking changes to our public api

to reduce the external dependencies needed for development with
`chorus`, we could also add some other reexports, potentially
`async_trait::async_trait`
2024-07-25 11:49:44 +02:00
kozabrada123 d829537713 remove cargo lock from example 2024-07-25 11:31:16 +02:00
kozabrada123 b9bc37fcd4 Readd Observer trait as reexport 2024-07-25 11:29:35 +02:00
kozabrada123 832576dbf4 Update documentation in gateway_observers example 2024-07-25 11:28:22 +02:00
kozabrada123 539460a552 Fix voice_simple example 2024-07-25 11:27:30 +02:00
3 changed files with 17 additions and 10 deletions

View File

@ -34,8 +34,13 @@ 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 Observer<GatewayReady>. // This struct can observe GatewayReady events when subscribed, because it implements the trait Subscriber<GatewayReady>.
// The Observer trait can be implemented for a struct for a given websocketevent to handle observing it // The Subscriber 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,11 +22,9 @@ 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::{Observer, Gateway}, gateway::{Gateway, GatewayOptions, Observer},
types::{ types::{
GatewayReady, SelectProtocol, SelectProtocolData, SessionDescription, Snowflake, Speaking, GatewayIdentifyPayload, GatewayReady, SelectProtocol, SelectProtocolData, SessionDescription, Snowflake, Speaking, SpeakingBitflags, SsrcDefinition, UpdateVoiceState, VoiceEncryptionMode, VoiceIdentify, VoiceProtocol, VoiceReady, VoiceServerUpdate
SpeakingBitflags, SsrcDefinition, VoiceEncryptionMode, VoiceIdentify, VoiceProtocol,
VoiceReady, VoiceServerUpdate, GatewayIdentifyPayload, UpdateVoiceState,
}, },
voice::{ voice::{
gateway::{VoiceGateway, VoiceGatewayHandle}, gateway::{VoiceGateway, VoiceGatewayHandle},
@ -219,7 +217,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).unwrap() SpeakingBitflags::from_bits(data.speaking.into()).unwrap()
); );
} }
} }
@ -253,7 +251,7 @@ async fn main() {
]) ])
.unwrap(); .unwrap();
let gateway = Gateway::spawn(GATEWAY_URL.to_string()) let gateway = Gateway::spawn(GATEWAY_URL.to_string(), GatewayOptions::default())
.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,6 +77,10 @@ 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;