Use GeneralCommandType enum in GeneralCommand name

pull/4192/head
Niels van Velzen 4 years ago
parent 7da03d67a7
commit 3459655bb4

@ -135,6 +135,7 @@
- [YouKnowBlom](https://github.com/YouKnowBlom) - [YouKnowBlom](https://github.com/YouKnowBlom)
- [KristupasSavickas](https://github.com/KristupasSavickas) - [KristupasSavickas](https://github.com/KristupasSavickas)
- [Pusta](https://github.com/pusta) - [Pusta](https://github.com/pusta)
- [nielsvanvelzen](https://github.com/nielsvanvelzen)
# Emby Contributors # Emby Contributors

@ -669,62 +669,57 @@ namespace Emby.Dlna.PlayTo
private Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken) private Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
{ {
if (Enum.TryParse(command.Name, true, out GeneralCommandType commandType)) switch (command.Name)
{ {
switch (commandType) case GeneralCommandType.VolumeDown:
{ return _device.VolumeDown(cancellationToken);
case GeneralCommandType.VolumeDown: case GeneralCommandType.VolumeUp:
return _device.VolumeDown(cancellationToken); return _device.VolumeUp(cancellationToken);
case GeneralCommandType.VolumeUp: case GeneralCommandType.Mute:
return _device.VolumeUp(cancellationToken); return _device.Mute(cancellationToken);
case GeneralCommandType.Mute: case GeneralCommandType.Unmute:
return _device.Mute(cancellationToken); return _device.Unmute(cancellationToken);
case GeneralCommandType.Unmute: case GeneralCommandType.ToggleMute:
return _device.Unmute(cancellationToken); return _device.ToggleMute(cancellationToken);
case GeneralCommandType.ToggleMute: case GeneralCommandType.SetAudioStreamIndex:
return _device.ToggleMute(cancellationToken); if (command.Arguments.TryGetValue("Index", out string index))
case GeneralCommandType.SetAudioStreamIndex: {
if (command.Arguments.TryGetValue("Index", out string index)) if (int.TryParse(index, NumberStyles.Integer, _usCulture, out var val))
{ {
if (int.TryParse(index, NumberStyles.Integer, _usCulture, out var val)) return SetAudioStreamIndex(val);
{
return SetAudioStreamIndex(val);
}
throw new ArgumentException("Unsupported SetAudioStreamIndex value supplied.");
} }
throw new ArgumentException("SetAudioStreamIndex argument cannot be null"); throw new ArgumentException("Unsupported SetAudioStreamIndex value supplied.");
case GeneralCommandType.SetSubtitleStreamIndex: }
if (command.Arguments.TryGetValue("Index", out index))
{
if (int.TryParse(index, NumberStyles.Integer, _usCulture, out var val))
{
return SetSubtitleStreamIndex(val);
}
throw new ArgumentException("Unsupported SetSubtitleStreamIndex value supplied."); throw new ArgumentException("SetAudioStreamIndex argument cannot be null");
case GeneralCommandType.SetSubtitleStreamIndex:
if (command.Arguments.TryGetValue("Index", out index))
{
if (int.TryParse(index, NumberStyles.Integer, _usCulture, out var val))
{
return SetSubtitleStreamIndex(val);
} }
throw new ArgumentException("SetSubtitleStreamIndex argument cannot be null"); throw new ArgumentException("Unsupported SetSubtitleStreamIndex value supplied.");
case GeneralCommandType.SetVolume: }
if (command.Arguments.TryGetValue("Volume", out string vol))
{
if (int.TryParse(vol, NumberStyles.Integer, _usCulture, out var volume))
{
return _device.SetVolume(volume, cancellationToken);
}
throw new ArgumentException("Unsupported volume value supplied."); throw new ArgumentException("SetSubtitleStreamIndex argument cannot be null");
case GeneralCommandType.SetVolume:
if (command.Arguments.TryGetValue("Volume", out string vol))
{
if (int.TryParse(vol, NumberStyles.Integer, _usCulture, out var volume))
{
return _device.SetVolume(volume, cancellationToken);
} }
throw new ArgumentException("Volume argument cannot be null"); throw new ArgumentException("Unsupported volume value supplied.");
default: }
return Task.CompletedTask;
}
}
return Task.CompletedTask; throw new ArgumentException("Volume argument cannot be null");
default:
return Task.CompletedTask;
}
} }
private async Task SetAudioStreamIndex(int? newIndex) private async Task SetAudioStreamIndex(int? newIndex)

@ -1037,7 +1037,7 @@ namespace Emby.Server.Implementations.Session
var generalCommand = new GeneralCommand var generalCommand = new GeneralCommand
{ {
Name = GeneralCommandType.DisplayMessage.ToString() Name = GeneralCommandType.DisplayMessage
}; };
generalCommand.Arguments["Header"] = command.Header; generalCommand.Arguments["Header"] = command.Header;
@ -1268,7 +1268,7 @@ namespace Emby.Server.Implementations.Session
{ {
var generalCommand = new GeneralCommand var generalCommand = new GeneralCommand
{ {
Name = GeneralCommandType.DisplayContent.ToString(), Name = GeneralCommandType.DisplayContent,
Arguments = Arguments =
{ {
["ItemId"] = command.ItemId, ["ItemId"] = command.ItemId,

@ -217,16 +217,15 @@ namespace Jellyfin.Api.Controllers
[FromRoute, Required] string sessionId, [FromRoute, Required] string sessionId,
[FromRoute, Required] string command) [FromRoute, Required] string command)
{ {
var name = command; if (!Enum.TryParse(command, true, out GeneralCommandType commandType))
if (Enum.TryParse(name, true, out GeneralCommandType commandType))
{ {
name = commandType.ToString(); return BadRequest();
} }
var currentSession = RequestHelpers.GetSession(_sessionManager, _authContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authContext, Request);
var generalCommand = new GeneralCommand var generalCommand = new GeneralCommand
{ {
Name = name, Name = commandType,
ControllingUserId = currentSession.UserId ControllingUserId = currentSession.UserId
}; };
@ -249,11 +248,16 @@ namespace Jellyfin.Api.Controllers
[FromRoute, Required] string sessionId, [FromRoute, Required] string sessionId,
[FromRoute, Required] string command) [FromRoute, Required] string command)
{ {
if (!Enum.TryParse(command, true, out GeneralCommandType commandType))
{
return BadRequest();
}
var currentSession = RequestHelpers.GetSession(_sessionManager, _authContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authContext, Request);
var generalCommand = new GeneralCommand var generalCommand = new GeneralCommand
{ {
Name = command, Name = commandType,
ControllingUserId = currentSession.UserId ControllingUserId = currentSession.UserId
}; };

@ -8,7 +8,7 @@ namespace MediaBrowser.Model.Session
{ {
public class GeneralCommand public class GeneralCommand
{ {
public string Name { get; set; } public GeneralCommandType Name { get; set; }
public Guid ControllingUserId { get; set; } public Guid ControllingUserId { get; set; }

Loading…
Cancel
Save