mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-07-02 10:38:16 +00:00
feat: implement IAudioCodecPhonebookMessenger for phonebook messaging functionality
This commit is contained in:
parent
22f5558e39
commit
2dd99da67f
3 changed files with 120 additions and 4 deletions
|
|
@ -1,15 +1,38 @@
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using PepperDash.Essentials.Devices.Common.Codec;
|
using PepperDash.Essentials.Devices.Common.Codec;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Devices.Common.AudioCodec;
|
namespace PepperDash.Essentials.Devices.Common.AudioCodec;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the contract for a device that has a phonebook.
|
||||||
|
/// This is used to provide a common interface for devices that have phonebook functionality
|
||||||
|
/// </summary>
|
||||||
public interface IAudioCodecPhonebook : IHasDialer
|
public interface IAudioCodecPhonebook : IHasDialer
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets a phonebook entry at the specified index. The implementation of this method is up to the device, but it should update the phonebook entry at the specified index with the provided name and number.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="number"></param>
|
||||||
|
void SetPhonebookEntry(int index, string name, string number);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of phonebook entries for the device.
|
/// Gets the list of phonebook entries for the device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
List<CodecPhonebookEntry> PhonebookEntries { get; }
|
List<CodecPhonebookEntry> PhonebookEntries { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines a phonebook entry for the audio codec phonebook.
|
||||||
|
/// This is used to provide a common data structure for phonebook entries across different devices.
|
||||||
|
/// </summary>
|
||||||
|
public class CodecPhonebookEntry
|
||||||
|
{
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("number")]
|
||||||
|
public string Number { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using PepperDash.Core;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
|
using PepperDash.Essentials.Core;
|
||||||
|
using PepperDash.Essentials.Devices.Common.AudioCodec;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.AppServer.Messengers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a messaging bridge for devices implementing <see cref="IAudioCodecPhonebook"/>
|
||||||
|
/// </summary>
|
||||||
|
public class IAudioCodecPhonebookMessenger : MessengerBase
|
||||||
|
{
|
||||||
|
private readonly IAudioCodecPhonebook _phonebook;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="IAudioCodecPhonebookMessenger"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="messagePath"></param>
|
||||||
|
/// <param name="device"></param>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
|
public IAudioCodecPhonebookMessenger(string key, string messagePath, EssentialsDevice device)
|
||||||
|
: base(key, messagePath, device)
|
||||||
|
{
|
||||||
|
_phonebook = device as IAudioCodecPhonebook ?? throw new ArgumentNullException(nameof(device));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void RegisterActions()
|
||||||
|
{
|
||||||
|
base.RegisterActions();
|
||||||
|
|
||||||
|
AddAction("/fullStatus", (id, content) => SendFullStatus(id));
|
||||||
|
|
||||||
|
AddAction("/phonebookStatus", (id, content) => SendFullStatus(id));
|
||||||
|
|
||||||
|
AddAction("/setEntry", (id, content) =>
|
||||||
|
{
|
||||||
|
var entry = content.ToObject<SetPhonebookEntryContent>();
|
||||||
|
_phonebook.SetPhonebookEntry(entry.Index, entry.Name, entry.Number);
|
||||||
|
SendFullStatus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendFullStatus(string id = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var state = new IAudioCodecPhonebookStateMessage
|
||||||
|
{
|
||||||
|
PhonebookEntries = _phonebook.PhonebookEntries
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(() => PostStatusMessage(state, id));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.LogError(ex, "Error sending phonebook full status");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// State message for <see cref="IAudioCodecPhonebook"/>
|
||||||
|
/// </summary>
|
||||||
|
public class IAudioCodecPhonebookStateMessage : DeviceStateMessageBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the list of phonebook entries
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("phonebookEntries", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public List<CodecPhonebookEntry> PhonebookEntries { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Content model for the setEntry action
|
||||||
|
/// </summary>
|
||||||
|
public class SetPhonebookEntryContent
|
||||||
|
{
|
||||||
|
[JsonProperty("index")]
|
||||||
|
public int Index { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("number")]
|
||||||
|
public string Number { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -94,6 +94,5 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("isInCall", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("isInCall", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public bool? IsInCall { get; set; }
|
public bool? IsInCall { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue