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