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