cws

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const WSWait = 20 * time.Second

Variables

View Source
var (
	EmptyPacket     = WSPacket{}
	HeartbeatPacket = WSPacket{ID: "heartbeat"}
)

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

func (*Client) Close

func (c *Client) Close()

func (*Client) Heartbeat

func (c *Client) Heartbeat()

Heartbeat maintains connection to coordinator. Blocking.

func (*Client) Listen

func (c *Client) Listen()

func (*Client) Receive

func (c *Client) Receive(id string, f PacketHandler)

Receive receive and response back

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 PacketHandler added in v2.4.0

type PacketHandler func(resp WSPacket) (req WSPacket)

type WSPacket

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

	RoomID      string `json:"room_id"`
	PlayerIndex int    `json:"player_index"`

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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