Documentation ¶
Index ¶
- Variables
- func BeginChat(w http.ResponseWriter, r *http.Request)
- func GetRawJsonMessageTypeId(message []byte) (int, error)
- func MessageDispatch(senderId int64, data []byte)
- func RecvDataLoop(userId int64, connector *MSGNode.Connector, clientAddr string)
- func SaveDelayMessageLoop()
- func SaveGroupChatHistory(groupId int64, message []byte)
- func SaveSubscriptionHistory(subsId int64, message []byte)
- func SaveUserChatHistory(senderId, receiverId int64, message []byte)
- func SendDateLoop(userId int64, connector *MSGNode.Connector, clientAddr string)
- func SendErrorMessage(receiverId int64, code int, err error, rawMessage []byte)
- func SendGroupChatMessage(senderId int64, message []byte)
- func SendSubscriptionMessage(senderId int64, message []byte)
- func SendUserChatMessage(senderId int64, message []byte)
- func StartMessageWebSocketServer()
Constants ¶
This section is empty.
Variables ¶
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") )
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") )
var ( ErrTitleEmpty = errors.New("the title can not be empty") ErrAbstractEmpty = errors.New("the abstract can not be empty") )
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") )
var ( ErrSubscriptionFindFail = errors.New("find the target subscription fail, maybe not existed") ErrNotSubsManager = errors.New("you are not the subscription's manager") )
var (
ErrDeliveryTime = errors.New("invalid delivery time")
)
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 ¶
Get the value of 'type_id' from the json string message
func MessageDispatch ¶
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 ¶
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 ¶
Record the group chat history
func SaveSubscriptionHistory ¶
Record the subscription message history
func SaveUserChatHistory ¶
Record the normal user chat history
func SendDateLoop ¶
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 ¶
Send error message to target user client, if the user is not online, the message will be save as delay message.
func SendGroupChatMessage ¶
Send the message to a group chat. In fact, is send the message to every other user whom joined the group chat.
func SendSubscriptionMessage ¶
The manager send a message to every fans of the subscription.
func SendUserChatMessage ¶
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.