client

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 10 Imported by: 2

README

Go Pomelo Client

a pomelo client for golang updated for use with amoeba

go run .\example\basic\main.go --id="test" --token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzIyNDU1MDIsImlhdCI6MTYzMjI0NDAwMiwiaWQiOiJ0ZXN0IiwibmFtZSI6InRlc3QgcGVyc29uIiwibmJmIjoxNjMyMjQzOTkyfQ.v07XyWCYX1ykMyoU2lbxlcpEzKyXw0sl40gyVqcD4Qc'
// Output --
2021/09/21 13:10:15 attempting to connect to: ws://127.0.0.1:8080/ws?id=test&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzIyNDU1MDIsImlhdCI6MTYzMjI0NDAwMiwiaWQiOiJ0ZXN0IiwibmFtZSI6InRlc3QgcGVyc29uIiwibmJmIjoxNjMyMjQzOTkyfQ.v07XyWCYX1ykMyoU2lbxlcpEzKyXw0sl40gyVqcD4Qc...
2021/09/21 13:10:16 200
2021/09/21 13:10:16 connected to server at: ws://127.0.0.1:8080/ws?id=test&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzIyNDU1MDIsImlhdCI6MTYzMjI0NDAwMiwiaWQiOiJ0ZXN0IiwibmFtZSI6InRlc3QgcGVyc29uIiwibmJmIjoxNjMyMjQzOTkyfQ.v07XyWCYX1ykMyoU2lbxlcpEzKyXw0sl40gyVqcD4Qc
2021/09/21 13:10:17 onMembers {"members":["5b4949004d"]}
2021/09/21 13:10:18 room join: {"code":0,"result":"success","username":"87367791cd"}
exit status 1

Install

go get -u github.com/revzim/go-pomelo-client

Example

see example/basic

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(data []byte)

Callback represents the callback type which will be called when the correspond events is occurred.

type Connector

type Connector struct {

	// events handler
	sync.RWMutex
	// contains filtered or unexported fields
}

Connector is a Pomelo [nano] client

func NewConnector

func NewConnector() *Connector

NewConnector create a new Connector

func (*Connector) Close

func (c *Connector) Close()

Close close the connection, and shutdown the benchmark

func (*Connector) Connected

func (c *Connector) Connected(cb func())

Connected --

func (*Connector) InitHandshakeACK

func (c *Connector) InitHandshakeACK(heartbeatDuration int) error

InitHandshakeACK --

func (*Connector) InitReqHandshake

func (c *Connector) InitReqHandshake(version, hType string, rsa, userData map[string]interface{}) error

InitReqHandshake --

func (*Connector) IsClosed

func (c *Connector) IsClosed() bool

IsClosed check the connection is closed

func (*Connector) Notify

func (c *Connector) Notify(route string, data []byte) error

Notify send a notification to server

func (*Connector) On

func (c *Connector) On(event string, callback Callback)

On add the callback for the event

func (*Connector) Request

func (c *Connector) Request(route string, data []byte, callback Callback) error

Request send a request to server and register a callbck for the response

func (*Connector) Run

func (c *Connector) Run(addr string, ws bool, tickrate int64) error

Run --

func (*Connector) SetHandshake

func (c *Connector) SetHandshake(handshake interface{}) error

SetHandshake --

func (*Connector) SetHandshakeAck

func (c *Connector) SetHandshakeAck(handshakeAck interface{}) error

SetHandshakeAck --

func (*Connector) SetHeartBeat

func (c *Connector) SetHeartBeat(heartbeat interface{}) error

SetHeartBeat --

type DefaultHandshakePacket

type DefaultHandshakePacket struct {
	Code int              `json:"code"`
	Sys  HeartbeatSysOpts `json:"sys"`
}

DefaultACK --

type HandshakeOpts

type HandshakeOpts struct {
	Sys      SysOpts                `json:"sys"`
	UserData map[string]interface{} `json:"user"`
}

HandshakeOpts --

type HeartbeatSysOpts

type HeartbeatSysOpts struct {
	Heartbeat int `json:"heartbeat"`
}

HeartbeatSysOpts --

type SysOpts

type SysOpts struct {
	Version string                 `json:"version"`
	Type    string                 `json:"type"`
	RSA     map[string]interface{} `json:"rsa"`
}

SysOpts --

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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