Documentation ¶
Index ¶
- Constants
- Variables
- func ContentQuote(d interface{}) string
- func IsClientEvent(ev int32) bool
- func IsExServerEvent(ev int32) bool
- func IsServerEvent(ev int32) bool
- func IsUserStatusChanged(ev int32) bool
- func Register(key int32, value DisposeFunc)
- func SessionToPBSession(session *Session, token string) *pb.Session
- func SessionToPBUser(session *Session) *pb.User
- func ToPBEvent(ev *Event) *pb.Event
- type App
- type ArrayCopy
- type Client
- func (c *Client) Heartbeat(currentTime int64)
- func (c *Client) IsClosed() bool
- func (c *Client) IsHeartbeatTimeout(currentTime int64) bool
- func (c *Client) IsLogin() bool
- func (c *Client) IsSameAppId(session *Session) bool
- func (c *Client) IsSamePlat(session *Session) bool
- func (c *Client) Login(user *Session, loginTime int64)
- func (c *Client) Logout(logoutTime int64)
- func (c *Client) SendTo(msg []byte) error
- func (c *Client) SendToQueue(msg []byte) error
- func (c *Client) String() string
- type Config
- type Connect
- type DisposeFunc
- type Event
- type EventReq
- type EventRes
- type EventType
- type Group
- func (g *Group) CheckMember(chatGroup chat.Group, from *Session) ([]chat.MemberId, bool)
- func (g *Group) Enter(chatGroup chat.Group, user *chat.Member, option *chat.Option)
- func (g *Group) Enters(chatGroup chat.Group, members []chat.Member, option *chat.Option)
- func (g *Group) Leave(chatGroup chat.Group, userId chat.MemberId, option *chat.Option)
- func (g *Group) Leaves(chatGroup chat.Group, members []chat.Member, option *chat.Option)
- func (g *Group) Remove(chatGroup chat.Group, option *chat.Option)
- func (g *Group) Send(chatGroup chat.Group, from *Session, amMemberFn IAmMemberFunc, fn MemberFunc) error
- func (g *Group) String() string
- func (g *Group) UpdateVersion(chatGroup chat.Group, option *chat.Option)
- type GroupMgr
- func (mgr *GroupMgr) CreateGroup(from *Session, group *chat.GroupModel, option *chat.Option) error
- func (mgr *GroupMgr) DeleteGroup(from *Session, groupId int64, option *chat.Option) error
- func (mgr *GroupMgr) GetGroup(groupKey string) (*Group, error)
- func (mgr *GroupMgr) JoinGroup(from *Session, group *chat.GroupModel, option *chat.Option) error
- func (mgr *GroupMgr) LeaveGroup(from *Session, group *chat.GroupModel, option *chat.Option) error
- func (mgr *GroupMgr) OfflineGroups(from *Session)
- func (mgr *GroupMgr) OnlineGroups(from *Session)
- func (mgr *GroupMgr) Send(from *Session, chat *chat.Message, amMemberFn IAmMemberFunc, fn MemberFunc) error
- func (mgr *GroupMgr) WithChatGroup(group chat.Group)
- type IAmMemberFunc
- type IM
- func (im *IM) AddClients(client *Client)
- func (im *IM) AddUsers(key string, client *Client)
- func (im *IM) CheckAllUserOnline(session *Session) bool
- func (im *IM) CheckUserOnline(session *Session) bool
- func (im *IM) ClearTimeoutConnections()
- func (im *IM) ClientsRange(f func(client *Client) (result bool))
- func (im *IM) DelClients(client *Client)
- func (im *IM) DelUsers(client *Client) bool
- func (im *IM) GetAllUserList(session *Session) *UserList
- func (im *IM) GetClients() []*Client
- func (im *IM) GetLocalUserList(session *Session) *UserList
- func (im *IM) GetServerHost() string
- func (im *IM) GetServerPort() int
- func (im *IM) GetServers() []builder.Address
- func (im *IM) GetUserClient(session *Session) *Client
- func (im *IM) GrpcClient() rpc.IMClient
- func (im *IM) Handler(connect Connect, w http.ResponseWriter, r *http.Request)
- func (im *IM) InClient(client *Client) (ok bool)
- func (im *IM) Init(client discoveryservice.Client, rpcClient rpc.IMClient, user User, ...)
- func (im *IM) IsLocalAddress(server string) bool
- func (im *IM) RateLimit(session Session, version string) bool
- func (im *IM) ReceiveFromExServer(from *Session, to *Session, ev *Event, defHandler func())
- func (im *IM) ReceiveToLocal(from *Session, to *Session, ev *Event)
- func (im *IM) SendChat(from *Session, ev *Event, option chat.Option, handler func()) error
- func (im *IM) SendToAllUser(from *Session, to *Session, ev *Event, custom interface{})
- func (im *IM) SendToLocalAppId(from *Session, to *Session, ev *Event, custom interface{})
- func (im *IM) SendToLocalUser(from *Session, to *Session, ev *Event) (error, bool)
- func (im *IM) SendToRemote(from *Session, to *Session, ev *Event)
- func (im *IM) SendToRemoteAppId(addr string, from *Session, to *Session, ev *Event)
- func (im *IM) SendToRemoteUser(from *Session, to *Session, ev *Event) error
- func (im *IM) SendToUser(from *Session, to *Session, ev *Event) error
- func (im *IM) SyncToRemoteOnly(from *Session, to *Session, ev *Event)
- func (im *IM) UnInit()
- func (im *IM) UserMgr() User
- func (im *IM) WithGroupModel(chat chat.Group) *IM
- func (im *IM) WithGrpcClient(grpc rpc.IMClient) *IM
- func (im *IM) WithUserMgr(user User) *IM
- type MemberFunc
- type Online
- type Option
- type ReqHead
- func (h *ReqHead) GetRecvAt() int64
- func (h *ReqHead) GetReqAt() int64
- func (h *ReqHead) GetSeqId() string
- func (h *ReqHead) GetSource() string
- func (h *ReqHead) GetTimeOut() time.Duration
- func (h *ReqHead) GetVersion() string
- func (h *ReqHead) SetSource(source string)
- func (h *ReqHead) SetTimeOut(duration time.Duration)
- type ResHead
- type Session
- type Status
- type User
- type UserList
- type Work
Constants ¶
View Source
const ( ETException = EventType(1) ETClientPing = EventType(2) ETClientPingRsp = EventType(3) // ETClientBegin 客户端开始 ETClientBegin = EventType(10) ETClientHeartBeat = EventType(10) ETClientHeartBeatRsp = EventType(11) // ETClientLogin 登录 ETClientLogin = EventType(100) ETClientLoginRsp = EventType(101) ETClientLogout = EventType(102) ETClientLogoutRsp = EventType(103) // ETClientUserStatusChanged 用户状态发生变化 ETClientUserStatusChanged = EventType(104) ETClientUserStatusChangedRes = EventType(105) ETClientUserList = EventType(106) ETClientUserListRsp = EventType(107) // ETClientKicked 多端使用,被踢 ETClientKicked = EventType(108) // ETMessage 消息事件 ETMessage = EventType(200) ETMessageRsp = EventType(201) ETNotify = EventType(202) ETNotifyRsp = EventType(203) // ETChat 聊天事件 ETChat = EventType(204) ETChatRsp = EventType(205) // ETClientEnd 客户端结束 ETClientEnd = EventType(4999) // ETServerBegin 服务之间 ETServerBegin = EventType(5000) ETServerEnd = EventType(10000) // ETExServerBegin 外部服务 ETExServerBegin = EventType(20000) ETExServerEnd = EventType(30000) // ETHungUp 电话区间 ETHungUp = EventType(50000) ETHungUpRsp = EventType(50001) ETAppCall = EventType(50002) ETAppCallRsp = EventType(50003) // ETCallTransfer 将当前通道转接到某个用户 ETCallTransfer = EventType(50004) ETCallTransferRsp = EventType(50005) // ETCallListen 监听电话 ETCallListen = EventType(50006) ETCallListenRsp = EventType(50007) ETCallout2 = EventType(50008) ETCallout2Rsp = EventType(50009) ETCallout = EventType(50010) ETCalloutRsp = EventType(50011) )
View Source
const ( StatusOffline = 1 StatusOnline = 2 StatusHeartbeat = 3 )
View Source
const UserHeartbeatTimeout = int64(time.Minute * 3)
UserHeartbeatTimeout 3分钟
Variables ¶
View Source
var IAmNotMemberErr = errors.New("i am not member")
View Source
var (
KEmptyByte = []byte("")
)
View Source
var NotExistRemoteServer = result.Error(-100, "not exist remote server")
View Source
var StatusDesc = map[int32]string{ StatusOffline: "离开", StatusOnline: "在线", }
Functions ¶
func ContentQuote ¶
func ContentQuote(d interface{}) string
func IsClientEvent ¶
func IsExServerEvent ¶
func IsServerEvent ¶
func IsUserStatusChanged ¶
func Register ¶
func Register(key int32, value DisposeFunc)
func SessionToPBUser ¶
Types ¶
type Client ¶
type Client struct { User Session Conn *websocket.Conn // 用户连接 ClientId uint64 ConnectId uint64 Index int64 Addr string // 客户端地址 Token string InUserList bool // 是否在 IM.userClient // contains filtered or unexported fields }
func (*Client) IsHeartbeatTimeout ¶
func (*Client) IsSameAppId ¶
func (*Client) IsSamePlat ¶
func (*Client) SendToQueue ¶
type DisposeFunc ¶
type Event ¶
type Event struct { // 事件基数 EvTypeBase int32 `json:"-"` // 事件类型, EventType EventType int32 `json:"eventType"` // Content 格式,json,xml...protobuff, 默认json ContentType string `json:"contentType"` // 具体的业务数据 Content string `json:"content"` }
func CreateEvent ¶
func CreateEventWithContent ¶
type EventRes ¶
func NewResponse ¶
type Group ¶
Group 群
func (*Group) CheckMember ¶
func (*Group) Send ¶
func (g *Group) Send(chatGroup chat.Group, from *Session, amMemberFn IAmMemberFunc, fn MemberFunc) error
type GroupMgr ¶
type GroupMgr struct {
// contains filtered or unexported fields
}
func NewGroupMgr ¶
func NewGroupMgr() *GroupMgr
func (*GroupMgr) CreateGroup ¶
func (*GroupMgr) DeleteGroup ¶
func (*GroupMgr) LeaveGroup ¶
func (*GroupMgr) OfflineGroups ¶
OfflineGroups 用户离线
func (*GroupMgr) OnlineGroups ¶
OnlineGroups 用户上线,需要初始化群组路由
func (*GroupMgr) Send ¶
func (mgr *GroupMgr) Send(from *Session, chat *chat.Message, amMemberFn IAmMemberFunc, fn MemberFunc) error
func (*GroupMgr) WithChatGroup ¶
type IAmMemberFunc ¶
IAmMemberFunc 是否是群成员, iAmMember= true 是成员
type IM ¶
type IM struct {
// contains filtered or unexported fields
}
func (*IM) AddClients ¶
func (*IM) CheckAllUserOnline ¶
func (*IM) CheckUserOnline ¶
CheckUserOnline 查询用户是否在线
func (*IM) ClearTimeoutConnections ¶
func (im *IM) ClearTimeoutConnections()
func (*IM) ClientsRange ¶
func (*IM) DelClients ¶
func (*IM) GetAllUserList ¶
GetAllUserList 查询所有用户
func (*IM) GetClients ¶
func (*IM) GetLocalUserList ¶
GetLocalUserList 本机的用户
func (*IM) GetServerHost ¶
func (*IM) GetServerPort ¶
func (*IM) GetServers ¶
func (*IM) GetUserClient ¶
func (*IM) GrpcClient ¶
func (*IM) IsLocalAddress ¶
func (*IM) ReceiveFromExServer ¶
ReceiveFromExServer 收到外服务器的消息
func (*IM) ReceiveToLocal ¶
ReceiveToLocal 收到服务器之间的消息
func (*IM) SendToAllUser ¶
SendToAllUser 给全体用户发消息
func (*IM) SendToLocalAppId ¶
SendToLocalAppId 给本地 指定的客户端appid 送消息到, 除了userId
func (*IM) SendToLocalUser ¶
SendToLocalUser 给本机指定用户发送消息
func (*IM) SendToRemote ¶
SendToRemote 发送到远端
func (*IM) SendToRemoteAppId ¶
func (*IM) SendToRemoteUser ¶
func (*IM) SendToUser ¶
SendToUser 给指定在线用户发送消息
func (*IM) SyncToRemoteOnly ¶
SyncToRemoteOnly 仅仅只同步到远端
func (*IM) WithUserMgr ¶
type MemberFunc ¶
type Online ¶
type Online struct { AppId string `json:"appId"` UserId uint64 `json:"userId"` Plat int32 `json:"plat"` // 用户所在的服务器ip Host string `json:"host,omitempty"` // 用户所在的服务器端口 Port int `json:"port,omitempty"` // 客户端Ip ClientIp string `json:"clientIp,omitempty"` // 客户端端口 ClientPort string `json:"clientPort,omitempty"` // 用户上次登录时间 LoginTime int64 `json:"loginTime,omitempty"` // 用户上次心跳时间 HeartbeatTime int64 `json:"heartbeatTime,omitempty"` // 用户退出登录的时间 LogOutTime int64 `json:"logOutTime,omitempty"` // 是否离线 IsOffline bool `json:"isOffline"` }
type ReqHead ¶
type ReqHead struct { Source string `json:"source"` Version string `json:"version"` SeqId string `json:"seqId"` ReqAt int64 `json:"timeAt"` //客户端或服务器的时间 RecvAt int64 `json:"-"` //服务器收到的时间 TimeOut time.Duration `json:"-"` }
func (*ReqHead) GetTimeOut ¶
GetTimeOut request.HeadV2 interface
func (*ReqHead) GetVersion ¶
GetVersion request.Head interface
func (*ReqHead) SetTimeOut ¶
SetTimeOut request.HeadV2 interface
type ResHead ¶
type ResHead struct { result.Result Version string `json:"version"` //版本,请求者版本 Source string `json:"source,omitempty"` //请求源,可以请求者填写 SeqId string `json:"seqId,omitempty"` //请求序号,由请求者定义,服务器原路返回 TimeAt int64 `json:"timeAt,omitempty"` //服务收到请求的时间(ms) DiffAt int64 `json:"diffAt,omitempty"` //客户端与服务端时间差值(ms) SpendAt int64 `json:"spendAt,omitempty"` //从服务收到请求到响应完成,所花的时长(ms) ServerAt int64 `json:"serverAt,omitempty"` //服务器时间,豪秒,用于检验对时(ms) LogId string `json:"logId,omitempty"` }
type Session ¶
type Session struct { AppId string `form:"appId" binding:"required" json:"appId"` Plat int32 `form:"plat" binding:"-" json:"plat"` UserId uint64 `form:"userId" binding:"required" json:"userId"` ClientId uint64 `form:"clientId" binding:"-" json:"clientId"` }
func PBSessionToSession ¶
func PBUserToSession ¶
type Status ¶
type User ¶
type User interface { SetSupportApp(apps []App) NextSupportApp(fn func(app App) bool) ExistSupportApp(app App) bool HeartbeatTimeout() int64 GetUserKey(session *Session) string GetUserOnline(session *Session) (*Online, error) // SetUserOnline 写到redis中 SetUserOnline(session *Session, online *Online) error RemoveUserOnline(session *Session) error IsUserOnline(session *Session) (bool, error) GetAllOnline(cc *ArrayCopy, session *Session) error //UserStatusChanged 通知基它服务有变化 UserStatusChanged(status *Status, option *Option) }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.