Skip to content

Commit

Permalink
feat: add endpoint info messenger
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-welker committed Apr 9, 2024
1 parent 2d66b7a commit dc5e5c3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 32 deletions.
4 changes: 4 additions & 0 deletions src/NvxEpi/Devices/NvxBaseDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ protected void AddMcMessengers()

mc.AddDeviceMessenger(secondaryAudioMessenger);

var infoMessenger = new EndpointInfoMessenger($"{Key}-endpointInfo", $"/device/{Key}", this);

mc.AddDeviceMessenger(infoMessenger);

if (!(this is IHdmiInput hdmiInputDevice))
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "{key:l} does NOT implement IHdmiInput interface", this, Key);
Expand Down
70 changes: 70 additions & 0 deletions src/NvxEpi/McMessengers/EndpointInfoMessenger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NvxEpi.Devices;
using NvxEpi.Services.Feedback;
using PepperDash.Essentials.AppServer.Messengers;
using PepperDash.Essentials.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NvxEpi.McMessengers
{
public class EndpointInfoMessenger:MessengerBase
{
private readonly NvxBaseDevice device;

private readonly StringFeedback deviceNameFeedback;
public EndpointInfoMessenger(string key, string path, NvxBaseDevice device): base(key, path, device)
{
this.device = device;

deviceNameFeedback = device.Feedbacks.FirstOrDefault(fb => fb.Key == DeviceNameFeedback.Key) as StringFeedback;

if (deviceNameFeedback == null)
{
return;
}

deviceNameFeedback.OutputChange += SendUpdate;
}

protected override void RegisterActions()
{
base.RegisterActions();

AddAction("/fullStatus", SendFullStatus);

}

private void SendFullStatus(string id, JToken content)
{
PostStatusMessage(new EndpointInfoStateMessage
{
DeviceName = deviceNameFeedback?.StringValue ?? string.Empty
});
}

private void SendUpdate(object sender, FeedbackEventArgs args)
{
PostStatusMessage(JToken.FromObject(new EndpointInfoUpdateMessage
{
DeviceName = deviceNameFeedback?.StringValue ?? string.Empty
}));
}
}

public class EndpointInfoStateMessage : DeviceStateMessageBase
{
[JsonProperty("friendlyName")]
public string DeviceName { get; set; }
}

public class EndpointInfoUpdateMessage
{
[JsonProperty("friendlyName")]
public string DeviceName { get; set; }
}
}
32 changes: 0 additions & 32 deletions src/NvxEpi/McMessengers/VideoStatusMessenger.cs

This file was deleted.

0 comments on commit dc5e5c3

Please sign in to comment.