private void OnApplicationQuit()
 {
     LeanplumNative.CompatibilityLayer.FlushSavedSettings();
     if (LeanplumNative.calledStart)
     {
         LeanplumNative.Stop();
     }
     LeanplumNative.isStopped = true;
 }
        private void OnSocketMessage(object obj, MessageEventArgs e)
        {
            if (e.Message.MessageType == SocketIOMessageTypes.Event &&
                !String.IsNullOrEmpty(e.Message.MessageText))
            {
                IDictionary <string, object> messageReceived =
                    Json.Deserialize(e.Message.MessageText) as IDictionary <string, object>;
                string eventName = messageReceived.ContainsKey("name") ? messageReceived["name"] as string: "";

                if (eventName == "updateVars")
                {
                    onUpdateVars();
                }
                else if (eventName == "getVariables")
                {
                    bool sentValues = VarCache.SendVariablesIfChanged();
                    Dictionary <string, bool> response = new Dictionary <string, bool>();
                    response.Add("updated", sentValues);
                    socketIOClient.Emit("getContentResponse", response);
                }
                else if (eventName == "getActions")
                {
                    // Unsupported in LeanplumNative.
                    Dictionary <string, bool> response = new Dictionary <string, bool>();
                    response.Add("updated", false);
                    socketIOClient.Emit("getContentResponse", response);
                }
                else if (eventName == "registerDevice")
                {
                    IDictionary <string, object> packetData = (IDictionary <string, object>)
                                                                  ((IList <object>)messageReceived[Constants.Keys.ARGS])[0];
                    string email = (string)packetData["email"];
                    LeanplumUnityHelper.QueueOnMainThread(() =>
                    {
                        LeanplumNative.OnHasStartedAndRegisteredAsDeveloper();
                        LeanplumNative.CompatibilityLayer.Log(
                            "Your device is registered to " + email + ".");
                    });
                }
                else if (eventName == "trigger")
                {
                    IDictionary <string, object> packetData = (IDictionary <string, object>)
                                                                  ((IList <object>)messageReceived[Constants.Keys.ARGS])[0];

                    // Trigger Preview
                    LeanplumUnityHelper.QueueOnMainThread(() =>
                    {
                        onActionTrigger(packetData);
                    });
                }
            }
        }
        private void OnApplicationPause(bool isPaused)
        {
            if (!LeanplumNative.calledStart)
            {
                return;
            }

            if (isPaused)
            {
                LeanplumNative.Pause();
            }
            else
            {
                LeanplumNative.Resume();
            }
        }