Example #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);
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="raw"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        private static IInternalMessage ParseMethod(string raw, dynamic d)
        {
            IInternalMessage ret;

            switch (d.method)
            {
            case "optOutEvents":
            {
                var id   = (long)d.id;
                var args = (string[])d.arguments;
                ret = new OptOutEventsMethod(id, args);
            }
            break;

            case "auth":
            {
                var id        = (long)d.id;
                var channelId = (long)d.arguments[0];
                var myId      = (long?)d.arguments[1];
                var token     = (string)d.arguments[2];
                //2019/10/29 d.arguments[3]が何なのか不明。

                if (myId.HasValue)
                {
                    ret = new AuthMethod(id, channelId, myId.Value, token);
                }
                else
                {
                    ret = new AuthMethod(id, channelId);
                }
            }
            break;

            default:
                ret = new UnknownMessage(raw);
                break;
            }

            return(ret);
        }