socket

package
v0.0.0-...-c857007 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package socket contains the logic to communicate with the server for the game via websocket communication

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Socket

type Socket struct {
	Lobby *lobby.Lobby
	Game  *controller.Game
	User  User
	// contains filtered or unexported fields
}

Socket can be used to easily push and pull messages from the server.

func (*Socket) Close

func (s *Socket) Close()

Close releases the websocket

func (*Socket) Connect

func (s *Socket) Connect(event js.Value) error

Connect establishes the websocket connection if it has not yet been established.

func (*Socket) InitDom

func (s *Socket) InitDom(ctx context.Context, wg *sync.WaitGroup)

InitDom regesters socket dom functions.

func (*Socket) Send

func (s *Socket) Send(m game.Message)

Send delivers a message to the server via it's websocket, panicing if the WebSocket is not open.

type User

type User interface {
	// JWT gets the user's Java Web Token.
	JWT() string
	// Username gets the user's username.
	Username() string
	// Logout releases the use credentials from the browser.
	Logout()
}

User is the state of the current user.

Jump to

Keyboard shortcuts

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