/// <summary>オブザーバーに新しいデータを提供します。</summary> /// <param name="value">現在の通知情報。</param> public async void OnNext(SenderModel value) { if (value.Channel != Channel) { return; } if (Context.WebSocket.State != WebSocketState.Open) { CloseDisposable?.Dispose(); CloseDisposable = null; if (Context.WebSocket.State == WebSocketState.CloseReceived) { await Context.WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); } return; } if (value.IsClose) { OnCompleted(); } else { try { await Context.WebSocket.SendAsync( new ArraySegment <byte>(value.ReceiveData), value.IsBinary?WebSocketMessageType.Binary : WebSocketMessageType.Text , true, CancellationToken.None); } catch (Exception ex) { Debug.WriteLine(ex); } } }
public void Dispose() { CloseDisposable?.Dispose(); }