message

package
v0.0.0-...-828062d Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2018 License: MIT Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ConnType_WebSocket = "websocket"
	ConnType_LongPoll  = "longpoll"
)

连接类型

View Source
const (
	MessageLevel_All    = "0" //"all"
	MessageLevel_Normal = "1" //"normal"
	MessageLevel_Auth   = "2" //"auth" 表示仅发送给经过鉴权的连接
)

消息级别

View Source
const DefaultTimeOut = 60 //second
View Source
const MaxQueueMessageCount = 10000
View Source
const OnlineGroupID = "online"

Variables

View Source
var AppPool map[string]*AppGroups

应用集合

Functions

func CheckAuthToken

func CheckAuthToken(app *config.AppInfo, appId, groupId, groupIds, userId, token string) (RetCode int, RetMsg string)

检查应用鉴权结果 Author: panxinming CreateTime: 2017-02-07 13:00 入参: app:应用配置信息 appId:应用编号 groupid:用户组编号,应用自定义 userid:用户编号,应用需保证userid在同Appid下的唯一性 token:鉴权token 返回值: 0 成功 -101001:no permission connect! => appid[" + appId + "] no exists -101002:no permission connect! => check token has an error => [http-request-error] -101003:no permission connect! => check token has an error => [json-parse-error] -101004:no permission connect! => check token result => -101005:no permission connect! => check token: appid|groupid|userid not match

update log: 1、初始版本 --2017-02-07 13:00 by pxm

func GetMaxClientIndex

func GetMaxClientIndex() uint64

func GetTotalClientCreateCount

func GetTotalClientCreateCount() uint64

func InitAppInfo

func InitAppInfo()

init appgroupinfo

func PushMessage

func PushMessage(message string) (int, string)

push new message result: -10001:jsonunmar error -10002:this appid no have permission

func ReStartMessageService

func ReStartMessageService()

重新启动消息监听与消费服务

func RegisterClient

func RegisterClient(client *UserClient) int

register new userclient with roomid return values: -10001: not exists appid -10002: usergroup error 0: ok

func RemoveClient

func RemoveClient(client *UserClient)

remove userclient with roomid

func StartMessageService

func StartMessageService()

全局启动消息监听与消费服务

Types

type AppConnData

type AppConnData struct {
	AppID           string
	TotalCount      int
	NormalWebsocket int
	AuthWebsocket   int
	NormalLongPoll  int
	AuthLongPoll    int
}

type AppGroups

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

表示用户组的集合

func GetAppGroups

func GetAppGroups(appId string) (*AppGroups, bool)

get appgroups with appid

func GetState_AppGroups

func GetState_AppGroups(appId string) (*AppGroups, bool)

get appgroups with appid

func NewAppGroups

func NewAppGroups(appid string) *AppGroups

create a new groups

func (*AppGroups) GetAndInitUserGroup

func (app *AppGroups) GetAndInitUserGroup(appId, groupId string) *UserGroup

get and init UserGroup with appid

func (*AppGroups) GetGroupCount

func (app *AppGroups) GetGroupCount() int

get app's usergroup count

func (*AppGroups) GetState_AuthLongPollCount

func (app *AppGroups) GetState_AuthLongPollCount(groupIds ...string) int

get app's auth longpoll client count

func (*AppGroups) GetState_AuthWebSocketCount

func (app *AppGroups) GetState_AuthWebSocketCount(groupIds ...string) int

get app's auth websocke client count

func (*AppGroups) GetState_LongPollCount

func (app *AppGroups) GetState_LongPollCount(groupIds ...string) int

get app's longpoll client count

func (*AppGroups) GetState_TotalClientCount

func (app *AppGroups) GetState_TotalClientCount(groupIds ...string) int

get app's total client count

func (*AppGroups) GetState_UserGroups

func (ag *AppGroups) GetState_UserGroups() map[string]*UserGroup

获取用户组列表

func (*AppGroups) GetState_WebSocketCount

func (app *AppGroups) GetState_WebSocketCount(groupIds ...string) int

get app's websocke client count

func (*AppGroups) GetUserGroup

func (ag *AppGroups) GetUserGroup(groupId string) (*UserGroup, bool)

获取指定用户组

func (*AppGroups) SendMessage

func (ag *AppGroups) SendMessage(message *Message) int

