Merge pull request #1240 from PepperDash/codec-messenger-issues

Codec messenger serialization issues
This commit is contained in:
Andrew Welker
2025-04-02 12:05:17 -05:00
committed by GitHub
9 changed files with 339 additions and 211 deletions

View File

@@ -1,4 +1,5 @@
using System; using Newtonsoft.Json;
using System;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
@@ -11,6 +12,7 @@ namespace PepperDash.Essentials.Core
/// <summary> /// <summary>
/// The IRoutingInputs object this lives on /// The IRoutingInputs object this lives on
/// </summary> /// </summary>
[JsonIgnore]
public IRoutingInputs ParentDevice { get; private set; } public IRoutingInputs ParentDevice { get; private set; }
/// <summary> /// <summary>

View File

@@ -1,4 +1,5 @@
using System; using Newtonsoft.Json;
using System;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
@@ -8,6 +9,8 @@ namespace PepperDash.Essentials.Core
/// <summary> /// <summary>
/// The IRoutingOutputs object this port lives on /// The IRoutingOutputs object this port lives on
/// </summary> /// </summary>
///
[JsonIgnore]
public IRoutingOutputs ParentDevice { get; private set; } public IRoutingOutputs ParentDevice { get; private set; }
public InUseTracking InUseTracker { get; private set; } public InUseTracking InUseTracker { get; private set; }

View File

@@ -2,9 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using PepperDash.Core;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>

View File

@@ -37,6 +37,7 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
#region IRoutingOutputs Members #region IRoutingOutputs Members
[JsonIgnore]
public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; protected set; } public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; protected set; }
#endregion #endregion

View File

@@ -43,7 +43,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
protected override void RegisterActions() protected override void RegisterActions()
{ {
AddAction("/presets/fullStatus", (id, content) => AddAction("/fullStatus", (id, content) =>
{ {
this.LogInformation("getting full status for client {id}", id); this.LogInformation("getting full status for client {id}", id);
try try
@@ -56,7 +56,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
} }
}); });
AddAction("/presets/recall", (id, content) => AddAction("/recall", (id, content) =>
{ {
var p = content.ToObject<PresetChannelMessage>(); var p = content.ToObject<PresetChannelMessage>();
@@ -70,7 +70,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
RecallPreset(dev, p.Preset.Channel); RecallPreset(dev, p.Preset.Channel);
}); });
AddAction("/presets/save", (id, content) => AddAction("/save", (id, content) =>
{ {
var presets = content.ToObject<List<PresetChannel>>(); var presets = content.ToObject<List<PresetChannel>>();

View File

@@ -2,7 +2,10 @@
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.Core.DeviceTypeInterfaces; using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using System;
using System.Collections.Generic;
namespace PepperDash.Essentials.AppServer.Messengers namespace PepperDash.Essentials.AppServer.Messengers
{ {
@@ -56,10 +59,32 @@ namespace PepperDash.Essentials.AppServer.Messengers
private void SendFullStatus() private void SendFullStatus()
{ {
var stateObject = new JObject(); try
stateObject[_propName] = JToken.FromObject(itemDevice, serializer); {
this.LogInformation("Sending full status");
var stateObject = new ISelectableItemsStateMessage<TKey>
{
Items = itemDevice.Items,
CurrentItem = itemDevice.CurrentItem
};
PostStatusMessage(stateObject); PostStatusMessage(stateObject);
} }
catch (Exception e)
{
this.LogError("Error sending full status: {0}", e.Message);
}
}
}
public class ISelectableItemsStateMessage<TKey> : DeviceStateMessageBase
{
[JsonProperty("items")]
public Dictionary<TKey, ISelectableItem> Items { get; set; }
[JsonProperty("currentItem")]
public TKey CurrentItem { get; set; }
} }
} }

View File

@@ -1,6 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.DeviceTypeInterfaces; using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using System; using System;
@@ -152,11 +153,13 @@ namespace PepperDash.Essentials.AppServer.Messengers
message.Name = _device.Name; message.Name = _device.Name;
PostStatusMessage(JToken.FromObject(message), MessagePath, clientId); var token = JToken.FromObject(message);
PostStatusMessage(token, MessagePath, clientId);
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogMessage(ex, "Exception posting status message", this); this.LogError(ex, "Exception posting status message for {messagePath} to {clientId}", MessagePath, clientId ?? "all clients");
} }
} }
@@ -173,11 +176,13 @@ namespace PepperDash.Essentials.AppServer.Messengers
deviceState.MessageBasePath = MessagePath; deviceState.MessageBasePath = MessagePath;
PostStatusMessage(JToken.FromObject(deviceState), type, clientId); var token = JToken.FromObject(deviceState);
PostStatusMessage(token, type, clientId);
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogMessage(ex, "Exception posting status message", this); this.LogError(ex, "Exception posting status message for {type} to {clientId}", type, clientId ?? "all clients");
} }
} }

View File

@@ -12,7 +12,6 @@ using PepperDash.Essentials.Devices.Common.VideoCodec.Interfaces;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using static PepperDash.Essentials.AppServer.Messengers.VideoCodecBaseStateMessage.CameraStatus;
namespace PepperDash.Essentials.AppServer.Messengers namespace PepperDash.Essentials.AppServer.Messengers
{ {
@@ -77,6 +76,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void CallHistory_RecentCallsListHasChanged(object sender, EventArgs e) private void CallHistory_RecentCallsListHasChanged(object sender, EventArgs e)
{
try
{ {
var state = new VideoCodecBaseStateMessage(); var state = new VideoCodecBaseStateMessage();
@@ -90,6 +91,11 @@ namespace PepperDash.Essentials.AppServer.Messengers
PostStatusMessage(state); PostStatusMessage(state);
} }
} }
catch (Exception ex)
{
this.LogError(ex, "Error posting call history");
}
}
/// <summary> /// <summary>
/// ///
@@ -106,6 +112,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// Posts the current directory /// Posts the current directory
/// </summary> /// </summary>
protected void SendDirectory(CodecDirectory directory) protected void SendDirectory(CodecDirectory directory)
{
try
{ {
var state = new VideoCodecBaseStateMessage(); var state = new VideoCodecBaseStateMessage();
@@ -116,19 +124,13 @@ namespace PepperDash.Essentials.AppServer.Messengers
//state.CurrentDirectory = PrefixDirectoryFolderItems(directory); //state.CurrentDirectory = PrefixDirectoryFolderItems(directory);
state.CurrentDirectory = directory; state.CurrentDirectory = directory;
CrestronInvoke.BeginInvoke((o) => PostStatusMessage(state)); CrestronInvoke.BeginInvoke((o) => PostStatusMessage(state));
/* var directoryMessage = new
{
currentDirectory = new
{
directoryResults = prefixedDirectoryResults,
isRootDirectory = isRoot
} }
}; }
catch (Exception ex)
//Spool up a thread in case this is a large quantity of data {
CrestronInvoke.BeginInvoke((o) => PostStatusMessage(directoryMessage)); */ this.LogError(ex, "Error sending directory");
} }
} }
@@ -138,6 +140,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Codec_IsReadyChange(object sender, EventArgs e) private void Codec_IsReadyChange(object sender, EventArgs e)
{
try
{ {
var state = new VideoCodecBaseStateMessage var state = new VideoCodecBaseStateMessage
{ {
@@ -147,6 +151,10 @@ namespace PepperDash.Essentials.AppServer.Messengers
PostStatusMessage(state); PostStatusMessage(state);
SendFullStatus(); SendFullStatus();
} catch (Exception ex)
{
this.LogError(ex, "Error sending codec ready status");
}
} }
/// <summary> /// <summary>
@@ -352,6 +360,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
} }
private void SharingSourceFeedback_OutputChange(object sender, FeedbackEventArgs e) private void SharingSourceFeedback_OutputChange(object sender, FeedbackEventArgs e)
{
try
{ {
var state = new VideoCodecBaseStateMessage var state = new VideoCodecBaseStateMessage
{ {
@@ -359,9 +369,15 @@ namespace PepperDash.Essentials.AppServer.Messengers
}; };
PostStatusMessage(state); PostStatusMessage(state);
} catch (Exception ex)
{
this.LogError(ex, "Error posting sharing source");
}
} }
private void SharingContentIsOnFeedback_OutputChange(object sender, FeedbackEventArgs e) private void SharingContentIsOnFeedback_OutputChange(object sender, FeedbackEventArgs e)
{
try
{ {
var state = new VideoCodecBaseStateMessage var state = new VideoCodecBaseStateMessage
{ {
@@ -369,9 +385,15 @@ namespace PepperDash.Essentials.AppServer.Messengers
}; };
PostStatusMessage(state); PostStatusMessage(state);
} catch (Exception ex)
{
this.LogError(ex, "Error posting sharing content");
}
} }
private void PhonebookSyncState_InitialSyncCompleted(object sender, EventArgs e) private void PhonebookSyncState_InitialSyncCompleted(object sender, EventArgs e)
{
try
{ {
var state = new VideoCodecBaseStateMessage var state = new VideoCodecBaseStateMessage
{ {
@@ -380,6 +402,11 @@ namespace PepperDash.Essentials.AppServer.Messengers
PostStatusMessage(state); PostStatusMessage(state);
} }
catch (Exception ex)
{
this.LogError(ex, "Error posting phonebook sync state");
}
}
private void CameraIsOffFeedback_OutputChange(object sender, FeedbackEventArgs e) private void CameraIsOffFeedback_OutputChange(object sender, FeedbackEventArgs e)
{ {
@@ -403,9 +430,15 @@ namespace PepperDash.Essentials.AppServer.Messengers
private void CameraCodec_CameraSelected(object sender, CameraSelectedEventArgs e) private void CameraCodec_CameraSelected(object sender, CameraSelectedEventArgs e)
{
try
{ {
MapCameraActions(); MapCameraActions();
PostSelectedCamera(); PostSelectedCamera();
} catch(Exception ex)
{
this.LogError(ex, "Exception handling camera selected event");
}
} }
/// <summary> /// <summary>
@@ -563,6 +596,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
} }
private void PostCallHistory() private void PostCallHistory()
{
try
{ {
var codec = (Codec as IHasCallHistory); var codec = (Codec as IHasCallHistory);
@@ -580,6 +615,11 @@ namespace PepperDash.Essentials.AppServer.Messengers
} }
} }
} }
catch (Exception ex)
{
this.LogError(ex, "Error posting call history");
}
}
/// <summary> /// <summary>
/// Helper to grab a call with string ID /// Helper to grab a call with string ID
@@ -608,6 +648,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// ///
/// </summary> /// </summary>
private void GetDirectoryRoot() private void GetDirectoryRoot()
{
try
{ {
if (!(Codec is IHasDirectory dirCodec)) if (!(Codec is IHasDirectory dirCodec))
{ {
@@ -627,6 +669,11 @@ namespace PepperDash.Essentials.AppServer.Messengers
dirCodec.SetCurrentDirectoryToRoot(); dirCodec.SetCurrentDirectoryToRoot();
} }
catch (Exception ex)
{
this.LogError(ex, "Error getting directory root");
}
}
/// <summary> /// <summary>
/// Requests the parent folder contents /// Requests the parent folder contents
@@ -653,6 +700,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// ///
/// </summary> /// </summary>
private void SendIsReady() private void SendIsReady()
{
try
{ {
var status = new VideoCodecBaseStateMessage(); var status = new VideoCodecBaseStateMessage();
@@ -663,19 +712,25 @@ namespace PepperDash.Essentials.AppServer.Messengers
PostStatusMessage(status); PostStatusMessage(status);
} }
catch (Exception ex)
{
this.LogError(ex, "Error sending codec ready status");
}
}
/// <summary> /// <summary>
/// Helper method to build call status for vtc /// Helper method to build call status for vtc
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
protected VideoCodecBaseStateMessage GetStatus() protected VideoCodecBaseStateMessage GetStatus()
{
try
{ {
var status = new VideoCodecBaseStateMessage(); var status = new VideoCodecBaseStateMessage();
if (Codec is IHasCodecCameras camerasCodec) if (Codec is IHasCodecCameras camerasCodec)
{ {
status.Cameras = new VideoCodecBaseStateMessage.CameraStatus status.Cameras = new CameraStatus
{ {
CameraManualIsSupported = true, CameraManualIsSupported = true,
CameraAutoIsSupported = Codec.SupportsCameraAutoMode, CameraAutoIsSupported = Codec.SupportsCameraAutoMode,
@@ -716,10 +771,14 @@ namespace PepperDash.Essentials.AppServer.Messengers
status.MeetingInfo = meetingInfoCodec.MeetingInfo; status.MeetingInfo = meetingInfoCodec.MeetingInfo;
} }
//Debug.Console(2, this, "VideoCodecBaseStatus:\n{0}", JsonConvert.SerializeObject(status));
return status; return status;
} }
catch (Exception ex)
{
this.LogError(ex, "Error getting codec status");
return null;
}
}
protected virtual void SendFullStatus() protected virtual void SendFullStatus()
{ {
@@ -732,15 +791,24 @@ namespace PepperDash.Essentials.AppServer.Messengers
} }
private void PostReceivingContent(bool receivingContent) private void PostReceivingContent(bool receivingContent)
{
try
{ {
var state = new VideoCodecBaseStateMessage var state = new VideoCodecBaseStateMessage
{ {
ReceivingContent = receivingContent ReceivingContent = receivingContent
}; };
PostStatusMessage(state); PostStatusMessage(state);
} catch(Exception ex)
{
this.LogError(ex, "Error posting receiving content");
}
} }
private void PostCameraSelfView() private void PostCameraSelfView()
{
try
{ {
var status = new VideoCodecBaseStateMessage var status = new VideoCodecBaseStateMessage
{ {
@@ -750,11 +818,18 @@ namespace PepperDash.Essentials.AppServer.Messengers
PostStatusMessage(status); PostStatusMessage(status);
} }
catch (Exception ex)
{
this.LogError(ex, "Error posting camera self view");
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
private void PostCameraMode() private void PostCameraMode()
{
try
{ {
var status = new VideoCodecBaseStateMessage var status = new VideoCodecBaseStateMessage
{ {
@@ -763,20 +838,35 @@ namespace PepperDash.Essentials.AppServer.Messengers
PostStatusMessage(status); PostStatusMessage(status);
} }
catch (Exception ex)
{
this.LogError(ex, "Error posting camera mode");
}
}
private void PostSelectedCamera() private void PostSelectedCamera()
{
try
{ {
var camerasCodec = Codec as IHasCodecCameras; var camerasCodec = Codec as IHasCodecCameras;
var status = new VideoCodecBaseStateMessage var status = new VideoCodecBaseStateMessage
{ {
Cameras = new VideoCodecBaseStateMessage.CameraStatus() { SelectedCamera = GetSelectedCamera(camerasCodec) }, Cameras = new CameraStatus() { SelectedCamera = GetSelectedCamera(camerasCodec) },
Presets = GetCurrentPresets() Presets = GetCurrentPresets()
}; };
PostStatusMessage(status); PostStatusMessage(status);
} }
catch (Exception e)
{
this.LogError(e, "Error posting selected camera");
}
}
private void PostCameraPresets() private void PostCameraPresets()
{
try
{ {
var status = new VideoCodecBaseStateMessage var status = new VideoCodecBaseStateMessage
{ {
@@ -785,6 +875,11 @@ namespace PepperDash.Essentials.AppServer.Messengers
PostStatusMessage(status); PostStatusMessage(status);
} }
catch (Exception e)
{
this.LogError(e, "Error posting camera presets");
}
}
private Camera GetSelectedCamera(IHasCodecCameras camerasCodec) private Camera GetSelectedCamera(IHasCodecCameras camerasCodec)
{ {
@@ -796,7 +891,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
{ {
camera.Name = camerasCodec.SelectedCamera.Name; camera.Name = camerasCodec.SelectedCamera.Name;
camera.Capabilities = new Camera.CameraCapabilities() camera.Capabilities = new CameraCapabilities()
{ {
CanPan = camerasCodec.SelectedCamera.CanPan, CanPan = camerasCodec.SelectedCamera.CanPan,
CanTilt = camerasCodec.SelectedCamera.CanTilt, CanTilt = camerasCodec.SelectedCamera.CanTilt,
@@ -922,6 +1017,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
[JsonProperty("supportsAdHocMeeting", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("supportsAdHocMeeting", NullValueHandling = NullValueHandling.Ignore)]
public bool? SupportsAdHocMeeting { get; set; } public bool? SupportsAdHocMeeting { get; set; }
}
public class CameraStatus public class CameraStatus
{ {
@@ -942,6 +1038,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
[JsonProperty("selectedCamera", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("selectedCamera", NullValueHandling = NullValueHandling.Ignore)]
public Camera SelectedCamera { get; set; } public Camera SelectedCamera { get; set; }
}
public class Camera public class Camera
{ {
@@ -956,6 +1053,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
[JsonProperty("capabilities", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("capabilities", NullValueHandling = NullValueHandling.Ignore)]
public CameraCapabilities Capabilities { get; set; } public CameraCapabilities Capabilities { get; set; }
}
public class CameraCapabilities public class CameraCapabilities
{ {
@@ -972,11 +1070,6 @@ namespace PepperDash.Essentials.AppServer.Messengers
public bool? CanFocus { get; set; } public bool? CanFocus { get; set; }
} }
}
}
}
public class VideoCodecBaseEventMessage : DeviceEventMessageBase public class VideoCodecBaseEventMessage : DeviceEventMessageBase
{ {

View File

@@ -1133,8 +1133,12 @@ namespace PepperDash.Essentials
_messengers.Add(messenger.Key, messenger); _messengers.Add(messenger.Key, messenger);
if (_initialized)
{
this.LogDebug("Registering messenger {messengerKey} AFTER initialization", messenger.Key);
messenger.RegisterWithAppServer(this); messenger.RegisterWithAppServer(this);
} }
}
private void AddDefaultDeviceMessenger(IMobileControlMessenger messenger) private void AddDefaultDeviceMessenger(IMobileControlMessenger messenger)
{ {
@@ -2230,17 +2234,15 @@ Mobile Control Direct Server Infromation:
// /room/roomAB // /room/roomAB
// Can't do direct comparison because it will match /room/roomA with /room/roomA/xxx instead of /room/roomAB/xxx // Can't do direct comparison because it will match /room/roomA with /room/roomA/xxx instead of /room/roomAB/xxx
var handlersKv = _actionDictionary.FirstOrDefault(kv => message.Type.StartsWith(kv.Key + "/")); // adds trailing slash to ensure above case is handled var handlers = _actionDictionary.Where(kv => message.Type.StartsWith(kv.Key + "/")).SelectMany(kv => kv.Value).ToList(); // adds trailing slash to ensure above case is handled
if (handlersKv.Key == null) if (handlers.Count == 0)
{ {
this.LogInformation("-- Warning: Incoming message has no registered handler {type}", message.Type); this.LogInformation("-- Warning: Incoming message has no registered handler {type}", message.Type);
break; break;
} }
var handlers = handlersKv.Value;
foreach (var handler in handlers) foreach (var handler in handlers)
{ {
Task.Run( Task.Run(