Skip to content

Commit

Permalink
feat: announce new clients
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Nov 1, 2023
1 parent 91e7ab4 commit 04a77d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/cy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ func (c *Cy) pollClient(ctx context.Context, client *Client) {

c.sendQueuedToasts()

c.broadcastToast(client, toasts.Toast{
Message: "a client joined the server",
})

for {
select {
case <-conn.Ctx().Done():
Expand Down
13 changes: 13 additions & 0 deletions pkg/cy/toasts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ func (c *Cy) sendQueuedToasts() {
}
}

// Sends a toast to every client but the provided one.
func (c *Cy) broadcastToast(except *Client, toast toasts.Toast) {
c.RLock()
defer c.RUnlock()
for _, client := range c.clients {
if client == except {
continue
}
client.toast.Send(toast)
}
}

// Sends a toast to all clients.
func (c *Client) sendToast(toast toasts.Toast) {
c.toaster.Send(toast)
}
Expand Down

0 comments on commit 04a77d8

Please sign in to comment.