forked from alexandrevicenzi/go-sse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
34 lines (29 loc) · 787 Bytes
/
client.go
File metadata and controls
34 lines (29 loc) · 787 Bytes
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
package sse
// Client represents a web browser connection.
type Client struct {
lastEventID,
channel string
send chan *Message
}
func newClient(lastEventID, channel string) *Client {
return &Client{
lastEventID,
channel,
// use buffered channel so client could still receive message event though it is busy,
// this is to minimize message loss in client
make(chan *Message, 1024),
}
}
// SendMessage sends a message to client.
func (c *Client) SendMessage(message *Message) {
c.lastEventID = message.id
c.send <- message
}
// Channel returns the channel where this client is subscribe to.
func (c *Client) Channel() string {
return c.channel
}
// LastEventID returns the ID of the last message sent.
func (c *Client) LastEventID() string {
return c.lastEventID
}