mirror of
https://github.com/fosrl/olm.git
synced 2026-02-07 21:46:40 +00:00
Unix: handle encrypted messages
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user