WebsocketDealer

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	EventNewConnection = iota
	/*
		 	EventNewConnection call with *NewConnectData
			The caller of NewConnectData won't be collected.
	*/
	EventConnectionClose
)
View Source
const (
	ModuleName    = "WebsocketDealer"
	ModuleVersion = 0.2
)
View Source
const EventNum = 2

Variables

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

Functions

func InitWebsocketDealer added in v0.0.4

func InitWebsocketDealer()

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

type ConnectData added in v0.0.12

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

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

type Replier added in v0.0.4

type Replier struct {
	// contains filtered or unexported fields
}

func (*Replier) Call added in v0.0.4

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

func (*Replier) Return added in v0.0.4

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

func (*Replier) ToCaller added in v0.0.15

func (z *Replier) ToCaller() *Replier

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
	// contains filtered or unexported fields
}

func NewSession added in v0.0.12

func NewSession() *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 string          `json:"data"`
}

type WebsocketDealFunction

type WebsocketDealFunction func(replier *Replier, session *Session, arguments []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)

func (*WebsocketDealer) BindFunction

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

func (*WebsocketDealer) BroadCast added in v0.0.12

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

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)

*

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

type WebsocketResponse added in v0.0.4

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

Jump to

Keyboard shortcuts

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