示例#1
0
        public void getData(string simId, string key, GetDataRequestSuccessDelegate successDelegate, GetDataRequestErrorDelegate errorDelegate)
        {
            string dataReturnString = ExternalCalls.getKeyPairSessionStorage(simId, key);

            // returns json string defined as below

            /*
             *  var response =
             *  {
             *      success: true,
             *      key: javaKey,
             *      value: null,
             *      exists: false
             *  };
             */

            // Parse return string from external call
            JObject jObject = JsonConvert.DeserializeObject <JObject>(dataReturnString);

            JProperty propSuccess = jObject.Property("success");
            //JProperty propKey = jObject.Property("key");
            JProperty propValue  = jObject.Property("value");
            JProperty propExists = jObject.Property("exists");

            bool success = propSuccess.Value.ToObject <bool>();


            Message.GetDataResponse getDataResponse = new Message.GetDataResponse();
            getDataResponse.handshake = Transporter.getInstance().getHandshake();
            getDataResponse.simId     = simId;
            getDataResponse.key       = key;
            getDataResponse.value     = null;
            getDataResponse.exists    = propExists.ToObject <bool>();

            if (success == true)
            {
                getDataResponse.responseType = "success";
            }
            else
            {
                getDataResponse.responseType = "error";
            }

            if (propValue.Value != null)
            {
                getDataResponse.value = propValue.Value.ToObject <string>();
            }

            if (success == true)
            {
                successDelegate(getDataResponse);
            }
            else
            {
                errorDelegate(getDataResponse);
            }
        }
示例#2
0
        public void setDomainToShortform()
        {
            string currentDomain = ExternalCalls.getDomain();

            if (currentDomain.IndexOf("smartsparrow.com") == -1)
            {
                return;
            }

            ExternalCalls.setDomain("smartsparrow.com");
        }
        public override void sendMessage(string message)
        {
            SimCapiConsole.log(message, "Sent:");

            if (ExternalCalls.isInIFrame() == false)
            {
                return;
            }

            ExternalCalls.postMessage(message);
        }
示例#4
0
        public bool setDataRequest(string simId, string key, string value, SetDataRequestSuccessDelegate successDelegate, SetDataRequestErrorDelegate errorDelegate)
        {
            if (simId == null)
            {
                throw new System.Exception("setDataRequest() called with null simId!");
            }

            if (key == null)
            {
                throw new System.Exception("setDataRequest() called with null key!");
            }

            if (value == null)
            {
                throw new System.Exception("setDataRequest() called with null value!");
            }

            // Use local data fallback
            if (!ExternalCalls.isInIFrame() || ExternalCalls.isInAuthor())
            {
                _simCapiLocalData.setData(simId, key, value, successDelegate);
                return(true);
            }

            // Make sure dictionary exists for simId
            if (_setRequests.ContainsKey(simId) == false)
            {
                _setRequests[simId] = new Dictionary <string, SimCapiSetRequestCallback>();
            }

            // dataRequest in progress, add to queue
            if (_setRequests[simId].ContainsKey(key) == true)
            {
                _setRequests[simId][key].queuedSetRequest = new SimCapiQueuedSetRequest(value, successDelegate, errorDelegate);
                return(false);
            }

            _setRequests[simId][key] = new SimCapiSetRequestCallback(successDelegate, errorDelegate);

            string jsonString = SimCapiJsonMaker.create_SET_DATA_REQUEST(_handshake, key, value, simId);

            if (_handshake.authToken == null)
            {
                _pendingMessagesForHandshake.Add(jsonString);
            }
            else
            {
                sendMessage(jsonString);
            }

            return(true);
        }
示例#5
0
        void createMessageReciverObject()
        {
            if (_messageReceiver != null)
            {
                return;
            }

            string receiverName = generateName();

            ExternalCalls.bindMessageListener(receiverName);

            _messageReceiver = new GameObject(receiverName);
            SimCapiMono simCapiMono = _messageReceiver.AddComponent <SimCapiMono>();

            simCapiMono.transporter = this;
        }
示例#6
0
        public void notifyOnReady()
        {
            if (_handshake.authToken == null)
            {
                _pendingOnReady = true;

                // once everything is ready, we request a handshake from the viewer.
                requestHandshake();
            }
            else
            {
                string onReadyJsonString = SimCapiJsonMaker.create_ON_READY(_handshake);

                sendMessage(onReadyJsonString);
                _pendingOnReady = false;

                foreach (HandshakeDelegate handshakeDelegate in _handshakeListeners)
                {
                    handshakeDelegate(_handshake);
                }

                _handshakeComplete = true;
                _handshakeListeners.Clear();

                // send initial value snapshot
                notifyValueChange();
            }

            if (!ExternalCalls.isInIFrame())
            {
                Message.InitialSetupComplete initialSetupComplete = new Message.InitialSetupComplete();
                initialSetupComplete.handshake                = _handshake;
                initialSetupComplete.handshake.config         = new SimCapiConfig();
                initialSetupComplete.handshake.config.context = "VIEWER";

                handleInitialSetupComplete(initialSetupComplete);
            }
        }
示例#7
0
        public void setData(string simId, string key, string value, SetDataRequestSuccessDelegate successDelegate)
        {
            bool success = ExternalCalls.setKeyPairSessionStorage(simId, key, value);

            SimCapiConsole.log("SimCapiLocalData set data: " + success.ToString());

            if (success == false)
            {
                return;
            }

            Message.SetDataResponse setDataResponse = new Message.SetDataResponse();
            setDataResponse.handshake    = Transporter.getInstance().getHandshake();
            setDataResponse.simId        = simId;
            setDataResponse.key          = key;
            setDataResponse.value        = value;
            setDataResponse.responseType = "success";

            if (success == true)
            {
                successDelegate(setDataResponse);
            }
        }