示例#1
0
    /// <summary>
    /// This thread creates a connection with the cortex service through the websocket and then calls the login, createSession and subscribe methods.
    /// </summary>
    private IEnumerator Initialize()
    {
        w = new WebSocket(new Uri(EMOTIV_URL));
        yield return(StartCoroutine(w.Connect()));

        StartCoroutine(GetReply());

        Dictionary <string, string> loginDictionary = new Dictionary <string, string>();

        loginDictionary.Add("username", username);
        loginDictionary.Add("password", userPassword);
        loginDictionary.Add("client_id", CLIENT_ID);
        loginDictionary.Add("client_secret", CLIENT_SECRET);
        w.SendString(
            CortexJsonUtility.GetMethodJSON
            (
                "login",
                (int)MethodsID.Login,
                loginDictionary
            ));

        Authorize();
        StartCoroutine(CreateSession());
        StartCoroutine(SubscribeStreams());
    }
示例#2
0
 /// <summary>
 /// Calls a training method with some given parameters.
 /// </summary>
 /// <param name="parameters"></param>
 public void SendTrainMessage(Dictionary <string, string> parameters)
 {
     w.SendString(
         CortexJsonUtility.GetMethodJSON
         (
             "training",
             (int)MethodsID.Training,
             parameters
         ));
 }
示例#3
0
    /// <summary>
    /// Calls the logout method
    /// </summary>
    public void Logout()
    {
        Dictionary <string, string> logoutDictionary = new Dictionary <string, string>();

        logoutDictionary.Add("username", username);
        w.SendString(
            CortexJsonUtility.GetMethodJSON
            (
                "logout",
                (int)MethodsID.Logout,
                logoutDictionary
            ));
    }
示例#4
0
    /// <summary>
    /// Calls the authorize method with the corresponding client id and secret.
    /// </summary>
    void Authorize()
    {
        Dictionary <string, string> authorizeDictionary = new Dictionary <string, string>();

        authorizeDictionary.Add("client_id", CLIENT_ID);
        authorizeDictionary.Add("client_secret", CLIENT_SECRET);

        w.SendString(
            CortexJsonUtility.GetMethodJSON
            (
                "authorize",
                (int)MethodsID.Authorize,
                authorizeDictionary
            ));
    }
示例#5
0
    /// <summary>
    /// Waits until the _auth token is gathered, then it calls the createSession method.
    /// </summary>
    IEnumerator CreateSession()
    {
        while (_auth == null)
        {
            yield return(0);
        }

        Dictionary <string, string> sessionDictionary = new Dictionary <string, string>();

        sessionDictionary.Add("_auth", _auth);
        sessionDictionary.Add("status", "open");

        w.SendString(
            CortexJsonUtility.GetMethodJSON
            (
                "createSession",
                (int)MethodsID.CreateSession,
                sessionDictionary
            ));
    }