Unix: handle encrypted messages

This commit is contained in:
Owen
2025-03-15 21:46:54 -04:00
parent 7e2d7b93a1
commit 3d70ff190f
4 changed files with 128 additions and 9 deletions

View File

@@ -27,7 +27,8 @@ type Client struct {
isConnected bool
reconnectMux sync.RWMutex
onConnect func() error
onConnect func() error
onTokenUpdate func(token string)
}
type ClientOption func(*Client)
@@ -45,6 +46,10 @@ func (c *Client) OnConnect(callback func() error) {
c.onConnect = callback
}
func (c *Client) OnTokenUpdate(callback func(token string)) {
c.onTokenUpdate = callback
}
// NewClient creates a new Olm client
func NewClient(olmID, secret string, endpoint string, opts ...ClientOption) (*Client, error) {
config := &Config{
@@ -266,6 +271,8 @@ func (c *Client) establishConnection() error {
return fmt.Errorf("failed to get token: %w", err)
}
c.onTokenUpdate(token)
// Parse the base URL to determine protocol and hostname
baseURL, err := url.Parse(c.baseURL)
if err != nil {

View File

@@ -9,7 +9,8 @@ type Config struct {
type TokenResponse struct {
Data struct {
Token string `json:"token"`
Token string `json:"token"`
ServerPubKey string `json:"serverPubKey"`
} `json:"data"`
Success bool `json:"success"`
Message string `json:"message"`