MSGNode

package
v0.0.0-...-bbbc4ea Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserChatMessageTypeId     = iota // Users chat with each other one to one
	GroupChatMessageTypeId           // User group chat
	SubscriptionMessageTypeId        // From system notification or subscription
	ErrorMessageTypeId               // Tell the client what error happened
)

The type code of message

View Source
const (
	TextContent  = iota // the text message
	ImageContent        // the picture message
	VideoContent        // the video message
	VoiceContent        // the voice message
)

The type code of message content

View Source
const SystemId = 1024

Variables

View Source
var DelayMessageChat = make(chan [2]interface{}, 10000)

Saving the message which want sent to offline user. This chan has buffer, and the cap is 10000. Every element is an array, which saved the target user's id and bytes data of the message.

View Source
var GlobalGroupChats = &GroupChatNodePool{
	groups: make(map[int64]*GroupChatNode),
	wt:     sync.RWMutex{},
}

Saving all nodes for group chat information

View Source
var GlobalSubscriptions = &SubscriptionNodePool{
	subscriptions: make(map[int64]*SubsNode),
	wt:            sync.RWMutex{},
}

Saving all nodes for subscription information

View Source
var GlobalUsers = &UserNodePool{
	clients: make(map[int64]*UserNode),
	wt:      sync.RWMutex{},
}

Saving all nodes for every client connection.

Functions

This section is empty.

Types

type ActiveSorter

type ActiveSorter []*GroupChatNode

type for sort the group chat node by activeCount

func (ActiveSorter) Len

func (obj ActiveSorter) Len() int

implement the sort.Interface on the ActiveSorter

func (ActiveSorter) Less

func (obj ActiveSorter) Less(i, j int) bool

func (ActiveSorter) Swap

func (obj ActiveSorter) Swap(i, j int)

type BasicMessage

type BasicMessage struct {
	TypeId       int   `json:"type_id"`                 // the type number of message
	SenderId     int64 `json:"sender_id"`               // who send this message, the sender id
	ReceiverId   int64 `json:"receiver_id"`             // who will recv this message, the receiver id
	CreateTime   int64 `json:"create_time,omitempty"`   // set by the message center, timestamp, unit:sec.
	DeliveryTime int64 `json:"delivery_time,omitempty"` // the time for message want be sent, use for timing message
}

Basic message struct

func (*BasicMessage) GetDeliveryTime

func (obj *BasicMessage) GetDeliveryTime() int64

Get the value of 'DeliveryTime' field

func (*BasicMessage) GetReceiverId

func (obj *BasicMessage) GetReceiverId() int64

Get the value of 'ReceiverId' field

func (*BasicMessage) SetCreateTime

func (obj *BasicMessage) SetCreateTime()

Set the create time for the message

type ChatMessage

type ChatMessage struct {
	BasicMessage
	ContentType int    `json:"content_type"`           // how to show the message in client
	Content     string `json:"content,omitempty"`      // text content
	PreviewPic  string `json:"preview_pic,omitempty"`  // preview picture url
	ResourceUrl string `json:"resource_url,omitempty"` // resource URL
	Description string `json:"description,omitempty"`  // simple description
	Additional  string `json:"additional,omitempty"`   // other additional information
}

ChatMessage, used to send NormalMessage and GroupMessage mainly the Content-Type can be of {0:text, 1:picture,2:video, 3:voice}

type Connector

type Connector struct {
	CloseSignal chan struct{}
	DataChan    chan []byte
	// contains filtered or unexported fields
}

The connector for send and receive data with client

func NewConnector

func NewConnector(conn *websocket.Conn) *Connector

Create a new connector for the connection.

func (*Connector) ReadMessage

func (obj *Connector) ReadMessage() (messageType int, p []byte, err error)

func (*Connector) WriteMessage

func (obj *Connector) WriteMessage(messageType int, data []byte) error

type ErrorMessage

type ErrorMessage struct {
	BasicMessage
	Code       int    `json:"code"`                  // the code of error type
	Error      string `json:"error"`                 // the detail error information
	RawMessage []byte `json:"raw_message,omitempty"` // the row message which the user want to send.
}

ErrorMessage, used to send DebugMessage mainly

type GroupChatNode

type GroupChatNode struct {
	Id    int64      // group chat id
	Users Int64IdSet // the id of users whom joined the group chat
	// contains filtered or unexported fields
}

The group chat node, saving some information of the group chat

func NewGroupChatNode

func NewGroupChatNode(id int64, users []int64) *GroupChatNode

Initial a new group chat node.

func (*GroupChatNode) AddActiveCount

func (obj *GroupChatNode) AddActiveCount()

Increased the activeCount of the group chat node, keep the concurrent security.

func (*GroupChatNode) ResetActiveCount

func (obj *GroupChatNode) ResetActiveCount()

Reset the value of activeCount of the group chat node

type GroupChatNodePool

type GroupChatNodePool struct {
	// contains filtered or unexported fields
}

The group chat node pool. Save and manage the group chat nodes

func (*GroupChatNodePool) Add

func (obj *GroupChatNodePool) Add(groupChat *GroupChatNode)

Add a group chat node into the GroupChatPool

func (*GroupChatNodePool) CleanAll

func (obj *GroupChatNodePool) CleanAll()

