cws

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyPacket = WSPacket{}

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 server

func (*Client) Listen

func (c *Client) Listen()

func (*Client) Receive

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

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 WSPacket

type WSPacket struct {
	ID   string `json:"id"`
	Data string `json:"data"`

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

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

Jump to

Keyboard shortcuts

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