예제 #1
0
        internal static void ForceSendVariables(Leanplum.SyncVariablesCompleted completedHandler)
        {
            if (!Leanplum.IsDeveloperModeEnabled)
            {
                LeanplumNative.CompatibilityLayer.LogError("Leanplum Error: ForceSendVariables requires Development mode");
                return;
            }

            Dictionary <string, object> parameters = new Dictionary <string, object>
            {
                [Constants.Params.VARIABLES] = Json.Serialize(valuesFromClient),
                [Constants.Params.KINDS]     = Json.Serialize(defaultKinds)
            };

            LeanplumUnityHelper.QueueOnMainThread(() => {
                Request request   = RequestBuilder.withSetVarsAction().AndParameters(parameters).CreateImmediate();
                request.Response += delegate(object response)
                {
                    completedHandler?.Invoke(true);
                };
                request.Error += delegate(Exception ex)
                {
                    LeanplumNative.CompatibilityLayer.LogError("Leanplum Error: ForceSyncVariables", ex);
                    completedHandler?.Invoke(false);
                };
                Leanplum.RequestSender.Send(request);
            });
        }
예제 #2
0
 internal static bool SendVariablesIfChanged()
 {
     if (devModeValuesFromServer != null && valuesFromClient != devModeValuesFromServer)
     {
         var parameters = new Dictionary <string, string>();
         parameters[Constants.Params.VARIABLES] = Json.Serialize(valuesFromClient);
         parameters[Constants.Params.KINDS]     = Json.Serialize(defaultKinds);
         LeanplumUnityHelper.QueueOnMainThread(() => LeanplumRequest.Post(Constants.Methods.SET_VARS, parameters).SendNow());
         return(true);
     }
     return(false);
 }
예제 #3
0
        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);
                    });
                }
            }
        }
예제 #4
0
        internal static void ForceSendVariables(Leanplum.SyncVariablesCompleted completedHandler)
        {
            var parameters = new Dictionary <string, string>();

            parameters[Constants.Params.VARIABLES] = Json.Serialize(valuesFromClient);
            parameters[Constants.Params.KINDS]     = Json.Serialize(defaultKinds);
            LeanplumUnityHelper.QueueOnMainThread(() => {
                LeanplumRequest setVarsReq = LeanplumRequest.Post(Constants.Methods.SET_VARS, parameters);
                setVarsReq.Response       += delegate(object response)
                {
                    completedHandler?.Invoke(true);
                };
                setVarsReq.Error += delegate(Exception ex)
                {
                    LeanplumNative.CompatibilityLayer.LogError("Leanplum Error: ForceSyncVariables", ex);
                    completedHandler?.Invoke(false);
                };
                setVarsReq.SendNow();
            });
        }