llconn

package
v0.0.0-...-d436db8 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChatroomServiceID = 10000006
)
View Source
const (
	GroupServiceID = 10000001
)

Variables

View Source
var (
	DefaultMessageMeter = &MessageMeter{wrapMessage: true}
)

Functions

func GenRandString

func GenRandString(length int64) string

func Sn

func Sn() uint64

Types

type AccountInfo

type AccountInfo struct {
	AccountType string // Account Type
	ID          string // User ID
	PWD         string // Corresponding password
	Sig         string // Signature to obtain token
	DID         string // Device ID
	Plf         string // Platform
	NE          bool   // Not Encrypt
}

func (*AccountInfo) IsValid

func (this *AccountInfo) IsValid() bool

type ChatroomMessage

type ChatroomMessage struct {
	Sn                  uint64
	ID                  uint32
	MaxID               uint32
	RoomID              string
	Sender              string
	MsgType             int32
	Content             []byte
	RegisteredMemberCnt int32 // 注册用户人数
	TotalMemberCnt      int32 // 总人数
	Valid               bool  // 是否有效
}

聊天室消息

type ChatroomService

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

func NewChatroom

func NewChatroom() *ChatroomService

func (*ChatroomService) GetMessage

func (this *ChatroomService) GetMessage(roomid string, ids []int64) bool

get chatroom message

func (*ChatroomService) HandleGetMessage

func (this *ChatroomService) HandleGetMessage(msg *UserMessage) bool

func (*ChatroomService) HandleServiceMessage

func (this *ChatroomService) HandleServiceMessage(data []byte, sn uint64, source int) bool

func (*ChatroomService) Join

func (this *ChatroomService) Join(roomid string) uint64

join in a chatroom return positive sequence number to match coressponding async response, returning zero means failure

func (*ChatroomService) Logout

func (this *ChatroomService) Logout()

func (*ChatroomService) Query

func (this *ChatroomService) Query(roomid string, memberIndex, count int32) uint64

query information of a specific room memberIndex and count are used to specify the range of members whose information should be retrieved return positive sequence number to match coressponding async response, returning zero means failure

func (*ChatroomService) Quit

func (this *ChatroomService) Quit(roomid string) uint64

quit from a room return positive sequence number to match coressponding async response, returning zero means failure

func (*ChatroomService) Register

func (this *ChatroomService) Register(conn *LongLiveConn) (int, error)

type ClientConf

type ClientConf struct {
	ConnType           string // Connection Type: "tcp", "websocket" or "wss"
	Addr               string // Server address
	AppID              int    // ApplicationID
	CV                 int    // ClientVersion
	PV                 int    // ProtocolVersion
	DK                 string // Default Key
	HeartItvl          int    // Heartbeat interval (unit second)
	SendHeartBeat      int    // Send heart beat or not. if 0, not send, else send.
	Autologin          int    // auto login after init login
	CheckLoginWhenJoin int    // check login when join chatroom
}

func (*ClientConf) IsValid

func (this *ClientConf) IsValid() bool

type Dumper

type Dumper interface {
	// contains filtered or unexported methods
}

type GroupService

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

func NewGroup

func NewGroup() *GroupService

func (*GroupService) GetMessage

func (this *GroupService) GetMessage(roomid string, ids []int64) bool

get chatroom message

func (*GroupService) GetMsg

func (gs *GroupService) GetMsg(groupid string, startid uint64, offset int32)

func (*GroupService) GetMsgM

func (gs *GroupService) GetMsgM(ids []int64)

func (*GroupService) HandleGetMessage

func (this *GroupService) HandleGetMessage(msg *UserMessage) bool

func (*GroupService) HandleServiceMessage

func (gs *GroupService) HandleServiceMessage(data []byte, sn uint64, source int) bool

func (*GroupService) Register

func (gs *GroupService) Register(conn *LongLiveConn) (int, error)

func (*GroupService) Sync

func (gs *GroupService) Sync(groups []string)

type JoinResp

type JoinResp struct {
	Sn             uint64
	Result         int32
	Reason         []byte
	PartnerData    []byte
	RoomID         string
	Members        []string
	TotalMemberCnt int32
}

加入聊天室的响应

type LongLiveConn

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

func New

func New(clientConf ClientConf, accountConf AccountInfo) (*LongLiveConn, *error)

func (*LongLiveConn) GetMultiInfo

func (this *LongLiveConn) GetMultiInfo(infoType string, ids []int64, sparameter []byte) bool

GetMultiInfo, so far it is used to get chatroom message

func (*LongLiveConn) Register

func (this *LongLiveConn) Register(service ServiceHandler) bool

Register a service on long live connection Corresponding data pakcet would be delivery to the service if matches TODO concurrent access unsafe

func (*LongLiveConn) SendServiceMessage

func (this *LongLiveConn) SendServiceMessage(serviceID int, data []byte) uint64

Send Service Message

func (*LongLiveConn) SetDumpStream

func (this *LongLiveConn) SetDumpStream(value bool)

enable the switch to print data stream

