@@ -72,3 +72,14 @@ func (h *Hub) run() {
}
+
+func (h *Hub) GetClients() []*Client {
+ h.mutex.RLock()
+ defer h.mutex.RUnlock()
+ var clients = make([]*Client, 0)
+ for _, c := range h.clients {
+ clients = append(clients, c)
+ }
+ return clients
+}
@@ -57,6 +57,10 @@ func newApp() *gin.Engine {
app.GET("/websocket/endpoint", func(ctx *gin.Context) { srv.WebsocketHandler(ctx) })
+ app.GET("/websocket/clients", func(ctx *gin.Context) {
+ clients := srv.Hub.GetClients()
+ ctx.JSON(http.StatusOK, gin.H{"clients": clients})
+ })
return app