using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Devices.Common.Codec;
using PepperDash.Essentials.Devices.Common.VideoCodec;
namespace PepperDash.Essentials.AppServer.Messengers
{
///
/// Provides a messaging bridge for a VideoCodecBase
///
public abstract class MessengerBase : IKeyed
{
public string Key { get; private set; }
///
///
///
public MobileControlSystemController AppServerController { get; private set; }
public string MessagePath { get; private set; }
///
///
///
///
public MessengerBase(string key, string messagePath)
{
Key = key;
if (string.IsNullOrEmpty(messagePath))
throw new ArgumentException("messagePath must not be empty or null");
MessagePath = messagePath;
}
///
/// Registers this messenger with appserver controller
///
///
public void RegisterWithAppServer(MobileControlSystemController appServerController)
{
if (appServerController == null)
throw new ArgumentNullException("appServerController");
AppServerController = appServerController;
CustomRegisterWithAppServer(AppServerController);
}
///
/// Implemented in extending classes. Wire up API calls and feedback here
///
///
abstract protected void CustomRegisterWithAppServer(MobileControlSystemController appServerController);
///
/// Helper for posting status message
///
/// The contents of the content object
protected void PostStatusMessage(object contentObject)
{
if (AppServerController != null)
{
AppServerController.SendMessageToServer(JObject.FromObject(new
{
type = MessagePath,
content = contentObject
}));
}
}
}
}