I have a stream that allows bi-directional communication between a terminal on the other side of it (it uses websockets). I got inputs working on a console app by using:
_ = Console.OpenStandardInput().CopyToAsync(stream).ConfigureAwait(false); Now i want the same but using the input from a client to my signalR hub. I tried using a static Stream instance and writing to that from a seperate method:
public ContainerStreams containerStream { get; }
public ContainerShellHub(ContainerStreams container)
{
containerStream = container;
}
public async Task SendMessage(string message)
{
var sw = new StreamWriter(containerStream.Stream);
sw.WriteLine(message);
sw.Flush();
}
public async IAsyncEnumerable<string> GetLogs(
string clusterId,
[EnumeratorCancellation]
CancellationToken cancellationToken)
{
...
var websocket =
await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "sh",
pod.Spec.Containers[0].Name);
var demux = new StreamDemuxer(websocket);
demux.Start();
var stream = demux.GetStream(ChannelIndex.StdOut, ChannelIndex.StdIn);
_ = containerStream.Stream.CopyToAsync(stream).ConfigureAwait(false);
...
}
This however does not work, i cannot find a way to get my users inputs into the stream