Created
April 19, 2019 10:46
-
-
Save NeelBhatt/95afe97b8a14698bb58f3057d9e4fc8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class PiMonitRWorker : BackgroundService | |
{ | |
private readonly IHubContext<PiMonitRHub> _piMonitRHub; | |
private readonly PiCameraService _piCameraService; | |
private readonly FaceClientCognitiveService _faceClientCognitiveService; | |
public PiMonitRWorker(IHubContext<PiMonitRHub> piMonitRHub, | |
PiCameraService piCameraService, FaceClientCognitiveService faceClientCognitiveService) | |
{ | |
_piMonitRHub = piMonitRHub; | |
_piCameraService = piCameraService; | |
_faceClientCognitiveService = faceClientCognitiveService; | |
} | |
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | |
{ | |
while (!stoppingToken.IsCancellationRequested) | |
{ | |
if (!PiMonitRHub._isStreamRunning) | |
{ | |
var stream = await _piCameraService.CapturePictureAsStream(); | |
if (await _faceClientCognitiveService.IsCryingDetected(stream)) | |
{ | |
await _piMonitRHub.Clients.All.SendAsync("ReceiveNotification", "Baby Crying Detected! You want to start streaming?"); | |
} | |
} | |
//Run the background service for every 10 seconds | |
await Task.Delay(10000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment