public override void sendMessage(string message)
        {
            SimCapiConsole.log(message, "Sent:");

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

            ExternalCalls.postMessage(message);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
            }
        }