Documentation ¶
Index ¶
- Constants
- Variables
- type ActiveSorter
- type BasicMessage
- type ChatMessage
- type Connector
- type ErrorMessage
- type GroupChatNode
- type GroupChatNodePool
- func (obj *GroupChatNodePool) Add(groupChat *GroupChatNode)
- func (obj *GroupChatNodePool) CleanAll()
- func (obj *GroupChatNodePool) CleanByActiveCount()
- func (obj *GroupChatNodePool) CleanByLifeTime()
- func (obj *GroupChatNodePool) CleanGroupChatLoop()
- func (obj *GroupChatNodePool) Del(id int64)
- func (obj *GroupChatNodePool) Get(id int64) (*GroupChatNode, bool)
- type Int64IdSet
- type Message
- type SubsNode
- type SubscriptionMessage
- type SubscriptionNodePool
- type UserNode
- type UserNodePool
Constants ¶
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
const ( TextContent = iota // the text message ImageContent // the picture message VideoContent // the video message VoiceContent // the voice message )
The type code of message content
const SystemId = 1024
Variables ¶
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.
var GlobalGroupChats = &GroupChatNodePool{ groups: make(map[int64]*GroupChatNode), wt: sync.RWMutex{}, }
Saving all nodes for group chat information
var GlobalSubscriptions = &SubscriptionNodePool{ subscriptions: make(map[int64]*SubsNode), wt: sync.RWMutex{}, }
Saving all nodes for subscription information
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 ¶
Create a new connector for the connection.
func (*Connector) ReadMessage ¶
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) 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 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 ¶
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
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 ¶
Create a new node instance for the user's connection
func (*UserNode) AddMessageData ¶
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.