Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Broadcast c.WriteMessage to all listeners matching :id param #61

Open
kazzkiq opened this issue Aug 26, 2021 · 0 comments
Open

Broadcast c.WriteMessage to all listeners matching :id param #61

kazzkiq opened this issue Aug 26, 2021 · 0 comments

Comments

@kazzkiq
Copy link

kazzkiq commented Aug 26, 2021

I have this specific scenario where my application spawns n chat channels, (think of it like chat rooms with many listening and only one speaking) with n users listening each channel.

Only a central authority can broadcast to those channels (e.g. my app), and I plan to fire broadcasting in other parts of my application which are in other files, so I have no more access to the c context variable directly.

Is it possible to actually fire c.WriteMessage from other parts of the project?

Relevant code snippet:

app.Get("/ws/channels/:id", websocket.New(func(c *websocket.Conn) {
  id := c.Params("id")

  // How can I save ReadMessage() and WriteMessage() instances
  // in such a manner that I can call them from any other place in
  // my Fiber application?
  //
  // But also have the intelligence of only broadcasting to those
  // who matches the same id param of my broadcast? 
  readMessageInstance := c.ReadMessage
  writeMessageInstance := c.WriteMessage

}))
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant