danmu

package module
v0.0.0-...-40ae9f8 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2018 License: MIT Imports: 19 Imported by: 0

README

danmu

轻量弹幕(IM)系统,基于GO

Require

GO >= 1.8

KAFKA >= 1.0

Demo

本项目为你提供了一个在线demo:demo

Getting Start

安装好 GOLANG 环境以及 KAFKA

获取项目源码

go get github.com/kong36088/danmu

到项目config目录下配置好你的kafka地址以及服务监听地址

kafka 创建一个topic danmu

kafka-topics.sh --create --topic danmu --zookeeper localhost:2181 --replication-factor 1 --partitions 1

本项目为提供了一个使用实例,在完成环境部署后,运行以下命令:

$ cd /path/to/your/application

$ cd example/serv/

$ go build   # or go run main.go

$ ./serv    # run your application

服务开启之后,用浏览器访问打开html文件 example/client/room_list.html 即可看到服务效果

Documentation

Index

Constants

View Source
const (
	OPErr = "error"
	OPMsg = "message"
)
View Source
const (
	RoomActionAdd    = 1
	RoomActionDelete = 2
)

Variables

View Source
var (
	OK error = nil
	//sys
	ErrParamError = errors.New("incorrect param")

	//room
	ErrRoomDoesNotExist = errors.New("room does not exist")
)
View Source
var (
	Topic  string
	Topics []string
	Group  string
)

Functions

func CloseKafka

func CloseKafka()

func CloseLog

func CloseLog()

func InitCleaner

func InitCleaner() error

func InitClientBucket

func InitClientBucket() error

func InitConfig

func InitConfig() error

func InitKafka

func InitKafka(kafkaAddrs []string) error

func InitKafkaConsumer

func InitKafkaConsumer(kafkaAddrs []string) error

func InitKafkaProducer

func InitKafkaProducer(kafkaAddrs []string) error

func InitLog

func InitLog() error

func InitMessageHandler

func InitMessageHandler() error

func InitRoomBucket

func InitRoomBucket() error

func StartServer

func StartServer()

func StaticHandler

func StaticHandler(res http.ResponseWriter, req *http.Request)

func WriteTemplateToHttpResponse

func WriteTemplateToHttpResponse(res http.ResponseWriter, t *template.Template) error

Types

type Cleaner

type Cleaner struct {
}

func (*Cleaner) CleanClient

func (cleaner *Cleaner) CleanClient(client *Client)

*

清除保存的client信息,关闭连接

func (*Cleaner) CleanRoom

func (cleaner *Cleaner) CleanRoom(room *Room)

TODO CleanRoom

type Client

type Client struct {
	ClientId cid //remain
	RoomId   rid
	Conn     *websocket.Conn
}

func NewClient

func NewClient(roomId rid, conn *websocket.Conn) *Client

func (*Client) BatchWrite

func (client *Client) BatchWrite(proto []*Proto) error

func (*Client) Close

func (client *Client) Close() error

func (*Client) CloseHandler

func (client *Client) CloseHandler() func(code int, text string)

func (*Client) ErrorReport

func (client *Client) ErrorReport(err error, msg string) error

func (*Client) Read

func (client *Client) Read(v interface{}) (int, []byte, error)

func (*Client) ReadJSON

func (client *Client) ReadJSON(v interface{}) error

func (*Client) Write

func (client *Client) Write(proto *Proto) error

func (*Client) WriteControl

func (client *Client) WriteControl(messageType int, data []byte, deadline time.Time) error

func (*Client) WriteErrorMsg

func (client *Client) WriteErrorMsg(msg string) error

func (*Client) WriteMessage

func (client *Client) WriteMessage(msg string, roomId rid) error

type ClientBucket

type ClientBucket struct {
	Clients map[*websocket.Conn]*Client
	// contains filtered or unexported fields
}

func (*ClientBucket) Add

func (cb *ClientBucket) Add(client *Client) error

func (*ClientBucket) Get

func (cb *ClientBucket) Get(conn *websocket.Conn) (*Client, error)

func (*ClientBucket) Remove

func (cb *ClientBucket) Remove(conn *websocket.Conn) error

type Config

type Config struct {
	// contains filtered or unexported fields
}
var (
	Conf *Config
)

func NewConfig

func NewConfig() *Config

func (*Config) GetAllConfig

func (c *Config) GetAllConfig() map[string]map[string]string

func (*Config) GetConfig

func (c *Config) GetConfig(section, option string) string

func (*Config) GetSectionConfig

func (c *Config) GetSectionConfig(section string) map[string]string

type MessageRoomObserver

type MessageRoomObserver struct{}

func (*MessageRoomObserver) Update

func (mro *MessageRoomObserver) Update(action int, room *Room)

type Proto

type Proto struct {
	OP      string `json:"op"`
	Message string `json:"message"`
	RoomId  rid    `json:"room_id"`
}

func NewProto

func NewProto() *Proto

func (*Proto) JsonEncode

func (p *Proto) JsonEncode() string

func (Proto) String

func (p Proto) String() string

type Room

type Room struct {
	RoomId rid
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(roomId rid) *Room

func (*Room) AddClient

func (room *Room) AddClient(client *Client) error

func (*Room) GetClients

func (room *Room) GetClients() map[*websocket.Conn]*Client

func (Room) String

func (room Room) String() string

type RoomBucket

type RoomBucket struct {
	Rooms map[rid]*Room
	// contains filtered or unexported fields
}

func (*RoomBucket) Add

func (rb *RoomBucket) Add(room *Room) error

func (*RoomBucket) AttachObserver

func (rb *RoomBucket) AttachObserver(observer RoomObserverInterface)

func (*RoomBucket) DetachObserver

func (rb *RoomBucket) DetachObserver(observer RoomObserverInterface)

func (*RoomBucket) Get

func (rb *RoomBucket) Get(id rid) (*Room, error)

func (*RoomBucket) Remove

func (rb *RoomBucket) Remove(room *Room) error

type RoomObserverInterface

type RoomObserverInterface interface {
	Update(int, *Room)
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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