private IObservable <WebsocketMessageWrapper> GetMessageStream() =>
        Observable.Using(() => new EventLoopScheduler(), scheduler =>
                         Observable.Create <WebsocketMessageWrapper>(async observer =>
        {
            // make sure the websocket is connected
            await InitializeWebSocket();
            // subscribe observer to message stream
            var subscription = new CompositeDisposable(_incomingMessages.ObserveOn(scheduler).Subscribe(observer))
            {
                // register the observer's OnCompleted method with the cancellation token to complete the sequence on disposal
                _internalCancellationTokenSource.Token.Register(observer.OnCompleted)
            };

            // add some debug output
            var hashCode = subscription.GetHashCode();
            subscription.Add(Disposable.Create(() => Debug.WriteLine($"incoming message subscription {hashCode} disposed")));
            Debug.WriteLine($"new incoming message subscription {hashCode} created");

            return(subscription);
        }));