websocket

package
v0.0.0-...-76503f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(newtID, secret string, endpoint string, opts ...ClientOption) (*Client, error)

NewClient creates a new Newt client

func (*Client) Close

func (c *Client) Close() error

Close closes the WebSocket connection

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes the WebSocket connection

func (*Client) OnConnect

func (c *Client) OnConnect(callback func() error)

func (*Client) RegisterHandler

func (c *Client) RegisterHandler(messageType string, handler MessageHandler)

RegisterHandler registers a handler for a specific message type

func (*Client) SendMessage

func (c *Client) SendMessage(messageType string, data interface{}) error

SendMessage sends a message through the WebSocket connection

type ClientOption

type ClientOption func(*Client)

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets the base URL for the client

type Config

type Config struct {
	NewtID   string `json:"newtId"`
	Secret   string `json:"secret"`
	Token    string `json:"token"`
	Endpoint string `json:"endpoint"`
}

type MessageHandler

type MessageHandler func(message WSMessage)

type TokenResponse

type TokenResponse struct {
	Data struct {
		Token string `json:"token"`
	} `json:"data"`
	Success bool   `json:"success"`
	Message string `json:"message"`
}

type WSMessage

type WSMessage struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL