1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//! # Guts Real-time
//!
//! Real-time WebSocket support for the Guts code collaboration platform.
//!
//! This crate provides WebSocket-based real-time updates for repository events,
//! enabling live notifications and instant UI updates without page refresh.
//!
//! ## Features
//!
//! - **Event Hub**: Central management of WebSocket connections
//! - **Subscriptions**: Channel-based subscription model
//! - **Event Broadcasting**: Efficient event distribution to subscribed clients
//! - **Notifications**: User notification system
//!
//! ## Channel Types
//!
//! - `repo:owner/name` - All events for a repository
//! - `repo:owner/name/prs` - Pull request events only
//! - `repo:owner/name/issues` - Issue events only
//! - `user:username` - User notifications
//! - `org:orgname` - Organization events
//!
//! ## Example
//!
//! ```rust
//! use guts_realtime::{EventHub, EventKind};
//! use std::sync::Arc;
//!
//! // Create the event hub
//! let hub = Arc::new(EventHub::new());
//!
//! // Connect a client
//! let (client, receiver) = hub.connect().unwrap();
//!
//! // Subscribe to a repository
//! hub.handle_command(
//! &client,
//! guts_realtime::ClientCommand::Subscribe {
//! channel: "repo:alice/myrepo".to_string(),
//! },
//! ).unwrap();
//!
//! // Emit an event
//! hub.emit_event(
//! "repo:alice/myrepo".to_string(),
//! EventKind::Push,
//! serde_json::json!({
//! "ref": "refs/heads/main",
//! "before": "abc123",
//! "after": "def456"
//! }),
//! );
//! ```
//!
//! ## WebSocket Protocol
//!
//! ### Client -> Server Messages
//!
//! ```json
//! // Subscribe to a channel
//! {"type": "subscribe", "channel": "repo:owner/name"}
//!
//! // Unsubscribe from a channel
//! {"type": "unsubscribe", "channel": "repo:owner/name"}
//!
//! // Ping for keepalive
//! {"type": "ping"}
//! ```
//!
//! ### Server -> Client Messages
//!
//! ```json
//! // Subscription confirmed
//! {"type": "subscribed", "channel": "repo:owner/name"}
//!
//! // Event notification
//! {"type": "event", "channel": "repo:owner/name", "event": "push", ...}
//!
//! // Pong response
//! {"type": "pong"}
//! ```
//!
//! ## Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────┐
//! │ EventHub │
//! │ ┌─────────────────────────────────┐ │
//! │ │ Clients Map │ │
//! │ │ client_id -> Client │ │
//! │ │ └─> subscriptions │ │
//! │ │ └─> message sender │ │
//! │ └─────────────────────────────────┘ │
//! │ │ │
//! │ ┌───────────────▼───────────────────┐ │
//! │ │ Broadcast Channel │ │
//! │ │ (for external subscribers) │ │
//! │ └───────────────────────────────────┘ │
//! └─────────────────────────────────────────┘
//! ```
// Re-export main types
pub use ;
pub use RealtimeError;
pub use ;
pub use ;
pub use ;
pub use ;