send a meeage for full app groups online groupid do nothing return send client count

type ConnData

type ConnData struct {
	Apps     []AppConnData
	DataTime time.Time
}

func GetConnData

func GetConnData() *ConnData

获取连接信息

type Message

type Message struct {
	//消息关联AppID
	AppID string
	//消息关联GroupID
	GroupID string
	//消息关联UserID
	UserID string
	//消息接收级别 - 目前分为all、auth、normal -匹配MessageLevel_Const
	MessageLevel string
	//消息接收AppID
	ToAppID string
	//消息接收GroupID
	ToGroupID string
	//消息接收UserID
	ToUserID string
	//消息接收UserID列表
	ToUserList interface{}
	//消息内容
	Content string
}

消息定义

type MessageQueue

type MessageQueue struct {
	AppID   string
	MsgChan chan Message
}

消息队列

type UserClient

type UserClient struct {
	Index    uint64 //客户端唯一索引
	ConnType string

	MessageChan chan string `json:"-"`

	TimeOut     int64    //超时时间 - 单位为秒
	From        string   //请求来源,比如site、mobile、jrpt等
	UserID      string   //user id
	GroupId     string   //用户组编号
	GroupIds    []string //多用户组编号
	AppId       string   //用户应用编号
	RemoteIP    string   //用户IP信息“ip:port”
	ReferrerUrl string   //ReferrerUrl
	IsAuth      bool     //是否带鉴权
	// contains filtered or unexported fields
}

user client for websocket

func NewClient

func NewClient(appId, userId, groupId, from string, groupIds []string, isAuth bool, ws *dotweb.WebSocket, context dotweb.Context) *UserClient

create a new UserClient with socketconn&userinfo

func (*UserClient) GetClientInfo

func (uc *UserClient) GetClientInfo() string

get client's json string

func (*UserClient) GetIndex

func (uc *UserClient) GetIndex() uint64

get client's serverindex

func (*UserClient) GetReferrerUrl

func (uc *UserClient) GetReferrerUrl() string

get client's referrer url

func (*UserClient) GetRemoteAddr

func (uc *UserClient) GetRemoteAddr() string

get client's remoteaddr

func (*UserClient) GetWebSocket

func (uc *UserClient) GetWebSocket() *dotweb.WebSocket

get client's websocket

func (*UserClient) ReadMessage

func (uc *UserClient) ReadMessage() (string, error)

read message from websocket.conn or hijackConn

func (*UserClient) Reset

func (uc *UserClient) Reset(appId, userId, groupId, from string, groupIds []string, isAuth bool, ws *dotweb.WebSocket, context dotweb.Context)

reset userclient attr

func (*UserClient) SendMessage

func (uc *UserClient) SendMessage(message string)

send message to client

type UserGroup

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

表示一组用户

func GetUserGroup

func GetUserGroup(appId, groupId string) (*UserGroup, bool)

get usergroup with appid & groupid

func NewUserGroup

func NewUserGroup(groupId string) *UserGroup

create a new client group

func (*UserGroup) AddClient

func (ug *UserGroup) AddClient(client *UserClient)

add new client into usergroup

func (*UserGroup) DeleteClient

func (ug *UserGroup) DeleteClient(client *UserClient)

delete a userclient

func (*UserGroup) GetGroupId

func (ug *UserGroup) GetGroupId() string

func (*UserGroup) GetState_AuthLongPollClientCount

func (ug *UserGroup) GetState_AuthLongPollClientCount() int

get usergroup's auth longpollclient count

func (*UserGroup) GetState_AuthWebSocketClientCount

func (ug *UserGroup) GetState_AuthWebSocketClientCount() int

get usergroup's auth websocketclient count

func (*UserGroup) GetState_LongPollClientCount

func (ug *UserGroup) GetState_LongPollClientCount() int

get usergroup's longpollclient count

func (*UserGroup) GetState_WebSocketClientCount

func (ug *UserGroup) GetState_WebSocketClientCount() int

get usergroup's websocketclient count

func (*UserGroup) GetUserClient

func (ug *UserGroup) GetUserClient(userId string) (*UserClient, bool)

获取指定UserId的用户客户端代理

func (*UserGroup) SendMessage

func (ug *UserGroup) SendMessage(message *Message) int

send a meeage for full group return send client count

Jump to

Keyboard shortcuts

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