ws
-- import "."
Usage
type BiliBiliLiveWSClient
go
type BiliBiliLiveWSClient struct {
*kernel.BaseClient
}
func NewClient
go
func NewClient(c *kernel.BaseClient) *BiliBiliLiveWSClient
func (*BiliBiliLiveWSClient) BatchHeartBeat
go
func (c *BiliBiliLiveWSClient) BatchHeartBeat(ctx context.Context, data *schema.BiliBiliLiveWSBatchHeartBeatReq) (*schema.BiliBiliLiveWSBatchHeartBeatRes, error)
BatchHeartBeat 发送直播房间批量长链心跳
参数:
ctx - 请求上下文
data - 请求参数,包含以下字段:
• ConnIDs: 心跳ID列表(必填)
返回值:
*schema.BiliBiliLiveWSBatchHeartBeatRes 包含以下字段:
• Code: 状态码(0表示成功)
• Message: 状态信息
• Data.FailedConnIDs: 心跳失败的心跳ID列表
error 调用过程中遇到的错误(如有)
注意事项: 1. 必须每30秒发送一次心跳以保持连接 2. 请求URL为https://member.bilibili.com/arcopen/fn/live/room/ws-batch-heartbeat 3. 请求头需包含Host: member.bilibili.com和Connection: keep-alive
func (*BiliBiliLiveWSClient) HeartBeat
go
func (c *BiliBiliLiveWSClient) HeartBeat(ctx context.Context, data *schema.BiliBiliLiveWSHeartBeatReq) (*schema.BiliBiliLiveWSHeartBeatRes, error)
HeartBeat 发送直播房间长链心跳
参数:
ctx - 请求上下文
data - 请求参数,包含以下字段:
• ClientId: 申请应用时获得的client_id(必填)
• ConnID: 获取长链地址时得到的心跳ID(必填)
返回值:
*schema.BiliBiliLiveWSHeartBeatRes 包含以下字段:
• Code: 状态码(0表示成功)
• Message: 状态信息
• Data: 响应数据(通常为空)
error 调用过程中遇到的错误(如有)
注意事项: 1. 必须每30秒发送一次心跳以保持连接 2. 请求URL为https://member.bilibili.com/arcopen/fn/live/room/ws-heartbeat 3. 请求头需包含Host: member.bilibili.com和Connection: keep-alive
func (*BiliBiliLiveWSClient) Start
go
func (c *BiliBiliLiveWSClient) Start(ctx context.Context) (*schema.BiliBiliLiveWSStartRes, error)
Start 启动直播WebSocket连接
接口文档参考: https://open.bilibili.com/doc/4/da2b13dc-7f7a-0025-be11-0b677e793baa#h1--id
参数:
ctx - 请求上下文
返回值:
*schema.BiliBiliLiveWSStartRes 包含以下字段:
• Code: 状态码
• Message: 消息
• Data: 连接数据,包含以下字段:
- ConnID: 心跳ID (需要在30秒内使用心跳接口保持连接)
- WebSocketInfo: 连接地址
error 调用过程中遇到的错误(如有)