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
use crate::;
use ;
use Display;
/// An interceptor that is called when a new Socket.IO connection is established.
///
/// ## Example
/// ```rust,ignore
/// use sword::prelude::*;
///
/// #[derive(Interceptor)]
/// pub struct MyInterceptor;
///
/// impl OnConnect for MyInterceptor {
/// type Error = String;
/// async fn on_connect(&self, socket: SocketContext) -> Result<(), Self::Error> {
/// println!("New connection established: {}", socket.id());
/// }
/// }
/// ```
///
/// ## Applying the Interceptor
/// To apply this interceptor use the #[interceptor] attribute under your #[on_connection] method:
/// ```rust,ignore
/// use sword::prelude::*;
///
/// #[socketio_adapter("/my_namespace")]
/// pub struct MyAdapter;
///
/// #[handlers]
/// impl MyAdapter {
/// #[on_connection]
/// #[interceptor(MyInterceptor)]
/// async fn handle_connection(&self, socket: SocketContext) {
/// // handle the initial connection (logging, authentication)
/// }
/// }
/// ```