Reset the groups map

func (*GroupChatNodePool) CleanByActiveCount

func (obj *GroupChatNodePool) CleanByActiveCount()

Clear up nodes whose activity percentage is under the limit

func (*GroupChatNodePool) CleanByLifeTime

func (obj *GroupChatNodePool) CleanByLifeTime()

Clear up nodes whose lifetime exceeds the limit

func (*GroupChatNodePool) CleanGroupChatLoop

func (obj *GroupChatNodePool) CleanGroupChatLoop()

Clear up nodes whose lifetime exceeds the limit or low activity. Working on at NN:00:00 every day by config.

func (*GroupChatNodePool) Del

func (obj *GroupChatNodePool) Del(id int64)

Delete a group chat node from the GroupChatPool

func (*GroupChatNodePool) Get

func (obj *GroupChatNodePool) Get(id int64) (*GroupChatNode, bool)

Get a group chat node from the GroupChatPool

type Int64IdSet

type Int64IdSet struct {
	// contains filtered or unexported fields
}

structure for saving the int64 id

func (*Int64IdSet) Add

func (obj *Int64IdSet) Add(id int64)

func (*Int64IdSet) Del

func (obj *Int64IdSet) Del(id int64)

func (*Int64IdSet) Exist

func (obj *Int64IdSet) Exist(id int64) bool

func (*Int64IdSet) Keys

func (obj *Int64IdSet) Keys() []int64

type Message

type Message interface {
	SetCreateTime()
	GetDeliveryTime() int64
	GetReceiverId() int64
}

type SubsNode

type SubsNode struct {
	Id        int64      // the subscription id
	ManagerId int64      // the id of the manager user
	Fans      Int64IdSet // the id of users whom followed the subscription
	// contains filtered or unexported fields
}

The subscription node, saving some information for the subscription

func NewSubsNode

func NewSubsNode(subsId, managerId int64, fans []int64) *SubsNode

New a subscription node

type SubscriptionMessage

type SubscriptionMessage struct {
	BasicMessage
	Title       string `json:"title"`                  // the title
	Abstract    string `json:"abstract"`               // the brief introduction of this message
	PreviewPic  string `json:"preview_pic,omitempty"`  // the preview picture url
	ResourceUrl string `json:"resource_url,omitempty"` // resource URL
}

SubscriptionMessage, used to send ChannelsMessage mainly

type SubscriptionNodePool

type SubscriptionNodePool struct {
	// contains filtered or unexported fields
}

The group chat node pool. Save and manage the group chat nodes

func (*SubscriptionNodePool) Add

func (obj *SubscriptionNodePool) Add(subsNode *SubsNode)

Add a group chat node into the SubscriptionPool

func (*SubscriptionNodePool) CleanByLifeTime

func (obj *SubscriptionNodePool) CleanByLifeTime()

Clear up nodes whose lifetime exceeds the limit

func (*SubscriptionNodePool) CleanByLifeTimeLoop

func (obj *SubscriptionNodePool) CleanByLifeTimeLoop()

Clear up nodes whose lifetime exceeds the limit. Working on at NN:00:00 every day by config.

func (*SubscriptionNodePool) Del

func (obj *SubscriptionNodePool) Del(id int64)

Delete a group chat node from the SubscriptionPool

func (*SubscriptionNodePool) Get

func (obj *SubscriptionNodePool) Get(id int64) (*SubsNode, bool)

Get a group chat node from the SubscriptionPool

type UserNode

type UserNode struct {
	Id int64

	Friends   Int64IdSet // the id of other users whom are the user's friend
	BlackList Int64IdSet // the id of other users whom are in the user' blacklist
	// contains filtered or unexported fields
}

The node of the user's clients for receiving and sending messages.

func NewUserNode

func NewUserNode(userId int64, friends, blacklist []int64) *UserNode

Create a new node instance for the user's connection

func (*UserNode) AddConn

func (obj *UserNode) AddConn(conn *Connector)

Add a connector for the node, the max count of connectors is 3.

func (*UserNode) AddMessageData

func (obj *UserNode) AddMessageData(data []byte)

add the message data to the node's every connector data channel.If have not any connector here, the message would be saved as delay message

func (*UserNode) ConnsWatchingLoop

func (obj *UserNode) ConnsWatchingLoop()

Watching the connectors of the node, when a connector is closed, remove it from the node and reduce the value of count of the connectors whom are belong to the node. When the node have not connectors, don't save the node in UserNodesPool anymore.

type UserNodePool

type UserNodePool struct {
	// contains filtered or unexported fields
}

func (*UserNodePool) Add

func (obj *UserNodePool) Add(node *UserNode)

Add a new client node into UserNodesPool, if the user is had a node, replace and close the old one

func (*UserNodePool) CleanAll

func (obj *UserNodePool) CleanAll()

Delete all the client node. It would close every connectors and stop the data translate goroutines for every nodes before reset the clients map.

func (*UserNodePool) Del

func (obj *UserNodePool) Del(node *UserNode)

Delete a client node from UserNodesPool, and close the connection of the node.

func (*UserNodePool) Get

func (obj *UserNodePool) Get(id int64) (*UserNode, bool)

Get a client node by id from UserNodesPool

Jump to

Keyboard shortcuts

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