ApiWS

package
v0.0.0-...-bbbc4ea Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMessageTypeId    = errors.New("not have 'type_id' field in the json string message")
	ErrUnSupportMsgTypeId = errors.New("the value of 'type_id' is not support")
)
View Source
var (
	ErrSendMessageOk        = errors.New("the message send ok")
	ErrUserDisguise         = errors.New("the sender id is not identical, don't disguise other to send message")
	ErrUnSupportContentType = errors.New("the message content type is not support")
	ErrTextContentEmpty     = errors.New("the text content is empty")
	ErrPreviewPicEmpty      = errors.New("the media preview picture url is empty")
	ErrResourceURLEmpty     = errors.New("the media resource url is empty")
	ErrReceiverRefuseRecv   = errors.New("the receiver refuse receive the message")
	ErrFriendshipNotExisted = errors.New("your are not friend still")
	ErrReceiverNotExisted   = errors.New("the receiver is not existed")
)
View Source
var (
	ErrTitleEmpty    = errors.New("the title can not be empty")
	ErrAbstractEmpty = errors.New("the abstract can not be empty")
)
View Source
var (
	ErrNotJoinedTheGroupChat = errors.New("you are not the member of the group chat")
	ErrGroupChatFindFail     = errors.New("find the target group chat fail, may not existed")
)
View Source
var (
	ErrSubscriptionFindFail = errors.New("find the target subscription fail, maybe not existed")
	ErrNotSubsManager       = errors.New("you are not the subscription's manager")
)
View Source
var (
	ErrDeliveryTime = errors.New("invalid delivery time")
)
View Source
var UpGrader = &websocket.Upgrader{
	CheckOrigin: func(r *http.Request) bool { return true }}

WebSocket upgrade worker

Functions

func BeginChat

func BeginChat(w http.ResponseWriter, r *http.Request)

Handle WebSocket upgrade request. Before upgrading, check token by send it to UserCenter through gRPC call. Then trying to get the user's connect node from UserNodesPool. if have not, new one and add into the UserNodesPool. Create a new connector for this connection and add the new connector into theNode's conns. Then start the send and receive data loop goroutine for this connector, and start the connector status watching loop goroutine.

func GetRawJsonMessageTypeId

func GetRawJsonMessageTypeId(message []byte) (int, error)

Get the value of 'type_id' from the json string message

func MessageDispatch

func MessageDispatch(senderId int64, data []byte)

Dispatch the chat message from ordinary user. If the `TypeId` of message is got error or not supported, it will send a error information to user client that sent the message.

func RecvDataLoop

func RecvDataLoop(userId int64, connector *MSGNode.Connector, clientAddr string)

Keep trying to receive message from the client by connector. When the connector was closed, stop the goroutine.

func SaveDelayMessageLoop

func SaveDelayMessageLoop()

Record the message for offline user. Save the message as delay message into database, when the user online again, send these message to the client. but if some thing error happened when save the delay message, it would only output the error log, would not block the program.

func SaveGroupChatHistory

func SaveGroupChatHistory(groupId int64, message []byte)

Record the group chat history

func SaveSubscriptionHistory

func SaveSubscriptionHistory(subsId int64, message []byte)

Record the subscription message history

func SaveUserChatHistory

func SaveUserChatHistory(senderId, receiverId int64, message []byte)

Record the normal user chat history

func SendDateLoop

func SendDateLoop(userId int64, connector *MSGNode.Connector, clientAddr string)

Keep send the data to client by connector, when have a new message for it. When the connector was closed, stop the goroutine.

func SendErrorMessage

func SendErrorMessage(receiverId int64, code int, err error, rawMessage []byte)

Send error message to target user client, if the user is not online, the message will be save as delay message.

func SendGroupChatMessage

func SendGroupChatMessage(senderId int64, message []byte)

Send the message to a group chat. In fact, is send the message to every other user whom joined the group chat.

func SendSubscriptionMessage

func SendSubscriptionMessage(senderId int64, message []byte)

The manager send a message to every fans of the subscription.

func SendUserChatMessage

func SendUserChatMessage(senderId int64, message []byte)

Send normal message to target user client, if the user is not online, it will record the message as a WaitSendMessage into database

func StartMessageWebSocketServer

func StartMessageWebSocketServer()

Types

This section is empty.

Jump to

Keyboard shortcuts

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