-
Notifications
You must be signed in to change notification settings - Fork 20
/
event.go
88 lines (75 loc) · 2.01 KB
/
event.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gyre
// EventType defines event type
type EventType int
// Event types
const (
EventEnter EventType = iota + 1
EventJoin
EventLeave
EventExit
EventWhisper
EventShout
)
// Converts EventType to string.
func (e EventType) String() string {
switch e {
case EventEnter:
return "EventEnter"
case EventJoin:
return "EventJoin"
case EventLeave:
return "EventLeave"
case EventExit:
return "EventExit"
case EventWhisper:
return "EventWhisper"
case EventShout:
return "EventShout"
}
return ""
}
// Event represents an event which contains information about the sender and the
// group it belongs.
type Event struct {
eventType EventType // Event type
sender string // Sender UUID as string
name string // Sender public name as string
address string // Sender ipaddress as string, for an ENTER event
headers map[string]string // Headers, for an ENTER event
group string // Group name for a SHOUT event
msg []byte // Message payload for SHOUT or WHISPER
}
// Type returns event type, which is a EventType.
func (e *Event) Type() EventType {
return e.eventType
}
// Sender returns the sending peer's id as a string.
func (e *Event) Sender() string {
return e.sender
}
// Name returns the sending peer's public name as a string.
func (e *Event) Name() string {
return e.name
}
// Addr returns the sending peer's ipaddress as a string.
func (e *Event) Addr() string {
return e.address
}
// Headers returns the event headers, or nil if there are none
func (e *Event) Headers() map[string]string {
return e.headers
}
// Header returns value of a header from the message headers
// obtained by ENTER.
func (e *Event) Header(name string) (value string, ok bool) {
value, ok = e.headers[name]
return
}
// Group returns the group name that a SHOUT event was sent to.
func (e *Event) Group() string {
return e.group
}
// Msg returns the incoming message payload (currently one frame).
func (e *Event) Msg() []byte {
return e.msg
}