Nov 26 2021 01:25 AM - edited Nov 26 2021 01:52 AM
Hi,
I'm having a problem with the disposing of a Blazor Web Assembly page containing an img tag having as src the path of a camera stream. In short, when I leave the page, the stream is not interrupted and remains active, wasting bandwitdh and resources.
I've the following Blazor page:
@page "/counter"
@implements IDisposable
<img src="@imgSrc" />
<br />
<button @onclick="OnBtnClicked">Hide/Show Image</button>
@code {
private string imgSrc;
private string imgPath = "http://user:password@192.168.x.x/axis-cgi/mjpg/video.cgi";
protected override async void OnInitialized() {
imgsrc=imgPath;
}
private void OnBtnClicked() {
imgsrc=(imgSrc.Equals("") ? imgPath : "");
StateHasChanged();
}
public void Dispose() {
Console.WriteLine("Disposing!");
}
}
When I enter counter page the streaming starts, and I can see badwitdh increasing from 0Mbps to about 4Mbps from Task Manager; if I click the button to "hide" the image, the bandwitdh goes back to 0Mbps.
However, if while the live stream is being shown I navigate e.g. to Home page, the bandwitdh remains to 4Mbps. At this point, even if I go back to the counter page and click the button to hide the image, even if the image correctly hides, the bandwitdh remains 4Mbps.
It's like an underlying connection remains active and Blazor has no means to stop it, and disposing the page does not stop it either.
Do you know if there is a clean way to stop this stream?
Thank you very much!