bilive

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 13 Imported by: 0

README

bilibili-live-ws

https://github.com/simon300000/bilibili-live-ws 的 golang 移植

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CMD

type CMD string
const (
	CMD_DANMU_MSG              CMD = "DANMU_MSG"              // 弹幕消息
	CMD_WELCOME_GUARD          CMD = "WELCOME_GUARD"          //欢迎xxx老爷
	CMD_ENTRY_EFFECT           CMD = "ENTRY_EFFECT"           // 欢迎舰长进入房间
	CMD_WELCOME                CMD = "WELCOME"                // 欢迎xxx进入房间
	CMD_SUPER_CHAT_MESSAGE_JPN CMD = "SUPER_CHAT_MESSAGE_JPN" // 二个都是SC留言
	CMD_SUPER_CHAT_MESSAGE     CMD = "SUPER_CHAT_MESSAGE"     // 二个都是SC留言

	CMD_SEND_GIFT  CMD = "SEND_GIFT"  // 投喂礼物
	CMD_COMBO_SEND CMD = "COMBO_SEND" // 连击礼物

	CMD_ANCHOR_LOT_START CMD = "ANCHOR_LOT_START" // 天选之人开始完整信息
	CMD_ANCHOR_LOT_END   CMD = "ANCHOR_LOT_END"   // 天选之人获奖id
	CMD_ANCHOR_LOT_AWARD CMD = "ANCHOR_LOT_AWARD" // 天选之人获奖完整信息

	CMD_GUARD_BUY      CMD = "GUARD_BUY"      // 上舰长
	CMD_USER_TOAST_MSG CMD = "USER_TOAST_MSG" // 续费了舰长
	CMD_NOTICE_MSG     CMD = "NOTICE_MSG"     // 在本房间续费了舰长

	CMD_ACTIVITY_BANNER_UPDATE_V2 CMD = "ACTIVITY_BANNER_UPDATE_V2" // 小时榜变动

	CMD_ROOM_REAL_TIME_MESSAGE_UPDATE CMD = "ROOM_REAL_TIME_MESSAGE_UPDATE" // 上舰长

)

type Client

type Client struct {
	RoomID int
	Conn   *websocket.Conn
	// contains filtered or unexported fields
}

func NewClient

func NewClient(roomid int) *Client

func (*Client) Close

func (c *Client) Close() (err error)

func (*Client) Connect

func (c *Client) Connect() (err error)

func (*Client) ReadPackets

func (c *Client) ReadPackets() (pkts []*Packet, err error)

Decode 是解码操作会耗时, 追求性能的话移动到协程里

func (*Client) WritePacket

func (c *Client) WritePacket(pkt Packet) (err error)

type EnterRoom

type EnterRoom struct {
	ClientVer *string `json:"clientver,omitempty"` // 例如 "1.5.10.1"
	Platform  *string `json:"platform,omitempty"`  // 例如 "web"
	ProtoVer  *int    `json:"protover,omitempty"`  // 1 或者 2. protover 为 1 时不会使用zlib压缩,为 2 时会发送带有zlib压缩的包,也就是数据包协议为 2
	RoomID    int     `json:"roomid"`              // 房间长 ID,可以通过 room_init API 获取
	UID       *int    `json:"uid,omitempty"`       // uin,可以通过 getUserInfo API 获取
	Type      *int    `json:"type,omitempty"`      // 不知道啥,总之写 2
}

进房-json-内容 https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md#进房-json-内容

type Message

type Message struct {
	CMD CMD `json:"cmd"`
}

type OpreationType

type OpreationType uint32
const (
	OpreationHeartbeat          OpreationType = 2 // 客户端 - 心跳 - (空) - 不发送心跳包,70 秒之后会断开连接,通常每 30 秒发送 1 次
	OpreationHeartbeatReply     OpreationType = 3 // 服务器 - 心跳回应 - Int 32 Big Endian - Body 内容为房间人气值
	OpreationMessage            OpreationType = 5 // 服务器 - 通知 - JSON - 弹幕、广播等全部信息
	OpreationUserAuthentication OpreationType = 7 // 客户端	- 进房 - JSON - WebSocket 连接成功后的发送的第一个数据包,发送要进入房间 ID
	OpreationConnectSuccess     OpreationType = 8 // 服务器 - 进房回应 - (空)
)

type Packet

type Packet struct {
	PacketLength    uint32          // 数据包长度
	HeaderLength    uint16          // 数据包头部长度(固定为 16)
	ProtocolVersion ProtocolVersion //
	Operation       OpreationType   //
	SequenceID      uint32          // 数据包头部长度(固定为 1)
	Body            []byte          //
}

参考自 https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md

func DecodeHeader

func DecodeHeader(h []byte) (pkt *Packet)

func DecodePackets

func DecodePackets(body []byte) (pkts []*Packet, err error)

func NewConnectPacket

func NewConnectPacket(roomid int) Packet

func NewJSONPacket

func NewJSONPacket(body []byte) (pkt Packet)

func NewPingPacket

func NewPingPacket() Packet

func (*Packet) Bytes

func (pkt *Packet) Bytes() (h []byte)

func (*Packet) Decode

func (pkt *Packet) Decode() (npkt *Packet, err error)

func (*Packet) Header

func (pkt *Packet) Header() (h []byte)

type ProtocolVersion

type ProtocolVersion uint16
const (
	ProtocolNormalBuffer   ProtocolVersion = 0 // 未压缩的buffer
	ProtocolInt32BigEndian ProtocolVersion = 1 // Body 内容为房间人气值
	ProtocolInflateBuffer  ProtocolVersion = 2 // 压缩过的 Buffer,Body 内容需要用zlib.inflate解压出一个新的数据包,然后从数据包格式那一步重新操作一遍
	ProtocolBrotliBuffer   ProtocolVersion = 3 // 压缩信息,需要brotli解压,然后从数据包格式 那一步重新操作一遍
)

Jump to

Keyboard shortcuts

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