public static PusherEventData FromJson( string json )
        {
            PusherEventData data = new PusherEventData();
            Dictionary<string,object> dict = JsonHelper.Deserialize<Dictionary<string,object>>( json );
            if( dict != null ) {
                data.eventName = DataFactoryHelper.GetDictonaryValue( dict, "event", string.Empty );
                data.data = DataFactoryHelper.GetDictonaryValue( dict, "data", string.Empty );
                data.channel = DataFactoryHelper.GetDictonaryValue( dict, "channel", string.Empty );
            } else {
                Debug.LogWarning( "invalid pusher event data: '"+json+"'" );
            }

            return data;
        }
        public static PusherEventData FromJson(string json)
        {
            PusherEventData             data = new PusherEventData();
            Dictionary <string, object> dict = JsonHelper.Deserialize <Dictionary <string, object> >(json);

            if (dict != null)
            {
                data.eventName = DataFactoryHelper.GetDictonaryValue(dict, "event", string.Empty);
                data.data      = DataFactoryHelper.GetDictonaryValue(dict, "data", string.Empty);
                data.channel   = DataFactoryHelper.GetDictonaryValue(dict, "channel", string.Empty);
            }
            else
            {
                Debug.LogWarning("invalid pusher event data: '" + json + "'");
            }

            return(data);
        }
        private void websocket_MessageReceived(object sender, MessageEventArgs e)
        {
            Pusher.Log("Websocket message received: " + e.Data);

            if (e.IsPing)
            {
                Send("{\"event\": \"pusher:pong\"}");
                return;
            }

            PusherEventData message = PusherEventData.FromJson(e.Data);

            _pusher.EmitEvent(message.eventName, message.data);

            if (message.eventName.StartsWith("pusher"))
            {
                // Assume Pusher event
                switch (message.eventName)
                {
                case Constants.ERROR:
                    ParseError(message.data);
                    break;

                case Constants.CONNECTION_ESTABLISHED:
                    ParseConnectionEstablished(message.data);
                    break;

                case Constants.CHANNEL_SUBSCRIPTION_SUCCEEDED:

                    if (_pusher.Channels.ContainsKey(message.channel))
                    {
                        var channel = _pusher.Channels[message.channel];
                        channel.SubscriptionSucceeded(message.data);
                    }

                    break;

                case Constants.CHANNEL_SUBSCRIPTION_ERROR:

                    throw new PusherException("Error received on channel subscriptions: " + e.Data, ErrorCodes.SubscriptionError);

                case Constants.CHANNEL_MEMBER_ADDED:

                    // Assume channel event
                    if (_pusher.Channels.ContainsKey(message.channel))
                    {
                        var channel = _pusher.Channels[message.channel];

                        if (channel is PresenceChannel)
                        {
                            ((PresenceChannel)channel).AddMember(message.data);
                            break;
                        }
                    }

                    Pusher.LogWarning("Received a presence event on channel '" + message.channel + "', however there is no presence channel which matches.");
                    break;

                case Constants.CHANNEL_MEMBER_REMOVED:

                    // Assume channel event
                    if (_pusher.Channels.ContainsKey(message.channel))
                    {
                        var channel = _pusher.Channels[message.channel];

                        if (channel is PresenceChannel)
                        {
                            ((PresenceChannel)channel).RemoveMember(message.data);
                            break;
                        }
                    }

                    Pusher.LogWarning("Received a presence event on channel '" + message.channel + "', however there is no presence channel which matches.");
                    break;
                }
            }
            else
            {
                // Assume channel event
                if (_pusher.Channels.ContainsKey(message.channel))
                {
                    _pusher.Channels[message.channel].EmitEvent(message.eventName, message.data);
                }
            }
        }