websockets

package
v0.0.0-...-cdd45d8 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageAuthentication = iota
	MessageReceive
	MessageSent
)

Variables

This section is empty.

Functions

func Websockets

func Websockets(hub *Hub, db *gorm.DB) func(w http.ResponseWriter, r *http.Request)

Types

type AuthenticationMessage

type AuthenticationMessage struct {
	Type  int    `json:"type"`
	Token string `json:"token"`
}

type BaseMessage

type BaseMessage struct {
	Type int `json:"type"`
}

type Client

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

Client is a middleman between websocket connection and the hub

type Hub

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

Maintains the set of active clients and broadcasts messages to the clients

func NewHub

func NewHub() *Hub

Hub "constructor"

func (*Hub) PushMessage

func (h *Hub) PushMessage(receiver string, message database.Message, chat string)

Send message over websocket connection client

func (*Hub) Run

func (h *Hub) Run()

Main websocket runner

type ReceiveMessage

type ReceiveMessage struct {
	Type        int    `json:"type"`
	Message     string `json:"message"`
	Chat        string `json:"chat"`
	Sender      string `json:"sender"`
	ContentType int    `json:"content-type"`
}

type SentMessage

type SentMessage struct {
	Type        int    `json:"type"`
	Chat        string `json:"chat"`
	Message     string `json:"message"`
	Filename    string `json:"filename"`
	ContentType string `json:"content-type"`
}

type UserMapping

type UserMapping struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Create mapping of users to client connections

func (*UserMapping) Add

func (um *UserMapping) Add(id string, client *Client)

Map client connection to ip to client id

func (*UserMapping) Delete

func (um *UserMapping) Delete(id string, ip string)

func (*UserMapping) Get

func (um *UserMapping) Get(id string) []*Client

Retrieve all connected clients by user id

Jump to

Keyboard shortcuts

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