コード例 #1
0
        private void ParseError(string data)
        {
            Dictionary <string, object> dict = JsonHelper.Deserialize <Dictionary <string, object> >(data);
            string     message      = DataFactoryHelper.GetDictonaryValue(dict, "message", string.Empty);
            string     errorCodeStr = DataFactoryHelper.GetDictonaryValue(dict, "code", ErrorCodes.Unkown.ToString());
            ErrorCodes error        = DataFactoryHelper.EnumFromString <ErrorCodes>(errorCodeStr);

            throw new PusherException(message, error);
        }
コード例 #2
0
        private void ParseConnectionEstablished(string data)
        {
            Dictionary <string, object> dict = JsonHelper.Deserialize <Dictionary <string, object> >(data);

            _socketId = DataFactoryHelper.GetDictonaryValue(dict, "socket_id", string.Empty);

            ChangeState(ConnectionState.Connected);

            if (Connected != null)
            {
                Connected(this);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        private void SendChannelAuthData(string channelName, string jsonAuth)
        {
            // parse info from json data
            Dictionary <string, object> authDict = JsonHelper.Deserialize <Dictionary <string, object> >(jsonAuth);
            string authFromMessage        = DataFactoryHelper.GetDictonaryValue(authDict, "auth", string.Empty);
            string channelDataFromMessage = DataFactoryHelper.GetDictonaryValue(authDict, "channel_data", string.Empty);

            _connection.Send(JsonHelper.Serialize(new Dictionary <string, object>()
            {
                { "event", Constants.CHANNEL_SUBSCRIBE },
                {
                    "data", new Dictionary <string, object>()
                    {
                        { "channel", channelName },
                        { "auth", authFromMessage },
                        { "channel_data", channelDataFromMessage }
                    }
                }
            }));
        }