nailed it
This commit is contained in:
@@ -31,6 +31,7 @@ type Bkosmi struct {
|
||||
roomID string
|
||||
roomURL string
|
||||
connected bool
|
||||
authDone bool // Signals that authentication is complete (like IRC bridge)
|
||||
msgChannel chan config.Message
|
||||
jackboxClient *jackbox.Client
|
||||
}
|
||||
@@ -63,8 +64,25 @@ func (b *Bkosmi) Connect() error {
|
||||
b.roomID = roomID
|
||||
b.Log.Infof("Extracted room ID: %s", b.roomID)
|
||||
|
||||
// Create GraphQL WebSocket client (pure Go, no Playwright!)
|
||||
b.client = NewGraphQLWSClient(b.roomURL, b.roomID, b.Log)
|
||||
// Check if we need authentication
|
||||
email := b.GetString("Email")
|
||||
password := b.GetString("Password")
|
||||
|
||||
var token string
|
||||
if email != "" && password != "" {
|
||||
b.Log.Info("Authenticating with email/password...")
|
||||
token, err = loginWithChromedp(email, password, b.Log)
|
||||
if err != nil {
|
||||
return fmt.Errorf("authentication failed: %w", err)
|
||||
}
|
||||
b.Log.Info("✅ Authentication successful")
|
||||
} else {
|
||||
b.Log.Info("No credentials provided, using anonymous access")
|
||||
// token will be empty, client will get anonymous token
|
||||
}
|
||||
|
||||
// Create GraphQL WebSocket client with token
|
||||
b.client = NewGraphQLWSClient(b.roomURL, b.roomID, token, b.Log)
|
||||
|
||||
// Register message handler
|
||||
b.client.OnMessage(b.handleIncomingMessage)
|
||||
@@ -75,6 +93,7 @@ func (b *Bkosmi) Connect() error {
|
||||
}
|
||||
|
||||
b.connected = true
|
||||
b.authDone = true // Signal that authentication is complete
|
||||
b.Log.Info("Successfully connected to Kosmi")
|
||||
|
||||
return nil
|
||||
@@ -98,9 +117,18 @@ func (b *Bkosmi) Disconnect() error {
|
||||
|
||||
// JoinChannel joins a Kosmi room (no-op as we connect to a specific room)
|
||||
func (b *Bkosmi) JoinChannel(channel config.ChannelInfo) error {
|
||||
// Wait for authentication to complete before proceeding
|
||||
// This ensures the WebSocket connection is fully established (like IRC bridge)
|
||||
for {
|
||||
if b.authDone {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
// Kosmi doesn't have a concept of joining channels after connection
|
||||
// The room is specified in the configuration and joined on Connect()
|
||||
b.Log.Infof("Channel %s is already connected via room URL", channel.Name)
|
||||
b.Log.Debugf("Channel ready: %s (connected via room URL)", channel.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user