server

package
v0.0.0-...-e3a0aff Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChatHandler

func ChatHandler(hub *Hub, dbase *gorm.DB, w http.ResponseWriter, r *http.Request)

ChatHandler handles websocket requests from the peer.

Types

type Chat

type Chat struct {
	// broadcast|targeted
	Flag string `json:"Flag"`

	// the receiving party on a targeted Message
	RecipientID uint `json:"Recipient"`

	ConversationID uint `json:"ConversationID"`

	Message string `json:"Message"`
}

type Client

type Client struct {
	ClientID uint

	Name string

	Hub *Hub

	// Websockets connection
	Conn *ws.Conn

	// Buffered channel for the outgoing messages
	Send chan []byte

	SendJSON chan interface{}

	// Notification channel
	Notify chan interface{}
}

Client stands between the hub and the ws connections

type ConnectedClient

type ConnectedClient struct {
	gorm.Model

	UserID uint `gorm:"primaryKey"`

	Client *Client `gorm:"embedded"`

	LastSeen time.Time
}

ConnectedClient holds the connection info of a specific client

type Hub

type Hub struct {
	Connections map[uint]*ConnectedClient

	// Incoming messages from a client
	// to all connections subscribers of a channel
	Broadcast chan []byte

	// Incoming messages for a specific client
	Targeted chan *Message

	// returns connected users
	GetUsers chan *Client

	// Register client's requests
	Register chan *ConnectedClient

	// connects two peers
	Pair chan *db.PairedUsers

	// Unregister requests from the connections
	Unregister chan *ConnectedClient

	Notify chan Notification
}

Hub maintains active connections and broadcast messages to connections

func NewHub

func NewHub() *Hub

func (*Hub) Run

func (h *Hub) Run(dbase *gorm.DB)

type Message

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

type Notification

type Notification struct {
	Connected bool `json:"Connected"`
	Client    *Client
}

Jump to

Keyboard shortcuts

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