Version: v0.1.4 Latest Latest

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

Go to latest
Published: Aug 23, 2021 License: Apache-2.0 Imports: 15 Imported by: 0



@Title WebsocketDealer.go @Description 实现websocket低成本call 需要客户端配合 @Author Dorbmon



View Source
const (
	EventNewConnection = iota
		 	EventNewConnection call with *NewConnectData
			The caller of NewConnectData won't be collected.
		EventConnectionClose call with *NewConnectData.
		But you shouldn't write any data cause the connection had been close.
View Source
const (
	ModuleName    = "WebsocketDealer"
	ModuleVersion = 0.4
View Source
const EventNum = 3


View Source
var FunctionCallPool = sync.Pool{New: func() interface{} {
	return new(FunctionCall)
View Source
var NewConnectDataPool = sync.Pool{New: func() interface{} {
	return new(ConnectData)
View Source
var Once sync.Once


func Decode added in v0.1.1

func Decode(data []byte) ([]byte, error)

func InitWebsocketDealer added in v0.0.4

func InitWebsocketDealer()


type Coder added in v0.1.1

type Coder interface {
	Encode([]byte) []byte
	Decode([]byte) ([]byte, error)

type ConnectData added in v0.0.12

type ConnectData struct {
	Session *Session
	Context *RWeb.Context
	Caller  *Replier

type DefaultCoder added in v0.1.1

type DefaultCoder struct{}

func (*DefaultCoder) Encode added in v0.1.1

func (z *DefaultCoder) Encode(data []byte) []byte

type FunctionCall added in v0.0.22

type FunctionCall struct {
	FunctionName string
	Argument     []interface{}
	Session      *Session

type GlobalHandler added in v0.0.22

type GlobalHandler struct {
	// contains filtered or unexported fields

func NewGlobalHandler added in v0.0.22

func NewGlobalHandler() GlobalHandler

func (*GlobalHandler) GC added in v0.0.22

func (z *GlobalHandler) GC()

func (*GlobalHandler) MountUser added in v0.0.22

func (z *GlobalHandler) MountUser(key interface{}, val interface{}) bool

func (*GlobalHandler) SetDownFunction added in v0.0.22

func (z *GlobalHandler) SetDownFunction(f func(key interface{}, userData interface{}, lastBeatTime time.Time) bool)

func (*GlobalHandler) SetMaxHandleTime added in v0.0.22

func (z *GlobalHandler) SetMaxHandleTime(time time.Duration)

SetMaxHandleTime when it takes too long for a user to send a heart beat message,the user will be kicked off from the server. The MaxHandleTime is the limit.

func (*GlobalHandler) UserBeat added in v0.0.22

func (z *GlobalHandler) UserBeat(key interface{}) bool

type NumberPool added in v0.0.15

type NumberPool struct {
	// contains filtered or unexported fields

func NewNumberPool added in v0.0.15

func NewNumberPool(initNumber uint64) (ret NumberPool)

newNumberPool 生成新的Pool initNumber 初始化的数字数量

func (*NumberPool) Get added in v0.0.15

func (z *NumberPool) Get() uint64

func (*NumberPool) Put added in v0.0.15

func (z *NumberPool) Put(num uint64)

type Ranger added in v0.0.12

type Ranger func(data *ConnectData) error

Ranger broadCast ranger

type Replier added in v0.0.4

type Replier struct {
	// contains filtered or unexported fields

func R added in v0.0.16

func R() *Replier

R get the replier

func (*Replier) Call added in v0.0.4

func (z *Replier) Call(functionName string, args ...interface{}) (interface{}, error)

Call 调用客户端函数

func (*Replier) CallNotWait added in v0.0.18

func (z *Replier) CallNotWait(functionName string, args ...interface{}) error

CallNotWait 不等待回复

func (*Replier) Return added in v0.0.4

func (z *Replier) Return(data interface{}) error

Return 返回值

func (*Replier) ToCaller added in v0.0.15

func (z *Replier) ToCaller() *Replier

ToCaller With this function,you can turn a replier to a pure caller which means that you can keep this new caller while the replier will be collected and reused by RWeb.

type Session added in v0.0.12

type Session struct {
	Data       interface{}
	CreateTime int64

	Id uuid.UUID
	// contains filtered or unexported fields

func NewSession added in v0.0.12

func NewSession() *Session

NewSession Build a session

func S added in v0.0.16

func S() *Session

S get the session

type StandardCall

type StandardCall struct {
	Function string          `json:"function"`
	Argument []interface{}   `json:"argument"`
	Id       jsoniter.Number `json:"id"`
	IsReply  bool            `json:"reply"` //只是保留,客户端不需要实现 若为Reply时,需要设置为true

type StandardReply added in v0.0.4

type StandardReply struct {
	Id   jsoniter.Number `json:"id"`
	Data interface{}     `json:"data"`

type WebsocketCallInterceptor added in v0.0.19

type WebsocketCallInterceptor func(functionName string, replier *Replier, session *Session, args []interface{}) bool

type WebsocketDealFunction

type WebsocketDealFunction interface{}

type WebsocketDealer

type WebsocketDealer struct {
	OriginCheck func(ctx *RWeb.Context) bool

	Events event.System
	// contains filtered or unexported fields

func New

func New() (r WebsocketDealer)

New new websocket dealer

func (*WebsocketDealer) AddInterceptor added in v0.0.19

func (z *WebsocketDealer) AddInterceptor(interceptor WebsocketCallInterceptor)

AddInterceptor 添加拦截器

func (*WebsocketDealer) BindFunction

func (z *WebsocketDealer) BindFunction(FunctionName string, Function WebsocketDealFunction) error

BindFunction 绑定函数

func (*WebsocketDealer) BroadCast added in v0.0.12

func (z *WebsocketDealer) BroadCast(ranger Ranger) error

BroadCast 广播

func (*WebsocketDealer) BroadCastIdRange added in v0.0.12

func (z *WebsocketDealer) BroadCastIdRange(ranger Ranger, ids []uint64) error

func (*WebsocketDealer) Handler

func (z *WebsocketDealer) Handler(context *RWeb.Context)


Handler 使用此函数作为引擎的绑定函数

type WebsocketResponse added in v0.0.4

type WebsocketResponse struct {
	Id      jsoniter.Number `json:"id"`
	Data    interface{}     `json:"data"`
	IsReply bool            `json:"reply"`

Jump to

Keyboard shortcuts

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