Compare commits
6 Commits
543fbd1ab1
...
938dce6061
Author | SHA1 | Date |
---|---|---|
kozabrada123 | 938dce6061 | |
kozabrada123 | a27b488f61 | |
kozabrada123 | d829537713 | |
kozabrada123 | b9bc37fcd4 | |
kozabrada123 | 832576dbf4 | |
kozabrada123 | 539460a552 |
|
@ -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 {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue