dmpkg

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

This file implements the auth exchange. When Bilibili live client established the WebSocket connection successfully, it sends this message at first. The server then responses a OpConnectOk exchange with body `{"code":0}` which indicates success.

Since Bilibili only uses WebSocket binary message, the transportation is effectively a datagram channel. So we use a consumer-supplier abstraction to decouple the real protocol with WebSocket stuff.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAuthOk

func IsAuthOk(serverResponse DanmakuExchange) (bool, error)

Types

type Consumer

type Consumer[T any] interface {
	Consume(value T) error
}

type DanmakuExchange

type DanmakuExchange struct {
	DanmakuExchangeHeader
	Body []byte
}

DanmakuExchange represents an actual message sent from client or server. This is an atomic unit.

func DecodeExchange

func DecodeExchange(data []byte) (exc DanmakuExchange, err error)

func NewAuth

func NewAuth(protocol ProtocolVer, roomId common.RoomId, authKey string) (exc DanmakuExchange)

NewAuth creates a new authentication exchange.

func NewPing

func NewPing() (exc DanmakuExchange)

NewPing construct a new PING exahange.

func NewPlainExchange

func NewPlainExchange(operation Operation, body interface{}) (exc DanmakuExchange, err error)

NewPlainExchange creates a new exchange with raw body specified. body: a struct or a raw string

func (*DanmakuExchange) Inflate

func (e *DanmakuExchange) Inflate() (ret DanmakuExchange, err error)

Inflate decompresses the body if it is compressed

func (*DanmakuExchange) Marshal

func (e *DanmakuExchange) Marshal() (data []byte, err error)

func (*DanmakuExchange) String

func (e *DanmakuExchange) String() string

type DanmakuExchangeHeader

type DanmakuExchangeHeader struct {
	// Length total remaining bytes of this exchange, excluding `Length` itself
	Length uint32
	// HeaderLength = Length - len(Body) + 4, always equals to 16
	HeaderLength uint16
	ProtocolVer  ProtocolVer
	Operation    Operation
	// SequenceId is always 1
	SequenceId uint32
}

type Operation

type Operation uint32
const (
	OpHeartbeat    Operation = 2
	OpHeartbeatAck Operation = 3
	OpLayer7Data   Operation = 5
	OpConnect      Operation = 7
	OpConnectOk    Operation = 8
)

Operations

func (Operation) String

func (o Operation) String() string

type ProtocolVer

type ProtocolVer uint16
const (
	// ProtoPlainJson the body is plain JSON text
	ProtoPlainJson ProtocolVer = 0
	// ProtoMinimal the body is uint32 watcher count (big endian)
	ProtoMinimal ProtocolVer = 1
	// ProtoZlib the body is a zlib compressed package
	ProtoZlib ProtocolVer = 2
	// ProtoBrotli the body is a brotli compressed package
	ProtoBrotli ProtocolVer = 3
)

type Supplier

type Supplier[T any] interface {
	Get() (T, error)
}

Jump to

Keyboard shortcuts

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