pub struct Realtime { /* private fields */ }
Expand description
Realtime client for WebSocket subscriptions
Provides cross-platform realtime subscriptions to Supabase database changes.
§Examples
§Basic subscription
use supabase::{Client, realtime::RealtimeEvent};
let client = Client::new("your-url", "your-key")?;
let realtime = client.realtime();
realtime.connect().await?;
let sub_id = realtime
.channel("public-posts")
.table("posts")
.subscribe(|msg| println!("New post: {:?}", msg))
.await?;
Implementations§
Source§impl Realtime
impl Realtime
Sourcepub fn new(config: Arc<SupabaseConfig>) -> Result<Self>
pub fn new(config: Arc<SupabaseConfig>) -> Result<Self>
Create a new realtime client (works on both native and WASM)
§Examples
use supabase::types::SupabaseConfig;
use supabase::realtime::Realtime;
use std::sync::Arc;
let config = Arc::new(SupabaseConfig {
url: "https://your-project.supabase.co".to_string(),
key: "your-anon-key".to_string(),
..Default::default()
});
let realtime = Realtime::new(config).unwrap();
Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Connect to the realtime server (cross-platform)
§Examples
let client = Client::new("your-url", "your-key")?;
let realtime = client.realtime();
realtime.connect().await?;
println!("Connected to Supabase realtime!");
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnect from the realtime server
§Examples
let client = Client::new("your-url", "your-key")?;
let realtime = client.realtime();
realtime.connect().await?;
// ... do work ...
realtime.disconnect().await?;
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if connected to realtime server
§Examples
let client = Client::new("your-url", "your-key")?;
let realtime = client.realtime();
if !realtime.is_connected().await {
realtime.connect().await?;
}
Sourcepub fn channel(&self, _topic: &str) -> ChannelBuilder
pub fn channel(&self, _topic: &str) -> ChannelBuilder
Create a channel subscription builder
§Examples
let client = Client::new("your-url", "your-key")?;
let subscription = client.realtime()
.channel("public-posts")
.table("posts")
.subscribe(|msg| println!("Update: {:?}", msg))
.await?;
Sourcepub async fn unsubscribe(&self, subscription_id: &str) -> Result<()>
pub async fn unsubscribe(&self, subscription_id: &str) -> Result<()>
Unsubscribe from a channel
§Examples
let client = Client::new("your-url", "your-key")?;
let realtime = client.realtime();
let subscription_id = realtime
.channel("posts")
.table("posts")
.subscribe(|_| {})
.await?;
// Later...
realtime.unsubscribe(&subscription_id).await?;
Sourcepub async fn subscribe<F>(
&self,
subscription_config: SubscriptionConfig,
callback: F,
) -> Result<String>
pub async fn subscribe<F>( &self, subscription_config: SubscriptionConfig, callback: F, ) -> Result<String>
Subscribe to a channel with custom configuration
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Realtime
impl !RefUnwindSafe for Realtime
impl Send for Realtime
impl Sync for Realtime
impl Unpin for Realtime
impl !UnwindSafe for Realtime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more