const TOKEN: &str = "";
const GATEWAY_URL: &str = "wss://gateway.old.server.spacebar.chat/";
use async_trait::async_trait;
use chorus::gateway::{Gateway, GatewayOptions};
use chorus::{
self,
types::{GatewayIdentifyPayload, GatewayReady},
};
use pubserve::Subscriber;
use std::{sync::Arc, time::Duration};
use tokio::{self};
#[cfg(not(target_arch = "wasm32"))]
use tokio::time::sleep;
#[cfg(target_arch = "wasm32")]
use wasmtimer::tokio::sleep;
#[derive(Debug)]
pub struct ExampleObserver {}
#[async_trait]
impl Subscriber<GatewayReady> for ExampleObserver {
async fn update(&self, _data: &GatewayReady) {
println!("Observed Ready!");
}
}
#[tokio::main(flavor = "current_thread")]
async fn main() {
let gateway_websocket_url = GATEWAY_URL;
let options = GatewayOptions::default();
let gateway = Gateway::spawn(gateway_websocket_url, options)
.await
.unwrap();
let observer = ExampleObserver {};
let shared_observer = Arc::new(observer);
gateway
.events
.lock()
.await
.session
.ready
.subscribe(shared_observer);
let token = TOKEN.to_string();
let mut identify = GatewayIdentifyPayload::common();
identify.token = token;
gateway.send_identify(identify).await;
loop {
sleep(Duration::from_secs(3600)).await;
}
}