wip: Start subscriptions

This commit is contained in:
Zoe Roux 2024-03-17 12:15:55 +01:00
parent 96ad9424bb
commit c1ebde75fd
No known key found for this signature in database
2 changed files with 18 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import "errors"
type Client struct {
id string
messages chan []byte
subscriptions []string
}
type Message struct {
@ -18,11 +19,24 @@ type Response struct {
Error string `json:"error,omitempty"`
}
func NewClient() *Client{
return &Client{
messages: make(chan []byte, MAX_MESSAGE_QUEUE),
subscriptions: make([]string, 0),
}
}
func (c *Client) HandleMessage(message Message) (interface{}, error) {
switch message.Action {
case "ping":
return "pong", nil
case "subscribe":
c.subscriptions = append(c.subscriptions, message.Value.(string))
return nil, nil
default:
return nil, errors.New("invalid action")
}
}
func (c *Client) ListenChannels() {
}

View File

@ -23,12 +23,11 @@ func main() {
}
defer c.CloseNow()
client := &Client{
messages: make(chan []byte, MAX_MESSAGE_QUEUE),
}
client := NewClient()
server.RegisterClient(client)
defer server.DeleteClient(client)
go client.ListenChannels()
for {
var message Message
err := wsjson.Read(r.Context(), c, &message)