emotiv-cortex-v2
A Rust client for the Emotiv Cortex v2 WebSocket API.
Pre-release. This crate is under active development; APIs and behavior may change. Treat as pre-release when depending on it.
Not affiliated with Emotiv. This crate is independent, community-maintained, and is not created by, affiliated with, supported by, sponsored by, or endorsed by Emotiv, Inc. For official support and products, see emotiv.com.
Provides a complete, typed interface to the Emotiv Cortex service for interacting with Emotiv EEG headsets (Insight, EPOC+, EPOC X, EPOC Flex) NOTE: ONLY INSIGHT DEVICES HAVE BEEN TESTED.
Features
- (close to) Full Cortex v2 API coverage (authentication, headsets, sessions, all 9 data streams, records, markers, profiles, BCI training)
- Two-layer client: raw
CortexClientfor full control,ResilientClientfor use with auto-reconnect, token refresh, and retry - Typed data streams (EEG, motion, band power, performance metrics, mental commands, facial expressions, device quality)
- Feature-selectable TLS backend (
rustls-tlsdefault,native-tlsopt-in) - TOML config loading can be enabled/disabled via
config-toml
Feature Flags
| Feature | Default | Description |
|---|---|---|
rustls-tls |
yes | Use rustls TLS backend (tokio-tungstenite/rustls-tls-webpki-roots) |
native-tls |
no | Use native TLS backend (tokio-tungstenite/native-tls) |
config-toml |
yes | Enable TOML parsing for CortexConfig::from_file/discover |
Exactly one TLS backend feature must be enabled (rustls-tls or native-tls).
If config-toml is disabled, CortexConfig::from_file and file-based discover return a ConfigError explaining how to re-enable TOML parsing.
Which client should I use?
| Layer | Type | Token mgmt | Reconnect | Best for |
|---|---|---|---|---|
| Low-level | CortexClient |
Manual | No | tooling, tests, direct protocol control |
| High-level | ResilientClient |
Automatic | Yes | ease of use |
Prerequisites
- EMOTIV Launcher installed and running
- API credentials from the Emotiv Developer Portal
Quick Start
[]
= "0.3"
= { = "1", = ["rt-multi-thread", "macros"] }
Use native TLS instead of rustls:
[]
= { = "0.3", = false, = ["native-tls", "config-toml"] }
= { = "1", = ["rt-multi-thread", "macros"] }
use ;
use QueryHeadsetsOptions;
async
Configuration
Set environment variables:
Or create a cortex.toml (see cortex.toml.example for all options):
= "your-client-id"
= "your-client-secret"
Examples
See the [examples/](examples/) directory for complete working examples covering all API areas.
For endpoint-by-endpoint compatibility tracking against the official API reference,
see [docs/api-parity.md](docs/api-parity.md).
Testing
Run the full crate test suite (unit tests, deterministic mock integration tests, and live smokes):
Protocol Modules
Types are grouped by domain:
protocol::rpc- JSON-RPC request/response/errorprotocol::constants-Methods,ErrorCodes,Streamsprotocol::headset- headset and config-mapping typesprotocol::session-SessionInfoprotocol::streams- stream event payloads and parsed stream structsprotocol::records- record/marker/export typesprotocol::profiles- profile types and actionsprotocol::training- detection/training + advanced BCI typesprotocol::auth- user login typesprotocol::subjects- subject and demographic types
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.