douyuclient

package
v0.0.0-...-4cd40bb Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: Apache-2.0 Imports: 9 Imported by: 1

README

Douyu Client

Read Douyu's barrage data

Import

import "github.com/DreamedOfMe/barrage-kit/douyuclient"

Demo

package main
import (
	"fmt"
	"github.com/DreamedOfMe/barrage-kit/douyuclient"
	"time"
)

func main() {
    fmt.Println("started")
    client := douyuclient.New("openbarrage.douyutv.com:8601", 50)
    client.AddRoom("196")
    client.AddRoom("52004")
    msgChannel, err := client.Start()
    if err != nil {
        fmt.Println(err)
        return
    }
    go func() {
        time.Sleep(20 * time.Second)
        client.AddRoom("252140")
        time.Sleep(20 * time.Second)
        client.Stop()
    }()
    for msg := range msgChannel {
        fmt.Println("msg", msg.Text())
    }
    
    fmt.Println("restart after 5s")
    
    time.Sleep(5 * time.Second)
    msgChannel, err = client.Start()
    if err != nil {
        fmt.Println(err)
        return
    }
    go func() {
        time.Sleep(20 * time.Second)
        client.Stop()
    }()
    for msg := range msgChannel {
        fmt.Println("msg2", msg.Text())
    }
    
    fmt.Println("exit after 5s")
    
    time.Sleep(5 * time.Second)
    fmt.Println("end main")
}

Documentation

Index

Constants

View Source
const (
	ClientInit = iota
	ClientRunning
	ClientStopping
	ClientStopped
)
View Source
const (
	TaskTypeCreate = iota
	TaskTypeDeleteAll
	TaskTypeReconnect
)

Variables

This section is empty.

Functions

func CreateRawMsg

func CreateRawMsg(data []byte, msgType uint16) []byte

func CreateRawSendMsg

func CreateRawSendMsg(data string) []byte

func SetLoggerOut

func SetLoggerOut(out io.Writer)

Types

type Client

type Client interface {
	AddRoom(roomId string)
	Start() (<-chan *Message, error)
	Status() byte
	Stop()
}

func New

func New(address string, bufferSize uint32) Client

type ConnectStatus

type ConnectStatus byte
const (
	ConnectConnected ConnectStatus = iota
	ConnectDisconnected
)

type Message

type Message struct {
	NanoTimestamp int64
	RawContent    []byte
}

Message contains the timestamp and content of the received message.

func (*Message) Body

func (message *Message) Body() []byte

func (*Message) Head

func (message *Message) Head() []byte

func (*Message) Text

func (message *Message) Text() string

Jump to

Keyboard shortcuts

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