pushKit

package
v2.8.127 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ChannelClosedError = errorKit.New("Channel is already closed")
)

Functions

This section is empty.

Types

type BaseChannel

type BaseChannel struct {
	Id    string
	Bsid  string
	User  string
	Group string

	RWMutex mutexKit.RWMutex

	Data   interface{}
	Closed bool

	Listeners Listeners
}

func (*BaseChannel) IsClosed

func (channel *BaseChannel) IsClosed() (rst bool)

func (*BaseChannel) SetClosed

func (channel *BaseChannel) SetClosed() (flag bool)

SetClosed

PS: 如果返回值为true,应当触发 listener.onClose().

@return true: 设置成功

false:	设置失败(因为已经被设置关闭)

type Channel

type Channel interface {
	// Close 后端主动关闭通道.
	Close() error

	Push(data []byte) error

	IsClosed() (rst bool)

	SetClosed() (flag bool)
}

type Listener

type Listener interface {
	OnFailure(w http.ResponseWriter, r *http.Request, failureInfo string)

	OnHandshake(w http.ResponseWriter, r *http.Request, channel Channel)

	// OnMessage 收到 客户端 发来的消息.
	/*
		PS: 仅适用于WebSocket连接,因为SSE连接是单工的.
	*/
	OnMessage(channel Channel, messageType int, data []byte)

	OnClose(channel Channel, closeInfo string)
}

type Listeners added in v2.8.127

type Listeners []Listener

func NewListeners added in v2.8.127

func NewListeners(listener Listener) Listeners

func (Listeners) OnClose added in v2.8.127

func (listeners Listeners) OnClose(channel Channel, closeInfo string)

func (Listeners) OnFailure added in v2.8.127

func (listeners Listeners) OnFailure(w http.ResponseWriter, r *http.Request, failureInfo string)

func (Listeners) OnHandshake added in v2.8.127

func (listeners Listeners) OnHandshake(w http.ResponseWriter, r *http.Request, channel Channel)

func (Listeners) OnMessage added in v2.8.127

func (listeners Listeners) OnMessage(channel Channel, messageType int, data []byte)

Jump to

Keyboard shortcuts

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