func (*LongLiveConn) Start

func (this *LongLiveConn) Start(ch chan string)

start running

type MemberChangedNotifcation

type MemberChangedNotifcation struct {
	RoomID         string
	Action         string
	Sn             uint64
	TotalMemberCnt int32
	Members        []string
}

成员变化通知

type MessageMeter

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

func (*MessageMeter) Check

func (mm *MessageMeter) Check(content string) bool

func (*MessageMeter) EnableWrapper

func (mm *MessageMeter) EnableWrapper(enable bool)

func (*MessageMeter) WrapMessage

func (mm *MessageMeter) WrapMessage(content string) string

type MessageSender

type MessageSender struct {
	PeerUrl      string
	ChatroomUrl  string
	RobotJoinUrl string
	RobotQuitUrl string
	PublicUrl    string
	IMUrl        string
}

invoke HTTP interface to send peer|public|im|chatroom messages

func NewMessageSender

func NewMessageSender(center string) (*MessageSender, error)

func (*MessageSender) SendChatroomMessage

func (this *MessageSender) SendChatroomMessage(roomid, sender string, content []byte, expiration, msgtype, priority, appid int) (string, error)

func (*MessageSender) SendImMessage

func (this *MessageSender) SendImMessage(receivers string, content []byte, expiration, priority, appid int) (string, error)

func (*MessageSender) SendPeerMessage

func (this *MessageSender) SendPeerMessage(receivers string, content []byte, expiration, priority, appid int) (string, error)

访问为POST方式

post数据内容:&m=111&b=Jm1zZz0xMjM0NV90ZXN0JnRyYWNlaWQ9MTIzNDU2Nzg5MCZyZWNlaXZlcnM9amlkXzEwMDAmc2VuZGVyPWppZF8yMDAw 示例数据中b的内容为&msg=12345_test&traceid=1234567890&receivers=jid_1000&sender=jid_2000的base64编码 请注意traceid的范围是无符号32位整数的范围 m的值是b的未编码内容加上"wpms"后计算出来的md5,目前没有打开校验,可以随便填

返回值为json格式字符串 {"code":0,"reason":"ok","ios_offline_users":[],"msgids":[{"owner":"jid_1000","id":113,"box":"inbox"},{"owner":"jid_2000","id":24,"box":"outbox"}]}

func (*MessageSender) SendPublicMessage

func (this *MessageSender) SendPublicMessage(content []byte, appid int) (string, error)

func (*MessageSender) SendRobotJoinMessage

func (this *MessageSender) SendRobotJoinMessage(roomid, userid string) (string, error)

func (*MessageSender) SendRobotQuitMessage

func (this *MessageSender) SendRobotQuitMessage(roomid, userid string) (string, error)

type QueryResp

type QueryResp struct {
	RoomID         string
	Sn             uint64
	Result         int32
	TotalMemberCnt int32
	Members        []string
}

聊天室详情

type QuitResp

type QuitResp struct {
	RoomID string
	Sn     uint64
	Result int32
}

退出聊天室响应

type ServiceHandler

type ServiceHandler interface {
	HandleServiceMessage(data []byte, sn uint64, source int) bool
	HandleGetMessage(msg *UserMessage) bool
	Register(*LongLiveConn) (int, error)
}

type Stream

type Stream interface {
	Close()
	Read([]byte) (int, error)
	Write([]byte) (int, error)
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

type TcpStream

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

func NewTcpStream

func NewTcpStream(addr string, timeout time.Duration) (*TcpStream, error)

func (*TcpStream) Close

func (this *TcpStream) Close()

func (*TcpStream) Read

func (this *TcpStream) Read(data []byte) (int, error)

func (*TcpStream) SetReadDeadline

func (this *TcpStream) SetReadDeadline(t time.Time) error

func (*TcpStream) SetWriteDeadline

func (this *TcpStream) SetWriteDeadline(t time.Time) error

func (*TcpStream) Write

func (this *TcpStream) Write(data []byte) (int, error)

type TestMessage

type TestMessage struct {
	SentTime int64 // UnixNano
	Content  string
}

type UserMessage

type UserMessage struct {
	ID       uint64
	Content  []byte
	InfoType string
	MsgType  uint32
	Sn       uint64
	Valid    uint32
}

type WebSocketStream

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

func NewWebSocketSecurityStream

func NewWebSocketSecurityStream(addr string, timeout time.Duration) (*WebSocketStream, error)

func NewWebSocketStream

func NewWebSocketStream(addr string, timeout time.Duration) (*WebSocketStream, error)

func (*WebSocketStream) Close

func (ws *WebSocketStream) Close()

func (*WebSocketStream) Read

func (ws *WebSocketStream) Read(data []byte) (n int, err error)

func (*WebSocketStream) SetReadDeadline

func (ws *WebSocketStream) SetReadDeadline(t time.Time) error

func (*WebSocketStream) SetWriteDeadline

func (ws *WebSocketStream) SetWriteDeadline(t time.Time) error

func (*WebSocketStream) Write

func (ws *WebSocketStream) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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