nailed it
This commit is contained in:
@@ -34,6 +34,7 @@ const (
|
||||
type GraphQLWSClient struct {
|
||||
roomURL string
|
||||
roomID string
|
||||
token string // JWT token (can be empty for anonymous)
|
||||
log *logrus.Entry
|
||||
conn *websocket.Conn
|
||||
messageCallback func(*NewMessagePayload)
|
||||
@@ -50,10 +51,11 @@ type WSMessage struct {
|
||||
}
|
||||
|
||||
// NewGraphQLWSClient creates a new native WebSocket client
|
||||
func NewGraphQLWSClient(roomURL, roomID string, log *logrus.Entry) *GraphQLWSClient {
|
||||
func NewGraphQLWSClient(roomURL, roomID, token string, log *logrus.Entry) *GraphQLWSClient {
|
||||
return &GraphQLWSClient{
|
||||
roomURL: roomURL,
|
||||
roomID: roomID,
|
||||
token: token,
|
||||
log: log,
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
@@ -63,11 +65,18 @@ func NewGraphQLWSClient(roomURL, roomID string, log *logrus.Entry) *GraphQLWSCli
|
||||
func (c *GraphQLWSClient) Connect() error {
|
||||
c.log.Info("Connecting to Kosmi via native WebSocket")
|
||||
|
||||
// Step 1: Get anonymous token
|
||||
c.log.Debug("Getting anonymous token...")
|
||||
token, err := c.getAnonymousToken()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get token: %w", err)
|
||||
// Step 1: Get token (use provided or get anonymous)
|
||||
var token string
|
||||
if c.token != "" {
|
||||
c.log.Debug("Using provided authentication token")
|
||||
token = c.token
|
||||
} else {
|
||||
c.log.Debug("Getting anonymous token...")
|
||||
var err error
|
||||
token, err = c.getAnonymousToken()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get token: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Connect to WebSocket
|
||||
|
||||
Reference in New Issue
Block a user