Welcome to pusher_rs
- The long-missing Rust Pusher crate.
This library is still under heavy development. Currently in use by one of the projects I am working on. Open-sourcing it since it has matured to a good level.
A Rust client library for interacting with the Pusher Channels API. This library provides a simple and efficient way to integrate Pusher's real-time functionality into your Rust applications.
Features
- Connect to Pusher Channels
- Subscribe to public, private, presence, and private encrypted channels
- Publish events to channels
- Handle incoming events
- Automatic reconnection with exponential backoff
- Environment-based configuration
- Flexible channel management
Todo
- Support for Batch Triggers
- Improve error handling and logging
- Add comprehensive test suite
- Implement WebHooks support
- Optimize performance for high-load scenarios
- Create more detailed documentation and examples
Installation
Add this to your Cargo.toml
:
[]
= { = "https://github.com/chmod77/pusher-rs.git" }
If you want to use a specific branch or commit, you can specify it like this:
[]
= { = "https://github.com/username/pusher-rs.git", = "main" }
# or
= { = "https://github.com/username/pusher-rs.git", = "commit_hash" }
Configuration
The library uses environment variables for configuration. Create a .env
file in your project root with the following variables:
PUSHER_APP_ID=your_app_id
PUSHER_KEY=your_app_key
PUSHER_SECRET=your_app_secret
PUSHER_CLUSTER=your_cluster
PUSHER_USE_TLS=true - this will enforce TLS
Usage
Initializing the client
use ;
async
Subscribing to a channel
client.subscribe.await?;
Publishing an event
client.trigger.await?;
Handling events
client.bind.await?;
Working with encrypted channels
// Subscribe to an encrypted channel
client.subscribe_encrypted.await?;
// Publish to an encrypted channel
client.trigger_encrypted.await?;
Channel Types
The library supports four types of channels:
- Public
- Private
- Presence
- Private Encrypted
Each channel type has specific features and authentication requirements.
Error Handling
The library uses a custom PusherError
type for error handling. You can match on different error variants to handle specific error cases:
use PusherError;
match client.connect.await
Advanced Usage
Custom Configuration
While the library defaults to using environment variables, you can also create a custom configuration:
use PusherConfig;
use Duration;
let config = PusherConfig ;
Channel Management
The library provides a ChannelList
struct for managing subscribed channels:
let mut channel_list = new;
let channel = new;
channel_list.add;
if let Some = channel_list.get
Tests
Integration tests live under tests/integration_tests
Just run cargo test --test integration_tests -- --nocapture
to start.
More tests are being added. This section will be updated accordingly.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. Here's how you can contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feat/amazing-feature
) - Commit your changes (
git commit -m 'feat: Add some amazing feature'
) - Push to the branch (
git push origin feat/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License.