> For the complete documentation index, see [llms.txt](https://bonspiel-games.gitbook.io/cortex-unity-plugin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bonspiel-games.gitbook.io/cortex-unity-plugin/cortex/methods.md).

# Methods

List of methods available in the base Cortex class

## Start

Initialize connection to the Emotiv launcher, enabling use of the API. It is best to delay other functionality until the connection has been [authorized](/cortex-unity-plugin/cortex/events.md#authorized), or until [the connection state](/cortex-unity-plugin/cortex/events.md#connection-state-changed) has been updated to authorized.

```csharp
void Start(string clientId, string clientSecret, string appURL = "wss://localhost:6868", string emotivAppsPath = "C:\\Program Files\\EmotivApps", bool logs = false, bool streamPrint = false, string license = "");
```

| Parameter      | Description                                                                                 |
| -------------- | ------------------------------------------------------------------------------------------- |
| clientId       | client id of your cortex application                                                        |
| clientSecret   | client secret of your cortex application                                                    |
| appURL         | url through which to connect to the emotiv launcher                                         |
| emotivAppsPath | filepath where the emotiv launcher is installed, used to check if the launcher is installed |
| logs           | print logs to the debug console                                                             |
| streamPrint    | print all incoming stream data to the debug console                                         |
| license        | cortex api license, required for EEG access, which the plugin does not currently support    |

**Example:**

```csharp
using UnityEngine;
using CortexPlugin;

public class ConnectToCortex : MonoBehaviour
{
    [Header("credentials")]
    public string clientId;
    public string clientSecret;

    [Header("settings")]
    public bool printLogs;
    public bool printDataStreams;

    void Awake()
    {
        Cortex.Start(clientId, clientSecret, logs: printLogs, streamPrint: printDataStreams);
    }

    private void OnApplicationQuit()
    {
        Cortex.Stop();
    }
}
```

## Query Headsets

Queries a list of available headsets, triggering [Headset Query Result](/cortex-unity-plugin/cortex/events.md#headset-query-result).

-> [Headset Query Result](/cortex-unity-plugin/cortex/events.md#headset-query-result)

```csharp
void QueryHeadsets();
```

## Start Session

Opens a session and starts data streams with the headset, provided it has been connected. If successful, will trigger [Data Stream Started](/cortex-unity-plugin/cortex/events.md#data-stream-started).

->-> [Data Stream Started](/cortex-unity-plugin/cortex/events.md#data-stream-started)

```csharp
void StartSession(string headsetId);
```

**Example:**

```csharp
public void PairWithHeadset(Headset target)
{
    if(target.status == "connected")
    {
        Cortex.StartSession(target.headsetId);
    }
}
```

## Connect Device

Pairs a device with the Emotiv launcher, needed to start a session. Devices may already be connected, which will result in an error event.

-> [Device Connected](/cortex-unity-plugin/cortex/events.md#device-connected)

```csharp
void ConnectDevice(string headsetId);
```

**Example:**

```csharp
string pairingHeadset;

public void PairWithHeadset(Headset target)
{
    if(target.status == "connected")
    {
        Cortex.StartSession(target.headsetId);
    }
    else
    {
        pairingHeadset = target.headsetId;
        Cortex.ConnectDevice(target.headsetId);
        Cortex.HeadsetConnected += PairWithNewlyConnectedHeadset;
    }
}

void PairWithNewlyConnectedHeadset(HeadsetConnectEventArgs args)
{
    if (args.HeadsetId != pairingHeadset)
        return;

    Cortex.StartSession(args.HeadsetId);
    pairingHeadset = "";
    Cortex.HeadsetConnected -= PairWithNewlyConnectedHeadset;
}
```

## End Session

Ends a headset session.

-> [Data Stream Ended](/cortex-unity-plugin/cortex/events.md#data-stream-ended)

```csharp
void EndSession(string sessionId);
```

## End Session By Headset

End a headset session with a headset id rather than a session id.

-> [Data Stream Ended](/cortex-unity-plugin/cortex/events.md#data-stream-ended)

```csharp
void EndSessionByHeadset(string headsetId);
```

## Get Session By Headset

Gets the session id associated with the given headset if it exists.

```csharp
string GetSessionByHeadset(string headsetId);
```

## End Most Recent Session

Ends the session that was started most recently, regardless of activity.

-> [Data Stream Ended](/cortex-unity-plugin/cortex/events.md#data-stream-ended)

```csharp
void EndMostRecentSession();
```

## Stop

Closes the Cortex connection.

```csharp
void Stop();
```
