chat

package
v0.0.0-...-0064678 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConnManager Stores all Conn types by their uuid.
	ConnManager = struct {
		sync.Mutex
		Conns map[string]*Conn
	}{
		Conns: make(map[string]*Conn),
	}
)
View Source
var DialogManager = struct {
	sync.Mutex
	Rooms map[string]*Dialog
}{
	Rooms: make(map[string]*Dialog, 0),
}

Stores all Dialog types by their name.

Functions

func ConstructMessage

func ConstructMessage(room, event, src, dst string, body string) *dto.Message

Constructs and returns a new Message type.

func HandleData

func HandleData(c *Conn, msg *dto.Message)

HandleData Handles incoming, error free messages.

func SocketHandler

func SocketHandler(ctx *echo.Context, log *logrus.Entry, registry *service.Registry, userID string) error

SocketHandler Calls NewConnection, starts the returned Conn's writer, joins the root room, and finally starts the Conn's reader.

Types

type Conn

type Conn struct {
	sync.Mutex
	Socket  *websocket.Conn
	ID      string
	Send    chan dto.Message
	Dialogs map[string]string
	// contains filtered or unexported fields
}

The Conn type represents a single client.

func NewConnection

func NewConnection(ctx *echo.Context, log *logrus.Entry, registry *service.Registry, userID string) (*Conn, error)

NewConnection Upgrades an HTTP connection and creates a new Conn type.

func (*Conn) Emit

func (c *Conn) Emit(msg *dto.Message)

Emit Broadcasts a Message to all members of a Dialog.

func (*Conn) IsDialogExist

func (c *Conn) IsDialogExist(name string) bool

IsDialogExist CheckDialog ...

func (*Conn) Join

func (c *Conn) Join(name string)

Join Adds the Conn to a Dialog. If the Dialog does not exist, it is created.

func (*Conn) Leave

func (c *Conn) Leave(name string)

Leave Removes the Conn from a Dialog.

func (*Conn) LeftChat

func (c *Conn) LeftChat(msg *dto.Message)

LeftChat ...

func (*Conn) ReadMessage

func (c *Conn) ReadMessage(msg *dto.Message)

ReadMessage ...

func (*Conn) SendFile

func (c *Conn) SendFile(msg *dto.Message)

func (*Conn) SendMessage

func (c *Conn) SendMessage(msg *dto.Message)

SendMessage ...

func (*Conn) SendSticker

func (c *Conn) SendSticker(msg *dto.Message)

SendMessage ...

type Dialog

type Dialog struct {
	sync.Mutex
	Name    string
	Members map[string]string

	Send chan *DialogMessage
	// contains filtered or unexported fields
}

The Dialog type represents a communication channel.

func NewRoom

func NewRoom(name string) *Dialog

Creates a new Dialog type and starts it.

func (*Dialog) Emit

func (r *Dialog) Emit(c *Conn, msg *dto.Message)

Broadcasts data to all members of the Dialog.

func (*Dialog) Join

func (r *Dialog) Join(c *Conn)

Adds a Conn to the Dialog.

func (*Dialog) Leave

func (r *Dialog) Leave(c *Conn)

Removes a Conn from the Dialog.

func (*Dialog) Start

func (r *Dialog) Start()

Starts the Dialog.

func (*Dialog) Stop

func (r *Dialog) Stop()

Stops the Dialog.

type DialogMessage

type DialogMessage struct {
	Sender *Conn
	Data   *dto.Message
}

Message protocol used only with a room's Send channel.

Jump to

Keyboard shortcuts

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