Documentation ¶
Overview ¶
Package wsbridge implements Twisms via a Websocket Protobuf RPC bridge. This is used for proxying and testing.
Index ¶
- func SendMessage(ctx context.Context, conn *websocket.Conn, msg *wsbridgeproto.Message) error
- type ClientService
- func (s *ClientService) SendMessage(ctx context.Context, msg *twismsproto.Message) error
- func (s *ClientService) SendingNumber() (string, float64)
- func (s *ClientService) Start(ctx context.Context, opts ClientStartOpts) error
- func (s *ClientService) SubscribeMessages(ch chan<- *twismsproto.Message, filters *twismsproto.MessageFilters)
- func (s *ClientService) UnsubscribeMessages(ch chan<- *twismsproto.Message)
- type ClientServiceConfig
- type ClientStartOpts
- type ServerService
- func (s *ServerService) SendMessage(ctx context.Context, msg *twismsproto.Message) error
- func (s *ServerService) SendingNumber() (string, float64)
- func (s *ServerService) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *ServerService) Start(ctx context.Context) error
- func (s *ServerService) SubscribeMessages(ch chan<- *twismsproto.Message, filters *twismsproto.MessageFilters)
- func (s *ServerService) UnsubscribeMessages(ch chan<- *twismsproto.Message)
- type ServerServiceConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SendMessage ¶
SendMessage sends a message to the wsbridge Websocket connection in Protobuf format. It sends the WebsocketPacket.send frame.
Types ¶
type ClientService ¶
type ClientService struct {
// contains filtered or unexported fields
}
ClientService wraps a Websocket connection to a wsbridge service.
func NewClientService ¶
func NewClientService(cfg ClientServiceConfig, logger *slog.Logger) *ClientService
NewClientService creates a new Service using the given Websocket address. Using this function, the Service acts as a Websocket client. The connection is not established until [Start] is called.
func (*ClientService) SendMessage ¶
func (s *ClientService) SendMessage(ctx context.Context, msg *twismsproto.Message) error
SendMessage implements twisms.MessageSender.
func (*ClientService) SendingNumber ¶
func (s *ClientService) SendingNumber() (string, float64)
func (*ClientService) Start ¶
func (s *ClientService) Start(ctx context.Context, opts ClientStartOpts) error
Start starts the service.
func (*ClientService) SubscribeMessages ¶
func (s *ClientService) SubscribeMessages(ch chan<- *twismsproto.Message, filters *twismsproto.MessageFilters)
SubscribeMessages implements twisms.MessageSubscriber.
func (*ClientService) UnsubscribeMessages ¶
func (s *ClientService) UnsubscribeMessages(ch chan<- *twismsproto.Message)
UnsubscribeMessages implements twisms.MessageSubscriber.
type ClientServiceConfig ¶
type ClientServiceConfig struct { // PhoneNumbers is the list of phone numbers managed by this service. PhoneNumbers []string `json:"phone_numbers"` // WSAddress is the Websocket address of the wsbridge server. WSAddress string `json:"ws_address"` // Headers is the headers to send when connecting to the wsbridge server. // By default, this is empty. Headers http.Header `json:"headers"` // AcknowledgementTimeout is the timeout for message acknowledgements. // If 0, then no acknowledgement is required. AcknowledgementTimeout cfgutil.Duration `json:"acknowledgement_timeout"` }
ClientServiceConfig is the configuration for ClientService.
type ClientStartOpts ¶
type ClientStartOpts struct { // LastSeen is the last time the client was seen. // If not zero, the client may receive old messages from the server. LastSeen time.Time }
ClientStartOpts are options for starting the client service. All properties are optional.
type ServerService ¶
type ServerService struct {
// contains filtered or unexported fields
}
ServerService wraps a Websocket HTTP handler for the wsbridge server.
func NewServerService ¶
func NewServerService(cfg ServerServiceConfig, logger *slog.Logger) *ServerService
NewServerService creates a new Service using the given Websocket address.
func (*ServerService) SendMessage ¶
func (s *ServerService) SendMessage(ctx context.Context, msg *twismsproto.Message) error
SendMessage implements twisms.MessageSender.
func (*ServerService) SendingNumber ¶
func (s *ServerService) SendingNumber() (string, float64)
func (*ServerService) ServeHTTP ¶
func (s *ServerService) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
func (*ServerService) Start ¶
func (s *ServerService) Start(ctx context.Context) error
Start implements twid.Starter.
func (*ServerService) SubscribeMessages ¶
func (s *ServerService) SubscribeMessages(ch chan<- *twismsproto.Message, filters *twismsproto.MessageFilters)
SubscribeMessages implements twisms.MessageSubscriber.
func (*ServerService) UnsubscribeMessages ¶
func (s *ServerService) UnsubscribeMessages(ch chan<- *twismsproto.Message)
UnsubscribeMessages implements twisms.MessageSubscriber.
type ServerServiceConfig ¶
type ServerServiceConfig struct { // PhoneNumbers is the list of phone numbers managed by this service. PhoneNumbers []string `json:"phone_numbers"` // MessageQueue is the message queue to use for catchup messages. // If nil, no catchup messages will be sent. MessageQueue *catchupstorage.MessageQueueConfig `json:"message_queue"` // AcknowledgementTimeout is the timeout for message acknowledgements. // If 0, then no acknowledgement is required. AcknowledgementTimeout cfgutil.Duration `json:"acknowledgement_timeout"` }
ServerServiceConfig is the configuration for ClientService.