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)]
pub struct ExampleObserver {}
// This struct can observe GatewayReady events when subscribed, because it implements the trait Subscriber<GatewayReady>.
// 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.
//
// This struct can observe GatewayReady events when subscribed, because it implements the trait Observer<GatewayReady>.
// The Observer trait can be implemented for a struct for a given websocketevent to handle observing it
// One struct can be an observer of multiple websocketevents, if needed
#[async_trait]
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 chorus::{
gateway::{Gateway, GatewayOptions, Observer},
gateway::{Observer, Gateway},
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::{
gateway::{VoiceGateway, VoiceGatewayHandle},
@ -217,7 +219,7 @@ impl Observer<Speaking> for VoiceHandler {
println!(
"Received Speaking! (SRRC: {}, flags: {:?})",
data.ssrc,
SpeakingBitflags::from_bits(data.speaking.into()).unwrap()
SpeakingBitflags::from_bits(data.speaking).unwrap()
);
}
}
@ -251,7 +253,7 @@ async fn main() {
])
.unwrap();
let gateway = Gateway::spawn(GATEWAY_URL.to_string(), GatewayOptions::default())
let gateway = Gateway::spawn(GATEWAY_URL.to_string())
.await
.unwrap();

View File

@ -19,7 +19,7 @@ pub use message::*;
pub use options::*;
use crate::errors::GatewayError;
use crate::types::Snowflake;
use crate::types::{Snowflake};
use std::any::Any;
use std::collections::HashMap;
@ -77,10 +77,6 @@ const GATEWAY_LAZY_REQUEST: u8 = 14;
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.
pub trait Updateable: 'static + Send + Sync {
fn id(&self) -> Snowflake;