Documentation ¶
Index ¶
- Constants
- Variables
- func ContentQuote(d interface{}) string
- func IsClientEvent(ev int32) bool
- func IsEventResp(ev int32) bool
- func IsExServerEvent(ev int32) bool
- func IsMQEvent(ev int32) bool
- func IsServerEvent(ev int32) bool
- func IsUserStatusChanged(ev int32) bool
- func NewContext(ctx context.Context, traceId string) context.Context
- func NewWithTraceId(traceId string) context.Context
- func Register(key int32, value DisposeFunc)
- func SdkVersion() string
- func SessionToPBSession(session *Session, token string) *pb.Session
- func SessionToPBUser(session *Session) *pb.User
- func StringEvent(e int32) string
- func ToPBEvent(ev *Event) *pb.Event
- func WithHandshakeTimeout(t time.Duration) option.Option
- type App
- type Client
- func (c *Client) Close(ctx context.Context, reason string) error
- func (c *Client) GetAccount() string
- func (c *Client) GetAddr() string
- func (c *Client) GetAppId() string
- func (c *Client) GetClientId() uint64
- func (c *Client) GetClientType() int32
- func (c *Client) GetConnectId() uint64
- func (c *Client) GetConnectTime() int64
- func (c *Client) GetHeartTime() int64
- func (c *Client) GetIndex() int64
- func (c *Client) GetLoginTime() int64
- func (c *Client) GetOrgId() int32
- func (c *Client) GetPlatform() int32
- func (c *Client) GetRemoteAddr() string
- func (c *Client) GetSession() Session
- func (c *Client) GetSource() string
- func (c *Client) GetSyncTime() int64
- func (c *Client) GetTenantId() int32
- func (c *Client) GetToken() string
- func (c *Client) GetUserId() uint64
- func (c *Client) IsClosed() bool
- func (c *Client) IsLogin() bool
- func (c *Client) Login(ctx context.Context) error
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Run()
- func (c *Client) Send(ctx context.Context, eventType EventType, body []byte) error
- func (c *Client) SendMQ(ctx context.Context, topic string, content string) error
- func (c *Client) SendTo(msg []byte) error
- func (c *Client) SendToQueue(ctx context.Context, msg []byte) error
- func (c *Client) String() string
- func (c *Client) Subscribe(ctx context.Context, topic ...string) error
- func (c *Client) UnSubscribe(ctx context.Context, topic ...string) error
- func (c *Client) WithDisposeFunc(fn DisposeFunc) *Client
- type ClientCmd
- type ClientConn
- type Config
- type ConnectInfo
- type Copy
- type DisposeFunc
- type Event
- type EventReq
- type EventRes
- type EventType
- type Hub
- func (hub *Hub) AddClients(client *Client)
- func (hub *Hub) AddUsers(ctx context.Context, key string, client *Client, reason string) int
- func (hub *Hub) Alarm(ctx context.Context, code int32, level int32, title, detail string, err error)
- func (hub *Hub) CheckAllUserOnline(session *Session) bool
- func (hub *Hub) CheckUserOnline(session *Session) bool
- func (hub *Hub) ClientQuery(f func(client *Client) (result bool))
- func (hub *Hub) ClientSearch(q Query) []*Client
- func (hub *Hub) DelClient(client *Client)
- func (hub *Hub) DelUser(ctx context.Context, client *Client) bool
- func (hub *Hub) DoClientCmd(ctx context.Context, reg *ClientCmd)
- func (hub *Hub) DoClientCmdSync(ctx context.Context, cliCmd *ClientCmd)
- func (hub *Hub) GetAllUserList(session *Session) *UserList
- func (hub *Hub) GetAppList() []string
- func (hub *Hub) GetClients() []*Client
- func (hub *Hub) GetLocalUserList(session *Session) *UserList
- func (hub *Hub) GetOnline(session *Session, opt ...option.Option) *OnLineList
- func (hub *Hub) GetServerHost() string
- func (hub *Hub) GetServerPort() int
- func (hub *Hub) GetServers() []builder.Address
- func (hub *Hub) GetUserClient(session *Session) *Client
- func (hub *Hub) Handler(ctx context.Context, info ConnectInfo, w http.ResponseWriter, r *http.Request) error
- func (hub *Hub) InClient(client *Client) (ok bool)
- func (hub *Hub) Init(cfg Config)
- func (hub *Hub) IsLocalAddress(server string) bool
- func (hub *Hub) OnClose(ctx context.Context)
- func (hub *Hub) OnLogin(ctx context.Context, log LogInfo)
- func (hub *Hub) OnLogout(ctx context.Context, log LogInfo)
- func (hub *Hub) RateLimit(session Session, version string) bool
- func (hub *Hub) Receive(ctx context.Context, from *Session, to *Session, ev *Event) (err error)
- func (hub *Hub) ReceiveAll(ctx context.Context, from *Session, to *Session, ev *Event) (err error)
- func (hub *Hub) SendChat(ctx context.Context, from *Session, ev *Event, option chat.Option, ...) error
- func (hub *Hub) SendToAllUser(ctx context.Context, from *Session, to *Session, ev *Event, data interface{})
- func (hub *Hub) SendToLocalAppId(ctx context.Context, from *Session, to *Session, ev *Event, data interface{})
- func (hub *Hub) SendToLocalUser(ctx context.Context, from *Session, to *Session, ev *Event) (error, bool)
- func (hub *Hub) SendToRemote(ctx context.Context, from *Session, to *Session, ev *Event)
- func (hub *Hub) SendToRemoteAppId(ctx context.Context, addr string, from *Session, to *Session, ev *Event)
- func (hub *Hub) SendToRemoteUser(ctx context.Context, from *Session, to *Session, ev *Event) error
- func (hub *Hub) SendToUser(ctx context.Context, from *Session, to *Session, ev *Event) error
- func (hub *Hub) Source() string
- func (hub *Hub) StatusChanged(ctx context.Context, us Status)
- func (hub *Hub) SyncToRemoteOnly(ctx context.Context, from *Session, to *Session, ev *Event)
- func (hub *Hub) UnInit()
- type IAmMemberFunc
- type LogInfo
- type MemberFunc
- type MessageMQ
- type Mq
- type OnLineList
- type Online
- func (u *Online) Heartbeat(currentTime int64)
- func (u *Online) IsLocal(localIp string, localPort int) bool
- func (u *Online) IsOnline(heartCheck func(heartbeat int64) bool) bool
- func (u *Online) LogIn(currentTime int64)
- func (u *Online) LogOut(currentTime int64)
- func (u *Online) String() string
- func (u *Online) ToSession() Session
- type Option
- func WithChatGroupOption(group chat.Group) Option
- func WithChatOption(chat chat.Chat) Option
- func WithDiscoveryClientOption(client discoveryservice.Client) Option
- func WithRpcClientOption(rpc rpc.Client) Option
- func WithUseMQOption() Option
- func WithUserMgrOption(user User) Option
- func WithWorkerNumOption(work int) Option
- type Query
- type QueryFunc
- 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
- func (s *Session) Equal(c *Session) bool
- func (s *Session) EqualAccount(c *Session) bool
- func (s *Session) EqualAppId(session *Session) bool
- func (s *Session) EqualPlat(session *Session) bool
- func (s *Session) EqualUserId(c *Session) bool
- func (s *Session) IgnoreBit(f int32) bool
- func (s *Session) IsValid() bool
- func (s *Session) String() string
- type Status
- type User
- type UserList
Constants ¶
View Source
const ( CmdRegister = 1 CmdUnRegister = 2 CmdClose = 3 CmdKick = 4 )
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) // ETMq 简单的mq ETMq = EventType(206) ETMqRsp = EventType(207) // ETClientEnd 客户端结束 ETClientEnd = EventType(4999) // ETServerBegin 服务之间 ETServerBegin = EventType(5000) ETServerEnd = EventType(10000) // ETExServerBegin 外部服务 ETExServerBegin = EventType(20000) ETExServerEnd = EventType(30000) )
View Source
const ( SubscribeMQ = iota UnSubscribeMQ SendMQ )
View Source
const ( StatusOffline = 1 StatusOnline = 2 StatusHeartbeat = 3 )
View Source
const EnableUserType = 1000
View Source
const HandshakeTimeoutType = 10000
View Source
const (
IgnoreStatusBroadcast = 1
)
View Source
const OfflineType = 1001
View Source
const OnlineType = 1002
View Source
const UserHeartbeatTimeout = 180
UserHeartbeatTimeout 3分钟
Variables ¶
View Source
var (
EmptyByte = []byte("")
)
View Source
var GrcClientNil = result.Error(-102, "not exist remote server")
View Source
var IAmNotMemberErr = errors.New("i am not member")
View Source
var Ignored = result.Error(-103, "ignore the error")
View Source
var NotExistRemoteServer = result.Error(-100, "not exist remote server")
View Source
var OfflineOpt = option.WithOpt(true, "im_offline", OfflineType)
View Source
var OnlineOpt = option.WithOpt(true, "im_offline", OnlineType)
View Source
var StatusDesc = map[int32]string{ StatusOffline: "离开", StatusOnline: "在线", }
View Source
var UserObjNil = result.Error(-101, "not exist remote server")
Functions ¶
func ContentQuote ¶
func ContentQuote(d interface{}) string
func IsClientEvent ¶
func IsEventResp ¶ added in v0.1.27
func IsExServerEvent ¶
func IsServerEvent ¶
func IsUserStatusChanged ¶
func NewContext ¶ added in v0.1.18
func NewWithTraceId ¶ added in v0.1.9
func Register ¶
func Register(key int32, value DisposeFunc)
func SdkVersion ¶ added in v0.2.9
func SdkVersion() string
func SessionToPBUser ¶
func StringEvent ¶ added in v0.1.9
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func BuildClient ¶ added in v0.1.22
func BuildClient(clientConn ClientConn, info ConnectInfo, url string, index, firstTime int64, head http.Header, resp func(resp *http.Response), opts ...option.Option) *Client
BuildClient for client
func NewClient ¶
func NewClient(clientConn ClientConn, conn *websocket.Conn, info ConnectInfo, addr string, index, firstTime int64) *Client
func (*Client) GetAccount ¶ added in v0.3.8
func (*Client) GetClientId ¶ added in v0.3.8
func (*Client) GetClientType ¶ added in v0.3.8
func (*Client) GetConnectId ¶ added in v0.3.8
func (*Client) GetConnectTime ¶ added in v0.3.8
func (*Client) GetHeartTime ¶ added in v0.3.8
func (*Client) GetLoginTime ¶ added in v0.3.8
func (*Client) GetPlatform ¶ added in v0.3.8
func (*Client) GetRemoteAddr ¶ added in v0.3.8
func (*Client) GetSession ¶ added in v0.1.10
func (*Client) GetSyncTime ¶ added in v0.3.8
func (*Client) GetTenantId ¶ added in v0.3.8
func (*Client) UnSubscribe ¶ added in v0.2.11
UnSubscribe send unsubscribe pack
func (*Client) WithDisposeFunc ¶ added in v0.1.22
func (c *Client) WithDisposeFunc(fn DisposeFunc) *Client
type ClientConn ¶ added in v0.2.17
type ClientConn interface { DoClientCmd(ctx context.Context, cliCmd *ClientCmd) DoClientCmdSync(ctx context.Context, cliCmd *ClientCmd) StatusChanged(ctx context.Context, us Status) OnClose(ctx context.Context) OnLogin(ctx context.Context, log LogInfo) OnLogout(ctx context.Context, log LogInfo) Source() string }
type Config ¶
type Config struct { WorkForceReset bool `json:"workForceReset" yaml:"workForceReset"` RegisterClient int `json:"registerClient" yaml:"registerClient"` ServerAddr server.Address `json:"serverAddr" yaml:"serverAddr"` //服务地址 TokenCheckFunc func(ctx context.Context, client *Client, token string) error `json:"-" yaml:"-"` AlarmFunc func(ctx context.Context, code int32, level int32, title, detail string, err error) `json:"-" yaml:"-"` // contains filtered or unexported fields }
type ConnectInfo ¶ added in v0.2.17
type ConnectInfo struct { Session Version string `form:"version" json:"version" yaml:"version" url:"version"` Token string `form:"token" json:"token" yaml:"token" url:"token"` Reason string `form:"reason" json:"reason" yaml:"reason" url:"reason"` RemoteIP string `form:"-" json:"remoteIP" yaml:"-" url:"-"` }
type DisposeFunc ¶
type Event ¶
type Event struct { EvTypeBase int32 `json:"-"` // 事件基数 EventType int32 `json:"eventType"` // 事件类型, EventType ContentType string `json:"contentType"` // Content 格式,json,xml...protobuff, 默认json Content string `json:"content"` // 具体的业务数据 TraceId string `json:"-"` }
func CreateObjEvent ¶ added in v0.2.20
type EventReq ¶
type EventRes ¶
func NewResponse ¶
type Hub ¶ added in v0.2.11
type Hub struct {
// contains filtered or unexported fields
}
func (*Hub) AddClients ¶ added in v0.2.11
func (*Hub) CheckAllUserOnline ¶ added in v0.2.11
func (*Hub) CheckUserOnline ¶ added in v0.2.11
CheckUserOnline 查询用户是否在线
func (*Hub) ClientQuery ¶ added in v0.3.8
func (*Hub) ClientSearch ¶ added in v0.3.8
func (*Hub) DoClientCmd ¶ added in v0.2.11
func (*Hub) DoClientCmdSync ¶ added in v0.2.11
func (*Hub) GetAllUserList ¶ added in v0.2.11
GetAllUserList 查询所有用户
func (*Hub) GetAppList ¶ added in v0.3.5
func (*Hub) GetClients ¶ added in v0.2.11
func (*Hub) GetLocalUserList ¶ added in v0.2.11
GetLocalUserList 本机的用户
func (*Hub) GetOnline ¶ added in v0.2.21
func (hub *Hub) GetOnline(session *Session, opt ...option.Option) *OnLineList
GetOnline 在线或离线用户
func (*Hub) GetServerHost ¶ added in v0.2.11
func (*Hub) GetServerPort ¶ added in v0.2.11
func (*Hub) GetServers ¶ added in v0.2.11
func (*Hub) GetUserClient ¶ added in v0.2.11
func (*Hub) Handler ¶ added in v0.2.11
func (hub *Hub) Handler(ctx context.Context, info ConnectInfo, w http.ResponseWriter, r *http.Request) error
func (*Hub) IsLocalAddress ¶ added in v0.2.11
func (*Hub) ReceiveAll ¶ added in v0.2.11
func (*Hub) SendToAllUser ¶ added in v0.2.11
func (hub *Hub) SendToAllUser(ctx context.Context, from *Session, to *Session, ev *Event, data interface{})
SendToAllUser 给全体用户发消息 data 用户定义的数据结构(内部使用)
func (*Hub) SendToLocalAppId ¶ added in v0.2.11
func (hub *Hub) SendToLocalAppId(ctx context.Context, from *Session, to *Session, ev *Event, data interface{})
SendToLocalAppId 给本地 指定的客户端appid 送消息到, 除了userId data 用户定义的数据结构(内部使用)
func (*Hub) SendToLocalUser ¶ added in v0.2.11
func (hub *Hub) SendToLocalUser(ctx context.Context, from *Session, to *Session, ev *Event) (error, bool)
SendToLocalUser 给本机指定用户发送消息
func (*Hub) SendToRemote ¶ added in v0.2.11
SendToRemote 发送到远端
func (*Hub) SendToRemoteAppId ¶ added in v0.2.11
func (*Hub) SendToRemoteUser ¶ added in v0.2.11
func (*Hub) SendToUser ¶ added in v0.2.11
SendToUser 给指定在线用户发送消息
func (*Hub) StatusChanged ¶ added in v0.2.11
func (*Hub) SyncToRemoteOnly ¶ added in v0.2.11
SyncToRemoteOnly 仅仅只同步到远端
type IAmMemberFunc ¶
IAmMemberFunc 是否是群成员, iAmMember= true 是成员
type MemberFunc ¶
type Mq ¶ added in v0.2.11
type Mq struct {
// contains filtered or unexported fields
}
type OnLineList ¶ added in v0.2.21
type Online ¶
type Online struct { ID string `json:"id"` AppId string `json:"appId"` ClientIp string `json:"clientIp"` // 客户端Ip ClientPort string `json:"clientPort"` // 客户端端口 RemoteIp string `json:"remoteIp"` //用户远程IP Host string `json:"host"` // 用户所在的服务器ip Account string `json:"account"` UserId uint64 `json:"userId"` Port int `json:"port"` // 用户所在的服务器端口 Plat int32 `json:"plat"` LoginTime int64 `json:"loginTime"` // 用户上次登录时间 HeartbeatTime int64 `json:"heartbeatTime"` // 用户上次心跳时间 LogOutTime int64 `json:"logOutTime"` // 用户退出登录的时间 IsOffline bool `json:"isOffline"` // 是否离线 }
type Option ¶
type Option func(hub *Hub)
func WithChatGroupOption ¶ added in v0.2.11
WithChatGroupOption 群管理及群聊
func WithChatOption ¶ added in v0.2.15
WithChatOption 聊天信息保存
func WithDiscoveryClientOption ¶ added in v0.2.15
func WithDiscoveryClientOption(client discoveryservice.Client) Option
WithDiscoveryClientOption 分布式支持
func WithRpcClientOption ¶ added in v0.2.11
WithRpcClientOption 外部服务接用
func WithUserMgrOption ¶ added in v0.2.11
WithUserMgrOption 用户管理
func WithWorkerNumOption ¶ added in v0.2.13
WithWorkerNumOption 配置工作线程
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" yaml:"appId" url:"appId"` Account string `form:"account" json:"account" yaml:"account" url:"account"` UserId uint64 `form:"userId" json:"userId,omitempty" yaml:"userId,omitempty" url:"userId,omitempty"` ClientId uint64 `form:"clientId" json:"clientId,omitempty" yaml:"clientId,omitempty" url:"clientId,omitempty"` //客户端id ClientType int32 `form:"clientType" json:"clientType,omitempty" yaml:"clientType,omitempty" url:"clientType,omitempty"` //客户端类型 Plat int32 `form:"plat" json:"plat" yaml:"plat" url:"plat"` OrgId int32 `form:"orgId" json:"orgId,omitempty" yaml:"orgId,omitempty" url:"orgId,omitempty"` //所属组织 TenantId int32 `form:"tenantId" json:"tenantId,omitempty" yaml:"tenantId,omitempty" url:"tenantId,omitempty"` //租户id Ignore int32 `form:"ignore" json:"ignore,omitempty" yaml:"ignore,omitempty" url:"ignore,omitempty"` }
func PBSessionToSession ¶
func PBUserToSession ¶
func (*Session) EqualAccount ¶ added in v0.2.2
func (*Session) EqualAppId ¶ added in v0.2.2
func (*Session) EqualUserId ¶ added in v0.2.2
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, opt ...option.Option) (*Online, error) // SetUserOnline 写到redis中 SetUserOnline(session *Session, online *Online) error RemoveUserOnline(session *Session) error IsUserOnline(session *Session) (bool, error) GetAllOnline(cc *Copy, session *Session, opt ...option.Option) error //UserStatusChanged 通知基它服务有变化 UserStatusChanged(status *Status, opt ...option.Option) }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.