Class NyraExtension
- Namespace
- Nyra
- Assembly
- Nyra.dll
The extension that owns the audio nodes of a Discord client.
public sealed class NyraExtension : IAsyncDisposable, IDisposable
- Inheritance
-
NyraExtension
- Implements
- Inherited Members
Constructors
NyraExtension(IDiscordBridge)
Creates an extension bound to a Discord client bridge.
public NyraExtension(IDiscordBridge client)
Parameters
clientIDiscordBridgeThe bridge the nodes attach to.
Properties
Client
The Discord client bridge the nodes attach to.
public IDiscordBridge Client { get; }
Property Value
IsDisposed
Whether the extension was disposed.
public bool IsDisposed { get; }
Property Value
Nodes
Snapshot of the nodes added to this client.
public IReadOnlyList<Node> Nodes { get; }
Property Value
Methods
AddNode(Node)
Adds a node, it connects when ConnectAllNodesAsync(CancellationToken) runs.
public void AddNode(Node node)
Parameters
nodeNodeThe node to add.
ConnectAllNodesAsync(CancellationToken)
Connects every added node, a node that fails to connect is skipped and logged if the client has a logger.
public Task ConnectAllNodesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task
A task that completes when every node settled.
Remarks
Skipped is not stopped, a node whose initial connect failed keeps retrying in the background and connects by itself once its server is reachable again, only DisconnectAsync(CancellationToken) (or removing and disposing the node) stops it.
Dispose()
Disconnects and disposes every node of the extension and the bridge it routes through.
public void Dispose()
Remarks
Blocks on the guild teardown roundtrips of every node at once (each bounded by the HTTP timeout), prefer DisposeAsync() wherever the caller can await.
DisposeAsync()
Disconnects and disposes every node of the extension and the bridge it routes through, asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that completes when every node was disposed.
GetConnection(ulong)
The connection playing in the guild, on whatever node it lives, or null when the guild is not connected.
public GuildConnection? GetConnection(ulong guildId)
Parameters
guildIdulongThe guild to get the connection of.
Returns
- GuildConnection
The guild's connection, null when it is not connected.
GetNode()
The ready node with the fewest playing players, nodes without stats yet rank last.
public Node? GetNode()
Returns
- Node
The best node, null while none is ready.
Remarks
Null while no node is ready.
RemoveNodeAsync(Node, CancellationToken)
Removes a node and disconnects it, guild connections living on it are left untouched.
public Task RemoveNodeAsync(Node node, CancellationToken cancellationToken = default)
Parameters
nodeNodeThe node to remove.
cancellationTokenCancellationTokenA token to cancel the node's teardown.
Returns
- Task
A task that completes when the node was removed.
Remarks
The disconnect unwires the node's Discord events, so the guild connections left on the removed node lose the Discord-side tracking (a kick, a move, a voice server re-target) until the node is connected again, a removal that lands during the dormancy finds no subscriber, and the connection stays registered until then (see DisconnectAsync(CancellationToken) for the same rule on a plain stop).
Events
NodeConnected
Forwarded from every node when its websocket connects, with the node as sender.
public event AsyncEventHandler<NodeConnectedEventArgs>? NodeConnected
Event Type
NodeConnectionStatusUpdated
Forwarded from every node on connection status pushes (NodeLink only), with the node as sender.
public event AsyncEventHandler<NodeConnectionStatusEventArgs>? NodeConnectionStatusUpdated
Event Type
NodeDisconnected
Forwarded from every node when its websocket drops, with the node as sender.
public event AsyncEventHandler<NodeDisconnectedEventArgs>? NodeDisconnected
Event Type
NodeError
Forwarded from every node on internal errors, with the node as sender.
public event AsyncEventHandler<NodeErrorEventArgs>? NodeError
Event Type
NodeReady
Forwarded from every node when it turns ready, with the node as sender.
public event AsyncEventHandler<NodeReadyEventArgs>? NodeReady
Event Type
NodeStatsUpdated
Forwarded from every node on its statistics reports, with the node as sender.
public event AsyncEventHandler<NodeStatsEventArgs>? NodeStatsUpdated
Event Type
NodeWorkerFailed
Forwarded from every node when a cluster worker of it failed, with the node as sender.
public event AsyncEventHandler<WorkerFailedEventArgs>? NodeWorkerFailed