Coder Social home page Coder Social logo

douyumsg's Introduction

@@ -1,56 +1,44 @@

go-douyuchatmsg for golang


斗鱼弹幕客户端

package main

功能:

  • 获取斗鱼服务器弹幕消息,礼物消息,动态消息等

安装

go get -u github.com/dalgurak007/douyumsg

导入

import "github.com/dalgurak007/douyumsg"

快速开始

package main

import (
	"fmt"
	"github.com/dalgurak007/douyumsg"
	"os"
	"runtime"
)

func main() {
	// 根据房间号码获取一个房间
	room := douyumsg.NewRoom("122402")
	// 与服务器建立连接
	go func() {
		err := room.Run("openapi-danmu.douyu.com:8601")
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	}()
	// 获取弹幕消息,传入chan缓冲区大小,返回一个chan
	go func() {
		msg := room.ReceiveBarrage(100)
		for {
			m := <-msg
			fmt.Println("level:", m["level"], m["nn"], ":", m["txt"])
		}
	}()
	// 获取用户进入房间通知
	go func() {
		msg := room.JoinRoom(0)
		for {
			m := <-msg
			fmt.Println("用户:", "level:", m["level"], m["nn"], "进入直播间")
		}
	}()
	// 获取所有消息,同样返回一个chan,需要自己对消息进行过滤处理,格式参考斗鱼弹幕服务器第三方接入协议v1.6.2.pdf
	//for {
	//	msg := <-room.ReceiveAll(100)
	//	fmt.Println(msg)
	//}

	runtime.Goexit()
}

斗鱼服务消息格式参考

作者: dalgurak007 欢迎大家加入开发。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.