websock

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Receive

func Receive(ws *websocket.Conn, msg *Message) error

Receive fetches a message from the connection synchronously

NB! This will fail if the received message contains incompatible type and content

func Send

func Send(ws *websocket.Conn, msg *Message) error

Send sends a message to the connection synchronously

NB! This will fail if the given message contains incompatible type and content

Types

type ChatInfoMessage

type ChatInfoMessage struct {
	Name       string
	MyUsername string
	Users      []User
	Messages   []*ChatMessage
}

ChatInfoMessage is the message sent by the server to a client who joined a chat room

type ChatMessage

type ChatMessage struct {
	Sender    string
	Timestamp int64
	Message   []byte
}

ChatMessage is used in ChatInfoMessage, and by the server when notifying a client about a new chat message

type CreateChatRoomMessage

type CreateChatRoomMessage struct {
	Name     string
	Password string
	IsHidden bool
}

CreateChatRoomMessage is the message sent by a client to request creation of a new chat room

type GetChatRoomsResponseMessage

type GetChatRoomsResponseMessage struct {
	TotalConnected int
	Rooms          []Room
}

GetChatRoomsResponseMessage is sent by the server in response to a GetChatRooms request

type JoinChatMessage

type JoinChatMessage struct {
	Name     string
	Password string
}

JoinChatMessage is the message sent by a client to request to join a chat room

type Message

type Message struct {
	Type    MessageType
	Message interface{}
}

Message is the "base" message which is used for all websocket messages Type contains the type of the message (one of the MessageType enums) Message contains the actual content of the message, which can be a string, byte slice, a struct, or nil.

type MessageType

type MessageType int

MessageType enum contains all possible websocket message types

const (
	// Error means that en error occurred
	Error MessageType = iota
	// OK means that the action was successful
	OK

	// RegisterUser is sent when a client wants to register a new user
	RegisterUser
	// LoginUser is sent when a client wants to authenticate as a user
	LoginUser
	// AuthChallenge is sent by the server when an authentication challenge is initiated
	AuthChallenge
	// AuthChallengeResponse is sent by the client in resposne to an authentication challenge
	AuthChallengeResponse

	// CreateChatRoom is sent when a client wants to create a new chat room
	CreateChatRoom
	// GetChatRooms is sent when a client wants to retrieve a list of available chat rooms
	GetChatRooms
	// GetChatRoomsResponse is sent by the server in response to a GetChatRooms message
	GetChatRoomsResponse

	// JoinChat is sent when a clients wants to join a chat session
	JoinChat
	// ChatInfo is sent by the server when a client has joined a chat session
	ChatInfo
	// SendChat is sent when a client sends a chat message
	SendChat
	// ChatMessageReceived is sent by the server when another user in a chat room sends a chat message
	ChatMessageReceived
	// UserJoined is sent by the server when a user joins a chat room the client is in
	UserJoined
	// UserLeft is sent by the server when a user leaves a chat room the client is in
	UserLeft
	// LeaveChat is sent when a client wants to leave a chat room
	LeaveChat

	// Ping is a keepalive message sent by the server
	Ping
	// Pong is sent by the client in response to a Ping message
	Pong
)

type RegisterUserMessage

type RegisterUserMessage struct {
	Username  string
	PublicKey []byte
}

RegisterUserMessage is the message sent by a client to request user registration

type Room

type Room struct {
	Name        string
	HasPassword bool
	OnlineUsers int
}

Room is used in GetChatRoomsResponse

type SendChatMessage

type SendChatMessage struct {
	EncryptedContent map[string][]byte
}

SendChatMessage is the message sent by the client to the server when a new chat message is sent. The map EncryptedContent contains the message content encrypted by every recipients public key

type User

type User struct {
	Username  string
	PublicKey []byte
}

User is used in ChatInfoMessage, and by the server when notifying a client about a new connected user

Jump to

Keyboard shortcuts

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