Пример #1
0
        private void Websocket_Received(object sender, string e)
        {
            var raw = e;

            Debug.WriteLine(raw);
            try
            {
                var internalMessage = InternalMessageParser.Parse(raw, _methodReplyDict);
                if (internalMessage is WelcomeEvent)
                {
                    //    var optOutMethod = new OptOutEventsMethod(0, new string[] { "UserJoin", "UserLeave" });
                    //    Send(optOutMethod);
                    //}
                    //else if(internalMessage is OptOutEventsReply)
                    //{
                    AuthMethod authMethod;
                    if (MyUserId.HasValue)
                    {
                        authMethod = new AuthMethod(1, ChannelId, MyUserId.Value, Token);
                    }
                    else
                    {
                        authMethod = new AuthMethod(1, ChannelId);
                    }
                    Send(authMethod);
                }
                else if (internalMessage is UnknownMessage unknown)
                {
                    _logger.LogException(new ParseException(unknown.Raw));
                }
                //        switch (internalMessage)
                //        {
                //            case ChatMessageData chat:
                //                var context = CreateMessageContext(chat);
                //                RaiseMessageReceived(context);
                //                break;
                //            case UserUpdateEvent userUpdate:
                //                break;
                //            case DeleteMessageEvent deleteMessage:
                //                break;
                //            default:
                //                break;
                //        }
                //var mixerMessage = Tools.Convert(internalMessage);
                //RaiseMessageReceived(mixerMessage);
                RaiseMessageReceived(internalMessage);
            }
            catch (ParseException ex)
            {
                _logger.LogException(ex);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            }
        }
        private void WebSocket_Received(object sender, string e)
        {
            var raw = e;

            Debug.WriteLine(raw);
            try
            {
                var internalMessage = InternalMessageParser.Parse(raw, _methodReplyDict);
                if (internalMessage is WelcomeEvent)
                {
                    //    var optOutMethod = new OptOutEventsMethod(0, new string[] { "UserJoin", "UserLeave" });
                    //    Send(optOutMethod);
                    //}
                    //else if(internalMessage is OptOutEventsReply)
                    //{
                    AuthMethod authMethod;
                    if (_myUserId.HasValue)
                    {
                        authMethod = new AuthMethod(1, _channelId, _myUserId.Value, _token);
                    }
                    else
                    {
                        authMethod = new AuthMethod(1, _channelId);
                    }
                    Send(authMethod);
                }
                else if (internalMessage is UnknownMessage unknown)
                {
                    _logger.LogException(new ParseException(unknown.Raw));
                }
                MessageReceived?.Invoke(this, internalMessage);
            }
            catch (ParseException ex)
            {
                _logger.LogException(ex);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            }
        }