mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 13:15:03 +00:00
feat: Deprecate IHasCamerasMessenger; introduce new controls
Mark IHasCamerasMessenger as obsolete and replace it with IHasCamerasWithControlMessenger, which adds functionality for devices with camera controls. A new state message class, IHasCamerasWithControlsStateMessage, has been added to encapsulate camera state. Update MobileControlSystemController to use the new messenger implementation.
This commit is contained in:
@@ -1,17 +1,14 @@
|
|||||||
using System;
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using PepperDash.Essentials.Devices.Common.Cameras;
|
using PepperDash.Essentials.Devices.Common.Cameras;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.AppServer.Messengers
|
namespace PepperDash.Essentials.AppServer.Messengers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Messenger for devices that implement the IHasCameras interface.
|
/// Messenger for devices that implement the IHasCameras interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("Use IHasCamerasWithControlsMessenger instead. This class will be removed in a future version")]
|
||||||
public class IHasCamerasMessenger : MessengerBase
|
public class IHasCamerasMessenger : MessengerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using PepperDash.Essentials.Devices.Common.Cameras;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.AppServer.Messengers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Messenger for devices that implement the IHasCameras interface.
|
||||||
|
/// </summary>
|
||||||
|
public class IHasCamerasWithControlMessenger : MessengerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Device being bridged that implements IHasCameras interface.
|
||||||
|
/// </summary>
|
||||||
|
public IHasCamerasWithControls CameraController { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Messenger for devices that implement IHasCameras interface.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="cameraController"></param>
|
||||||
|
/// <param name="messagePath"></param>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
|
public IHasCamerasWithControlMessenger(string key, string messagePath, IHasCamerasWithControls cameraController)
|
||||||
|
: base(key, messagePath, cameraController)
|
||||||
|
{
|
||||||
|
CameraController = cameraController ?? throw new ArgumentNullException("cameraController");
|
||||||
|
CameraController.CameraSelected += CameraController_CameraSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CameraController_CameraSelected(object sender, CameraSelectedEventArgs<IHasCameraControls> e)
|
||||||
|
{
|
||||||
|
PostStatusMessage(new IHasCamerasWithControlsStateMessage
|
||||||
|
{
|
||||||
|
SelectedCamera = e.SelectedCamera
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers the actions for this messenger.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="ArgumentException"></exception>
|
||||||
|
protected override void RegisterActions()
|
||||||
|
{
|
||||||
|
base.RegisterActions();
|
||||||
|
|
||||||
|
AddAction("/fullStatus", (id, context) => SendFullStatus(id));
|
||||||
|
|
||||||
|
AddAction("/cameraListStatus", (id, content) => SendFullStatus(id));
|
||||||
|
|
||||||
|
AddAction("/selectCamera", (id, content) =>
|
||||||
|
{
|
||||||
|
var cameraKey = content?.ToObject<string>();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(cameraKey))
|
||||||
|
{
|
||||||
|
CameraController.SelectCamera(cameraKey);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Content must be a string representing the camera key");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendFullStatus(string clientId)
|
||||||
|
{
|
||||||
|
var state = new IHasCamerasWithControlsStateMessage
|
||||||
|
{
|
||||||
|
CameraList = CameraController.Cameras,
|
||||||
|
SelectedCamera = CameraController.SelectedCamera
|
||||||
|
};
|
||||||
|
|
||||||
|
PostStatusMessage(state, clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// State message for devices that implement the IHasCameras interface.
|
||||||
|
/// </summary>
|
||||||
|
public class IHasCamerasWithControlsStateMessage : DeviceStateMessageBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// List of cameras available in the device.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("cameraList", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public List<IHasCameraControls> CameraList { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The currently selected camera on the device.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("selectedCamera", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public IHasCameraControls SelectedCamera { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -975,6 +975,19 @@ namespace PepperDash.Essentials
|
|||||||
messengerAdded = true;
|
messengerAdded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device is IHasCamerasWithControls cameras2)
|
||||||
|
{
|
||||||
|
this.LogVerbose("Adding IHasCamerasMessenger for {deviceKey}", device.Key
|
||||||
|
);
|
||||||
|
var messenger = new IHasCamerasWithControlMessenger(
|
||||||
|
$"{device.Key}-cameras-{Key}",
|
||||||
|
$"/device/{device.Key}",
|
||||||
|
cameras2
|
||||||
|
);
|
||||||
|
AddDefaultDeviceMessenger(messenger);
|
||||||
|
messengerAdded = true;
|
||||||
|
}
|
||||||
|
|
||||||
this.LogVerbose("Trying to cast to generic device for device: {key}", device.Key);
|
this.LogVerbose("Trying to cast to generic device for device: {key}", device.Key);
|
||||||
|
|
||||||
if (device is EssentialsDevice)
|
if (device is EssentialsDevice)
|
||||||
|
|||||||
Reference in New Issue
Block a user