/// <summary> /// Set up and create a new streaming layer based on our light map /// </summary> /// <param name="ct">A cancellation token.</param> public async void StartStream(CancellationToken ct) { if (Bd.Id == null || Bd.Key == null || Bd.Lights == null || Bd.Groups == null) { LogUtil.Write("Bridge is not authorized.", "WARN"); return; } LogUtil.Write("Hue: Starting stream..."); SetClient(); try { // Make sure we are not already streaming. var _ = StreamingSetup.StopStream(_client, Bd); if (Streaming) { ResetColors(); } Streaming = false; } catch (SocketException e) { LogUtil.Write("Socket exception, probably our bridge wasn't streaming. Oh well: " + e.Message); } if (ct == null) { throw new ArgumentException("Invalid cancellation token."); } // Get our light map and filter for mapped lights // Grab our stream // Save previous light state(s) before stopping RefreshData(); DataUtil.InsertCollection <BridgeData>("bridges", Bd); StreamingGroup stream; try { stream = await StreamingSetup.SetupAndReturnGroup(_client, Bd, ct); } catch (Exception e) { LogUtil.Write("SException (Probably tried stopping/starting too quickly): " + e.Message, "WARN"); return; } // This is what we actually need if (stream == null) { LogUtil.Write("Error fetching bridge stream.", "WARN"); return; } _entLayer = stream.GetNewLayer(true); LogUtil.Write($"Hue: Stream started: {IpAddress}"); while (!ct.IsCancellationRequested) { Streaming = true; } StopStream(); }
public void StopStream() { LogUtil.Write($"Hue: Stopping Stream: {IpAddress}..."); var _ = StreamingSetup.StopStream(_client, Bd); if (Streaming) { ResetColors(); } Streaming = false; LogUtil.Write("Hue: Streaming Stopped."); }