github.com/philippseith/signalr@v0.6.3/hubcontext.go (about)

     1  package signalr
     2  
     3  import (
     4  	"context"
     5  	"sync"
     6  )
     7  
     8  // HubContext is a context abstraction for a hub
     9  // Clients gets a HubClients that can be used to invoke methods on clients connected to the hub
    10  // Groups gets a GroupManager that can be used to add and remove connections to named groups
    11  // Items holds key/value pairs scoped to the hubs connection
    12  // ConnectionID gets the ID of the current connection
    13  // Abort aborts the current connection
    14  // Logger returns the logger used in this server
    15  type HubContext interface {
    16  	Clients() HubClients
    17  	Groups() GroupManager
    18  	Items() *sync.Map
    19  	ConnectionID() string
    20  	Context() context.Context
    21  	Abort()
    22  	Logger() (info StructuredLogger, dbg StructuredLogger)
    23  }
    24  
    25  type connectionHubContext struct {
    26  	abort      context.CancelFunc
    27  	connection hubConnection
    28  	clients    HubClients
    29  	groups     GroupManager
    30  	info       StructuredLogger
    31  	dbg        StructuredLogger
    32  }
    33  
    34  func (c *connectionHubContext) Clients() HubClients {
    35  	return c.clients
    36  }
    37  
    38  func (c *connectionHubContext) Groups() GroupManager {
    39  	return c.groups
    40  }
    41  
    42  func (c *connectionHubContext) Items() *sync.Map {
    43  	return c.connection.Items()
    44  }
    45  
    46  func (c *connectionHubContext) ConnectionID() string {
    47  	return c.connection.ConnectionID()
    48  }
    49  
    50  func (c *connectionHubContext) Context() context.Context {
    51  	return c.connection.Context()
    52  }
    53  
    54  func (c *connectionHubContext) Abort() {
    55  	c.abort()
    56  }
    57  
    58  func (c *connectionHubContext) Logger() (info StructuredLogger, dbg StructuredLogger) {
    59  	return c.info, c.dbg
    60  }