Example #1
0
        private static void ProcessReadyFrame(ReadyFrame readyFrame)
        {
            var lastMessagesMapping = new Dictionary <string, Message>();

            readyFrame.data.lastMessages.ForEach(message =>
                                                 lastMessagesMapping.Add(message.id, message));
            var lobbyChannels = readyFrame.data.lobbyChannels
                                .Where(c => c.liveChannelId == null || c.liveChannelId.isEmpty())
                                .Where(c => c.workspaceId == DefaultWorkspaceId)
                                .ToDictionary(c => c.id);

            readyFrame.data.users.ForEach(user => Users[user.id] = user);
            readyFrame.data.readStates?.ForEach(state => ReadStates[state.channelId] = state);

            foreach (var c in lobbyChannels.Values)
            {
                if (c.lastMessageId != null)
                {
                    c.lastMessage = lastMessagesMapping[c.lastMessageId];
                }

                if (OverrideNames.ContainsKey(c.id))
                {
                    c.name = OverrideNames[c.id];
                }
            }
            foreach (var pair in readyFrame.data.groupMap)
            {
                Groups.putIfAbsent(pair.Key, () => pair.Value);
            }

            foreach (var keyValuePair in lobbyChannels)
            {
                Channels[keyValuePair.Key]  = keyValuePair.Value;
                PullFlags[keyValuePair.Key] = true;
            }

            _pingTimer          = new Timer(15000);
            _timeoutTimer       = new Timer(15000);
            _pingTimer.Elapsed += (sender, args) =>
            {
                var ts      = (long)DateTime.UtcNow.Subtract(Epoch).TotalMilliseconds;
                var frameSz = "{\"op\":9,\"d\": {\"ts\":" + ts + "}}";
                _lastPingTimestamp    = ts;
                _timeoutTimer.Enabled = true;
                _client.Send(frameSz);
            };
            _timeoutTimer.Elapsed  += (sender, args) => { _client.Close(); };
            _timeoutTimer.AutoReset = false;
            _pingTimer.AutoReset    = false;

            _pingTimer.Enabled = true;
            socketConnected    = true;
            reconnecting       = false;
        }
Example #2
0
 /// <summary>
 /// Вызывает событие готовности кадра
 /// </summary>
 public void CallReadyFrame()
 {
     ReadyFrame?.Invoke(this, EventArgs.Empty);
 }