pushKit

package
v2.8.125 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 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

	Listener Listener
}

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)
}

Jump to

Keyboard shortcuts

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