public InteractiveSocket(SocketOptions options)
        {
            _message = Observable.Create <string>(obs =>
            {
                return(Observable.Merge(_open.Select(x => true), _close.Select(x => false)).Subscribe(async isOpen =>
                {
                    if (isOpen && !_loopRunning)
                    {
                        _loopRunning = true;
                        Debug.WriteLine("Running loop");
                        ArraySegment <byte> buffer = new ArraySegment <byte>(new byte[8192]);
                        WebSocketReceiveResult result;
                        string stringMessage = "";
                        while (_socket.State == WebSocketState.Open)
                        {
                            do
                            {
                                result = await _socket.ReceiveAsync(buffer, CancellationToken.None);
                                stringMessage += Encoding.UTF8.GetString(buffer.Array, 0, result.Count);
                            }while (!result.EndOfMessage);
                            Debug.WriteLine(stringMessage);
                            obs.OnNext(stringMessage);
                            stringMessage = "";
                        }
                    }
                }));
            });

            SetOptions(options);

            _message.Subscribe(msg =>
            {
                ExtractMessage(msg);
            });

            _open.Subscribe(_ =>
            {
                _options.ReconnectionPolicy.Reset();
                _state = SocketState.Connected;
                foreach (var packet in _queue)
                {
                    var task = SendAsync(packet);
                }
            });

            _close.Subscribe(closeEvent =>
            {
                throw new NotImplementedException();
            });
        }
 public void SetOptions(SocketOptions options)
 {
     _options = options;
 }