Skip to main content

emotiv_cortex_v2/protocol/
session.rs

1//! Session management protocol types.
2
3use serde::Deserialize;
4
5use crate::protocol::headset::HeadsetInfo;
6
7/// Session information from `createSession` / `querySessions`.
8#[derive(Debug, Clone, Deserialize)]
9pub struct SessionInfo {
10    /// Session ID (UUID).
11    pub id: String,
12
13    /// Session status: "opened", "activated".
14    pub status: String,
15
16    /// `EmotivID` of the user
17    pub owner: String,
18
19    /// Id of license used by the session
20    pub license: String,
21
22    /// Application ID.
23    #[serde(rename = "appId")]
24    pub app_id: String,
25
26    /// ISO datetime when the session was created.
27    pub started: String,
28
29    /// ISO datetime when the session was closed.
30    pub stopped: Option<String>,
31
32    /// Data streams subscribed to in this session.
33    pub streams: Vec<String>,
34
35    /// Ids of all records created during this session.
36    #[serde(rename = "recordIds")]
37    pub record_ids: Vec<String>,
38
39    /// Whether this session is currently being recorded.
40    pub recording: bool,
41
42    /// Headset associated with this session.
43    pub headset: Option<HeadsetInfo>,
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_deserialize_session_info() {
52        let json = r#"{
53            "id": "session-uuid-456",
54            "status": "activated",
55            "owner": "user123",
56            "license": "license-abc",
57            "appId": "com.example.app",
58            "started": "2024-01-15T10:30:00Z",
59            "streams": ["eeg", "dev"],
60            "recordIds": [],
61            "recording": false
62        }"#;
63
64        let session: SessionInfo = serde_json::from_str(json).unwrap();
65        assert_eq!(session.id, "session-uuid-456");
66        assert_eq!(session.status, "activated");
67        assert_eq!(session.owner, "user123");
68        assert_eq!(session.license, "license-abc");
69        assert_eq!(session.streams, vec!["eeg", "dev"]);
70        assert!(!session.recording);
71        assert!(session.stopped.is_none());
72        assert!(session.headset.is_none());
73    }
74}