Skip to content

Commit 2e55c29

Browse files
committed
add ApiPermissions, add info about required API version
1 parent aad2b03 commit 2e55c29

File tree

6 files changed

+74
-2
lines changed

6 files changed

+74
-2
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Add support for UpDown volume type and new volume commands
33
- Add support for output device configuration
44
- Add support for PlayOrPause command
5+
- Add support for API permissions
56

67
# Changes in v0.2 (released 2025-02-14)
78
- First official release

src/Client/ApiPermissions.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Beefweb.Client;
2+
3+
/// <summary>
4+
/// Specifies which operations are allowed by current configuration.
5+
/// </summary>
6+
public sealed class ApiPermissions
7+
{
8+
/// <summary>
9+
/// True, if changing playlists is allowed.
10+
/// </summary>
11+
public bool ChangePlaylists { get; set; }
12+
13+
/// <summary>
14+
/// True, if changing output device is allowed.
15+
/// </summary>
16+
public bool ChangeOutput { get; set; }
17+
18+
/// <summary>
19+
/// True, if changing client configuration is allowed.
20+
/// </summary>
21+
public bool ChangeClientConfig { get; set; }
22+
}

src/Client/IPlayerClient.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ ValueTask<PlayerState> GetPlayerState(
104104
/// </summary>
105105
/// <param name="cancellationToken">Cancellation token.</param>
106106
/// <returns>Request task.</returns>
107+
/// <remarks>
108+
/// This method is available since Beefweb v0.10
109+
/// </remarks>
107110
ValueTask PlayOrPause(CancellationToken cancellationToken = default);
108111

109112
/// <summary>
@@ -144,20 +147,29 @@ ValueTask<PlayerState> GetPlayerState(
144147
/// <param name="volume">New volume value.</param>
145148
/// <param name="cancellationToken">Cancellation token.</param>
146149
/// <returns>Request task.</returns>
150+
/// <remarks>
151+
/// This method is available since Beefweb v0.10
152+
/// </remarks>
147153
ValueTask SetVolumeRelative(double volume, CancellationToken cancellationToken = default);
148154

149155
/// <summary>
150156
/// Increases volume.
151157
/// </summary>
152158
/// <param name="cancellationToken">Cancellation token.</param>
153159
/// <returns>Request task.</returns>
160+
/// <remarks>
161+
/// This method is available since Beefweb v0.10
162+
/// </remarks>
154163
ValueTask VolumeUp(CancellationToken cancellationToken = default);
155164

156165
/// <summary>
157166
/// Decreases volume.
158167
/// </summary>
159168
/// <param name="cancellationToken">Cancellation token.</param>
160169
/// <returns>Request task.</returns>
170+
/// <remarks>
171+
/// This method is available since Beefweb v0.10
172+
/// </remarks>
161173
ValueTask VolumeDown(CancellationToken cancellationToken = default);
162174

163175
/// <summary>
@@ -404,6 +416,9 @@ ValueTask SortPlaylist(
404416
/// </summary>
405417
/// <param name="cancellationToken">Cancellation token.</param>
406418
/// <returns>Request task.</returns>
419+
/// <remarks>
420+
/// This method is available since Beefweb v0.10
421+
/// </remarks>
407422
ValueTask<OutputsInfo> GetOutputs(CancellationToken cancellationToken = default);
408423

409424
/// <summary>
@@ -413,6 +428,9 @@ ValueTask SortPlaylist(
413428
/// <param name="deviceId">Output device id.</param>
414429
/// <param name="cancellationToken">Cancellation token.</param>
415430
/// <returns>Request task.</returns>
431+
/// <remarks>
432+
/// This method is available since Beefweb v0.10
433+
/// </remarks>
416434
ValueTask SetOutputDevice(string? typeId, string deviceId, CancellationToken cancellationToken = default);
417435

418436
// File browser API

src/Client/PlayerState.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43

54
namespace Beefweb.Client;
65

@@ -48,6 +47,15 @@ public sealed class PlayerState
4847
/// </summary>
4948
public VolumeInfo Volume { get; set; } = null!;
5049

50+
/// <summary>
51+
/// Current permissions.
52+
/// </summary>
53+
/// <remarks>
54+
/// This property is available since Beefweb v0.10
55+
/// For earlier value is null.
56+
/// </remarks>
57+
public ApiPermissions? Permissions { get; set; }
58+
5159
/// <summary>
5260
/// Gets option with specified <paramref name="id"/>.
5361
/// </summary>

src/Client/SetPlayerStateRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public sealed class SetPlayerStateRequest
1717
/// <summary>
1818
/// New relative volume value.
1919
/// </summary>
20+
/// <remarks>
21+
/// This property is available since Beefweb v0.10
22+
/// </remarks>
2023
public double? RelativeVolume { get; set; }
2124

2225
/// <summary>

src/CommandLineTool/Commands/StatusCommand.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class StatusCommand(IClientProvider clientProvider, ITabularWriter writer
2929
[Option(T.Playlist, Description = "Display playlist information")]
3030
public bool Playlist { get; set; }
3131

32+
[Option("-m|--permissions", Description = "Display permissions")]
33+
public bool Permissions { get; set; }
34+
3235
[Option("-r|--version", Description = "Display version information")]
3336
public bool Version { get; set; }
3437

@@ -48,7 +51,7 @@ public override async Task OnExecuteAsync(CancellationToken ct)
4851
var baseIndex = IndicesFrom0 ? 0 : 1;
4952
var properties = new List<string[]>();
5053

51-
if (Playback || All || !(Playlist || Volume || Options || Version))
54+
if (Playback || All || !(Playlist || Volume || Options || Permissions || Version))
5255
{
5356
var isStopped = state.PlaybackState == PlaybackState.Stopped;
5457
var track = isStopped ? "none" : activeItem.Columns[0];
@@ -95,6 +98,23 @@ public override async Task OnExecuteAsync(CancellationToken ct)
9598
["", o.Name.CapitalizeFirstChar(), o.FormatValue(IndicesFrom0)]));
9699
}
97100

101+
if (Permissions || All)
102+
{
103+
AddEmptyLine();
104+
properties.Add(["Permissions:"]);
105+
106+
if (state.Permissions == null)
107+
{
108+
properties.Add(["", "No available"]);
109+
}
110+
else
111+
{
112+
properties.Add(["", "Change playlists", state.Permissions.ChangePlaylists.ToString()]);
113+
properties.Add(["", "Change output device", state.Permissions.ChangeOutput.ToString()]);
114+
properties.Add(["", "Change client configuration", state.Permissions.ChangeClientConfig.ToString()]);
115+
}
116+
}
117+
98118
if (Version || All)
99119
{
100120
AddEmptyLine();

0 commit comments

Comments
 (0)