Nac*_*cho 7 signalr asp.net-core c#-8.0
我正在尝试创建一个应用程序,该应用程序使用 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,我想以这种方式使用它们。
我尝试使用 aQueue来存储数据(上传时入队,下载时出队),但两个连接的客户端之间的内存未共享。
另外,我不知道我是否可以使用该方法,Clients.Others.SendAsync()因为它用于从普通 SignalR 应用程序调用方法,并且在 JavaScript 库的文档中它使用方法stream()。
connection.start().then(() => {
console.log("connected");
connection.stream("DownloadStream").subscribe({
next: item => {
console.log(item);
},
complete: () => {
console.log("completed");
},
error: err => {
console.log(err);
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1587 次 |
| 最近记录: |