我正在尝试创建一个应用程序,该应用程序使用 RaspberryPi 摄像头录制视频并将该视频流式传输到 Web 浏览器。
我已经设法使用JavaScript SignalR 库建立了单独的Client->Server流和Server->Client流连接,现在我需要以某种方式连接服务器上的这两个函数,以便将一大块数据发送到浏览器一旦从 RaspberryPi 收到它。
这些是 Microsoft 文档中的两个示例:
public async Task UploadStream(IAsyncEnumerable<string> stream)
{
await foreach (var item in stream)
{
// Here I need to send the chunk (item) to the browser
Debug.WriteLine(item);
}
}
Run Code Online (Sandbox Code Playgroud)
public async IAsyncEnumerable<string> DownloadStream(CancellationToken cancellationToken)
{
while (true) // While there is data to stream
{
yield return "data"; // Return chunks to the browser
}
}
Run Code Online (Sandbox Code Playgroud)
这些示例是使用 C# 8.0 编写的IAsyncEnumerable,我想以这种方式使用它们。 …