websocket private functions

This commit is contained in:
Chen-I Lim 2021-02-02 13:00:22 -08:00
parent 58c967bf53
commit a56cf03e0c

View file

@ -152,7 +152,7 @@ func (ws *Server) authenticateListener(wsSession *websocketSession, token string
log.Printf("authenticateListener: Authenticated") log.Printf("authenticateListener: Authenticated")
} }
// AddListener adds a listener for a block's change. // addListener adds a listener for a block's change.
func (ws *Server) addListener(wsSession *websocketSession, blockIDs []string) { func (ws *Server) addListener(wsSession *websocketSession, blockIDs []string) {
if !wsSession.isAuthenticated { if !wsSession.isAuthenticated {
log.Printf("addListener: NOT AUTHENTICATED") log.Printf("addListener: NOT AUTHENTICATED")
@ -217,8 +217,8 @@ func (ws *Server) removeListenerFromBlocks(wsSession *websocketSession, blockIDs
ws.mu.Unlock() ws.mu.Unlock()
} }
// GetListeners returns the listeners to a blockID's changes. // getListeners returns the listeners to a blockID's changes.
func (ws *Server) GetListeners(blockID string) []*websocket.Conn { func (ws *Server) getListeners(blockID string) []*websocket.Conn {
ws.mu.Lock() ws.mu.Lock()
listeners := ws.listeners[blockID] listeners := ws.listeners[blockID]
ws.mu.Unlock() ws.mu.Unlock()
@ -243,7 +243,7 @@ func (ws *Server) BroadcastBlockChange(block model.Block) {
blockIDsToNotify := []string{block.ID, block.ParentID} blockIDsToNotify := []string{block.ID, block.ParentID}
for _, blockID := range blockIDsToNotify { for _, blockID := range blockIDsToNotify {
listeners := ws.GetListeners(blockID) listeners := ws.getListeners(blockID)
log.Printf("%d listener(s) for blockID: %s", len(listeners), blockID) log.Printf("%d listener(s) for blockID: %s", len(listeners), blockID)
if listeners != nil { if listeners != nil {