chathub

package
v0.0.0-...-76b470b Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AuthMessage message
	AuthMessage MessageType = "authMessage"

	// AuthFail message
	AuthFail MessageType = "authFail"

	// UserJoined message
	UserJoined MessageType = "userJoined"

	// PrivateMessage message
	PrivateMessage MessageType = "privateMessage"

	//Broadcast message
	Broadcast MessageType = "broadcast"

	//UsersStatus message
	UsersStatus MessageType = "usersStatus"

	// WriteWait Time allowed to write a message to the peer.
	WriteWait = 10 * time.Second

	// PongWait Time allowed to read the next pong message from the peer.
	PongWait = 60 * time.Second

	// PongPeriod should less than PongWait
	PingPeriod = (PongWait * 9) / 10

	// Maximum message size allowed from peer.
	MaxMessageSize = 1024
)
View Source
const (
	// UpdateStatusWait to update users status
	UpdateStatusWait = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*websocket.Conn
	ID       string
	Username string
	MsgChan  chan []byte
	Manager  *Manager
	Room     map[string]bool
	IsOnline bool
	sync.RWMutex
}

Client model

func (*Client) Consume

func (c *Client) Consume()

Consume function will read incoming message from client

func (*Client) Publish

func (c *Client) Publish()

Publish function will write message to connected client

type Clients

type Clients map[string]*Client

Clients type alias of map Client

type Manager

type Manager struct {
	AuthKey         string
	Clients         Clients
	JoinedClient    chan *Client
	ExitedClient    chan *Client
	AuthSuccess     chan *Client
	IncomingMessage chan *Message
	Upgrader        websocket.Upgrader
	JwtService      jwt.JwtService
	sync.RWMutex
}

Manager will manage client and chat

func NewManager

func NewManager(authKey string, jwtService jwt.JwtService) *Manager

NewManager function

func (*Manager) Handle

func (manager *Manager) Handle()

Handle function will handle incoming client

type Message

type Message struct {
	MessageType MessageType   `json:"messageType,omitempty"`
	AuthKey     string        `json:"authKey,omitempty"`
	Token       string        `json:"token,omitempty"`
	Username    string        `json:"username,omitempty"`
	From        string        `json:"from,omitempty"`
	To          string        `json:"to,omitempty"`
	Content     string        `json:"content,omitempty"`
	Date        time.Time     `json:"date,omitempty"`
	OnlineUsers []*OnlineUser `json:"onlineUsers,omitempty"`
}

Message structure

type MessageType

type MessageType string

MessageType type of message

type OnlineUser

type OnlineUser struct {
	Username string `json:"username,omitempty"`
	Status   bool   `json:"status"`
}

OnlineUser represent online user

Jump to

Keyboard shortcuts

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