Skip to content

Commit

Permalink
Add node disconnected event and payloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Jul 25, 2024
1 parent 08a2571 commit 040af86
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions wavelink/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"PlayerUpdateEventPayload",
"StatsEventPayload",
"NodeReadyEventPayload",
"NodeDisconnectedEventPayload",
"StatsEventMemory",
"StatsEventCPU",
"StatsEventFrames",
Expand Down Expand Up @@ -87,6 +88,19 @@ def __init__(self, node: Node, resumed: bool, session_id: str) -> None:
self.session_id = session_id


class NodeDisconnectedEventPayload:
"""Payload received in the :func:`on_wavelink_node_disconnected` event.
Attributes
----------
node: :class:`~wavelink.Node`
The node that has disconnected.
"""

def __init__(self, node: Node) -> None:
self.node = node


class TrackStartEventPayload:
"""Payload received in the :func:`on_wavelink_track_start` event.
Expand Down
9 changes: 9 additions & 0 deletions wavelink/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ async def _update_node(self) -> None:
self.node._spotify_enabled = True

async def connect(self) -> None:
if self.node._status is NodeStatus.CONNECTED:
# Node was previously connected...
# We can dispatch an event to say the node was disconnected...
payload: NodeDisconnectedEventPayload = NodeDisconnectedEventPayload(node=self.node)
self.dispatch("node_disconnected", payload)

self.node._status = NodeStatus.CONNECTING

if self.keep_alive_task:
Expand Down Expand Up @@ -283,4 +289,7 @@ async def cleanup(self) -> None:

self.node._websocket = None

payload: NodeDisconnectedEventPayload = NodeDisconnectedEventPayload(node=self.node)
self.dispatch("node_disconnected", payload)

logger.debug("Successfully cleaned up the websocket for %r", self.node)

0 comments on commit 040af86

Please sign in to comment.