ws

package
v0.0.0-...-1ea7b73 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperationHeartbeat          = 2
	OperationHeartbeatReply     = 3
	OperationMessage            = 5
	OperationUserAuthentication = 7
	OperationConnectSuccess     = 8

	PackageHeaderTotalLength = 16

	PackageOffset   = 0
	HeaderOffset    = 4
	VersionOffset   = 6
	OperationOffset = 8
	SequenceOffset  = 12

	BodyProtocolVersionNormal  = 0
	BodyProtocolDeflateVersion = 2
	HeaderDefaultVersion       = 1
	HeaderDefaultOperation     = 1
	HeaderDefaultSequence      = 1
	AuthOk                     = 0
	AuthTokenError             = -101
)

Variables

This section is empty.

Functions

func CreateLiveConn

func CreateLiveConn(wsHostServer types.WsHostServer) (*websocket.Conn, error)

func GetDanmuHostList

func GetDanmuHostList(roomId int, cookie string) (*types.GetDanmuHostListResp, error)

func LiveId2RoomId

func LiveId2RoomId(liveId int) (int, error)

func SendAuthMessage

func SendAuthMessage(ws *websocket.Conn, authMsg types.AuthMessage) error

func SendHeartbeat

func SendHeartbeat(ws *websocket.Conn) error

Types

type Header struct {
	PackLength uint32
	HeadLength uint16
	Version    uint16
	Operation  uint32
	Sequence   uint32
}

func PackHeader

func PackHeader(packLength, operation uint32) Header

func UnpackHeader

func UnpackHeader(head []byte) (Header, error)

func (Header) ToBytes

func (h Header) ToBytes() []byte

type Message

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

func PackMessage

func PackMessage(operation uint32, raw []byte) Message

func UnpackMessage

func UnpackMessage(raw []byte) ([]Message, error)

UnpackMessage 解析直播间消息 被压缩的消息是一组 Message, 所以解析完成会返回 []Message 而非 Message

func (Message) Operation

func (message Message) Operation() uint32

func (Message) Payload

func (message Message) Payload() []byte

func (Message) ToBytes

func (message Message) ToBytes() []byte

Jump to

Keyboard shortcuts

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