cws

package
v0.0.0-...-9402fd8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyPacket = WSPacket{}

EmptyPacket represents an empty packet

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(conn *websocket.Conn) *Client

NewClient returns a websocket client

func (*Client) Close

func (c *Client) Close()

func (*Client) GetID

func (c *Client) GetID() string

func (*Client) Heartbeat

func (c *Client) Heartbeat()

Heartbeat maintains connection to server

func (*Client) Listen

func (c *Client) Listen()

Listen start a client

func (*Client) Receive

func (c *Client) Receive(id string, f func(request WSPacket) (response WSPacket))

Receive receive and response

func (*Client) Send

func (c *Client) Send(request WSPacket, callback func(response WSPacket))

Send sends a packet and trigger callback when the packet comes back

func (*Client) SyncSend

func (c *Client) SyncSend(request WSPacket) (response WSPacket)

SyncSend sends a packet and wait for callback till the packet comes back

type WSPacket

type WSPacket struct {
	Type string `json:"type"`
	// TODO: Make Data generic: map[string]interface{} for more usecases
	Data string `json:"data"`

	PacketID string `json:"packet_id"`
	// Globally ID of a browser session
	SessionID string `json:"session_id"`
}

WSPacket represents a websocket packet

Jump to

Keyboard shortcuts

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