Skip to content

Commit

Permalink
✨ Listen stream messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MateoGreil committed May 7, 2024
1 parent 97adab2 commit 79092d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/protocols/stream/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package stream

type Response struct {
Command string `json:"response"`
}
19 changes: 19 additions & 0 deletions xapi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xapi

import (
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -56,10 +57,28 @@ func NewClient(userId string, password string, connectionType string) (*client,
}
go c.pingSocket()
go c.pingStream()
go c.listenStream()

return c, nil
}

func (c *client) listenStream() {
for {
_, msg, err := c.streamConn.ReadMessage()
if err != nil {
fmt.Println(err.Error())
}
fmt.Println("Stream message:", msg)
response := stream.Response{}
err = json.Unmarshal(msg, &response)
if err != nil {
fmt.Println(err.Error())
}
switch response.Command {
}
}
}

func (c *client) pingSocket() {
for {
request := socket.Request{
Expand Down

0 comments on commit 79092d3

Please sign in to comment.