예제 #1
0
        void HandleOnTextMessageRecv(string socketMessage)
        {
            if (Logging)
            {
                Debug.LogError(socketMessage);
            }

            IDictionary m = socketMessage.Deserialize() as IDictionary;

            if (m == null)
            {
                return;
            }

            var msg = m ["msg"] as string;

            switch (msg)
            {
            case AddedMessage.added:
                var collection = m ["collection"] as string;
                if (Collections.Contains(collection))
                {
                    Collections[collection].Added(socketMessage);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record add. Creating a collection to handle it.\nMessage:\n{0}", socketMessage));
                }
                break;

            case ChangedMessage.changed:
                ChangedMessage cm = socketMessage.Deserialize <ChangedMessage>();
                if (Collections.Contains(cm.collection))
                {
                    Collections[cm.collection].Changed(cm.id, cm.cleared, cm.fields);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record change. Cannot recover this record later.\nMessage:\n{0}", socketMessage));
                }
                break;

            case RemovedMessage.removed:
                RemovedMessage rm = socketMessage.Deserialize <RemovedMessage>();
                if (Collections.Contains(rm.collection))
                {
                    Collections[rm.collection].Removed(rm.id);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record remove.\nMessage:\n{0}", socketMessage));
                }
                break;

            case ReadyMessage.ready:
                ReadyMessage readym = socketMessage.Deserialize <ReadyMessage>();
                foreach (string sub in readym.subs)
                {
                    if (Subscriptions.Contains(sub))
                    {
                        Subscriptions [sub].ready = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: A subscription ready message was received, but the subscription could not be found.\nSubscription: {0}", sub));
                    }
                }
                break;

            case ConnectedMessage.connected:
                ConnectedMessage connm = socketMessage.Deserialize <ConnectedMessage>();

                if (WillConnect != null)
                {
                    WillConnect(connm.session);
                }

                if (DidConnect != null)
                {
                    DidConnect(connm.session);
                }

                break;

            case ResultMessage.result:
                ResultMessage resultm = null;
                resultm = socketMessage.Deserialize <ResultMessage>();
                if (methods.ContainsKey(resultm.id))
                {
                    methods[resultm.id].Callback(resultm.error, resultm.methodResult);
                }
                else
                {
                    Debug.LogError(string.Format("LiveData: A result message was received, but the method could not be found.\nMethod: {0}", resultm.id));
                }
                break;

            case UpdatedMessage.updated:
                UpdatedMessage updatedm = socketMessage.Deserialize <UpdatedMessage>();
                foreach (var method in updatedm.methods)
                {
                    if (methods.ContainsKey(method))
                    {
                        methods [method].Updated = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: An updated message was received, but the method could not be found.\nMethod: {0}", method));
                    }
                }
                break;

            default:
                if (!socketMessage.Contains("server_id"))
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled message.\nMessage:\n{0}", socketMessage));
                }
                break;
            }
        }
예제 #2
0
        void HandleOnTextMessageRecv(string socketMessage)
        {
            IDictionary m = socketMessage.Deserialize() as IDictionary;

            if (m == null)
            {
                return;
            }

            var msg = m ["msg"] as string;

            switch (msg)
            {
            case AddedMessage.added:
                var collection = m ["collection"] as string;
                if (collections.ContainsKey(collection))
                {
                    collections[collection].Added(socketMessage);
                }
                break;

            case ChangedMessage.changed:
                ChangedMessage cm = socketMessage.Deserialize <ChangedMessage>();
                if (collections.ContainsKey(cm.collection))
                {
                    collections[cm.collection].Changed(cm.id, cm.cleared, cm.fields);
                }
                break;

            case RemovedMessage.removed:
                RemovedMessage rm = socketMessage.Deserialize <RemovedMessage>();
                if (collections.ContainsKey(rm.collection))
                {
                    collections[rm.collection].Removed(rm.id);
                }
                break;

            case ReadyMessage.ready:
                ReadyMessage readym = socketMessage.Deserialize <ReadyMessage>();
                foreach (string sub in readym.subs)
                {
                    foreach (string collectionName in subscriptionsToCollections[sub])
                    {
                        collections[collectionName].SubscriptionReady(sub);
                    }
                }
                break;

            case ConnectedMessage.connected:
                ConnectedMessage connm = socketMessage.Deserialize <ConnectedMessage>();
                if (OnConnected != null)
                {
                    OnConnected(connm.session);
                }
                break;

            case ResultMessage.result:
                ResultMessage resultm = socketMessage.Deserialize <ResultMessage>();
                if (methods.ContainsKey(resultm.id))
                {
                    methods[resultm.id].Callback(resultm.error, resultm.methodResult);
                }
                else
                {
                    Debug.LogError("DDPClient.ProcessQueue: Result ID not found.");
                }
                break;

            case "updated":
                break;

            default:
                if (!socketMessage.Contains("server_id"))
                {
                    Debug.Log(string.Format("DDPClient.ProcessQueue: Unhandled message.\nMessage:\n{0}", socketMessage));
                }
                break;
            }
        }