Bad Response packet status
const Bad = 4
Err Response packet status
const Err = 5
Ok Response packet status
const Ok = 1
Type Mesh network type for WebSocket server
const Type = "WS"
func Command(ver float64, cmd float64, handlerName string, handler func(*State, func(error)))
Command Registers a packet handler as a command
func GetConnectionTTL() int64
GetConnectionTTL returns connection TTL
func GetEndPoint() string
GetEndPoint Returns WS server end point that is actually bound
func HookAllCommands(handlerName string, handler func(*State, func(error)))
HookAllCommands Registers a packet handler as a hook to all commands
func Init()
Init [INTERNAL USE ONLY] Flag the WS server state to be initialized to prevent registration of commands and hooks BEFORE initialization by user package
func IsCommandDuplicate(ver float64, commandID float64) bool
IsCommandDuplicate returns true if ver and commandID are used elsewhere when this function is called
func Offline()
Offline Sets mesh network status to offline
func OnDisconnect(callback func(string, string, string, error), last bool)
OnDisconnect Registers a callback on connection disconnect
func OnHeartbeat(handler func(*State, func(error)))
OnHeartbeat Registers a handler to be executed on heartbeat
func OnNewConnection(callback func(*State))
OnNewConnection Registers a callback on new WS connection w/ a client
func Online()
Online Sets mesh network status to online
func SetAllWriteHook(handler func(float64, float64, *State, interface{}) (map[string]interface{}, error))
SetAllWriteHook [INTERNAL USE ONLY] Registers a handler function to all TCP socket writes: Receives the payload and returns a payload
func SetPublicEndPoint(addr string)
SetPublicEndPoint sets public endpoint to be used by the client to connect
func SetPublicEndPointWithPort(addr string, port string)
SetPublicEndPointWithPort sets public endpoint with a port passed to be used by the client to connect
port string should be the port used by nginx or something similar for proxy
func Setup(confpath string)
Setup [INTERNAL USE ONLY] Loads configuration file into memory - pass an empty string to load nothing
func ShutdownWS(next func(error))
ShutdownWS Stops WebSocket server
State Client state data structure
type State struct { UserID string SID string Conn *websocket.Conn ClientAddr string TTLDuration int64 TTL int64 Connected bool Ver float64 Command float64 Payload map[string]interface{} ClientKey string EncryptionKey []byte EncryptionIV []byte EncryptionMacKey []byte }
func GetStateByAddr(addr string) *State
GetStateByAddr Returns a client state struct by client address
func (state *State) Disconnect()
Disconnect Disconnects the socket connection to the client
func (state *State) Kill(err error)
Kill Forcefully terminates the socket connection to the client
func (state *State) Send(ver float64, cmd float64, payload interface{}) error
Send Sends a packet to the client