Documentation ¶
Overview ¶
Package model provides the core components of the chat communication. It contains the client interface and structs for messages, rooms, clients as well as lists for clients and rooms.
Index ¶
- type Client
- type ClientList
- type Message
- type Room
- type RoomList
- type SocketClient
- func (c *SocketClient) Close()
- func (c *SocketClient) CloseUnexpectedly()
- func (c *SocketClient) HandleCommand(command, message string)
- func (c *SocketClient) Join(roomName string)
- func (c *SocketClient) Leave()
- func (c *SocketClient) LoginName() string
- func (c *SocketClient) Read() ([]byte, error)
- func (c *SocketClient) RefreshClientlists()
- func (c *SocketClient) RefreshRoomlists()
- func (c *SocketClient) Room() *Room
- func (c *SocketClient) Rooms()
- func (c *SocketClient) Send(m string)
- func (c *SocketClient) SendCommandResponse(message interface{}, command, parameter string)
- func (c *SocketClient) SendRoomMemberlist(members []string)
- type TcpClient
- func (c *TcpClient) Close()
- func (c *TcpClient) CloseUnexpectedly()
- func (c *TcpClient) Join(roomName string)
- func (c *TcpClient) Leave()
- func (c *TcpClient) LoginName() string
- func (c *TcpClient) Read() (line []byte, err error)
- func (c *TcpClient) Reader()
- func (c *TcpClient) RefreshClientlists()
- func (c *TcpClient) RefreshRoomlists()
- func (c *TcpClient) Room() *Room
- func (c *TcpClient) Rooms()
- func (c *TcpClient) Send(message string)
- func (c *TcpClient) Sender()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Getter Room() *Room LoginName() string // Commands Join(r string) Leave() Send(m string) Read() ([]byte, error) Close() CloseUnexpectedly() Rooms() // List updating for socket clients RefreshRoomlists() RefreshClientlists() }
The Client interface describes all necessary methods for TCP and Websocket clients.
type ClientList ¶
ClientList represents the list of all connected clients.
type Room ¶
type Room struct { Name string Clients *ClientList }
A Room has a name and a list of clients.
func (*Room) RefreshMemberlist ¶
func (r *Room) RefreshMemberlist()
RefreshMemberlist sends the current member list of the room to all connected Websocket client.
func (*Room) RemoveClient ¶
RemoveClient removes a client from the room.
type RoomList ¶
ClientList represents the list of all active rooms.
func (*RoomList) GetOrCreateRoom ¶
GetOrCreateRoom creates a room if not existing and returns it.
func (*RoomList) RemoveRoomIfEmpty ¶
RemoveRoomIfEmpty removes empty rooms from the room list.
type SocketClient ¶
type SocketClient struct {
// contains filtered or unexported fields
}
SocketClient represents a Websocket client. It implements the Client interface.
func NewSocketClient ¶
func NewSocketClient(loginName string, conn *socketio.NameSpace, room *Room, rooms *RoomList, clients *ClientList, out chan *Message) *SocketClient
NewSocketClient creates a SocketClient.
func (*SocketClient) Close ¶
func (c *SocketClient) Close()
Close will quit the connection to the client (and removes client from rooms if necessary). It deletes the client from the client list.
func (*SocketClient) CloseUnexpectedly ¶
func (c *SocketClient) CloseUnexpectedly()
CloseUnexpectedly gets called if the client disconnects unexpectedly (e.g. tab close). It deletes the client from the client list (and removes it from rooms if necessary).
func (*SocketClient) HandleCommand ¶
func (c *SocketClient) HandleCommand(command, message string)
HandleCommand handles all possible commands for the client and calls the associated methods.
func (*SocketClient) Join ¶
func (c *SocketClient) Join(roomName string)
Join lets clients join rooms and sends a room member overview. It takes care of room hopping and refreshes the client and room list of Websocket clients.
func (*SocketClient) Leave ¶
func (c *SocketClient) Leave()
With Leave clients can leave a room. It refreshes all associated lists.
func (*SocketClient) LoginName ¶
func (c *SocketClient) LoginName() string
LoginName return the login name of the client.
func (*SocketClient) Read ¶
func (c *SocketClient) Read() ([]byte, error)
Read is not needed for Websocket clients.
func (*SocketClient) RefreshClientlists ¶
func (c *SocketClient) RefreshClientlists()
RefreshClientlists refreshes the sidebar client list for all Websocket clients.
func (*SocketClient) RefreshRoomlists ¶
func (c *SocketClient) RefreshRoomlists()
RefreshRoomlists refreshes the sidebar room list for all Websocket clients.
func (*SocketClient) Room ¶
func (c *SocketClient) Room() *Room
Room return the current room of the client.
func (*SocketClient) Rooms ¶
func (c *SocketClient) Rooms()
Rooms sends a room overview to the client. The list gets presented inside the chat area.
func (*SocketClient) Send ¶
func (c *SocketClient) Send(m string)
Send sends a message to the client.
func (*SocketClient) SendCommandResponse ¶
func (c *SocketClient) SendCommandResponse(message interface{}, command, parameter string)
SendCommandResponse sends responses to the client (e.g. for registration).
func (*SocketClient) SendRoomMemberlist ¶
func (c *SocketClient) SendRoomMemberlist(members []string)
SendRoomMemberlist sends the client list of the current room of the client.
type TcpClient ¶
type TcpClient struct { // Channels In chan string // contains filtered or unexported fields }
SocketClient represents a TCP (Telnet) client. It implements the Client interface.
func NewTcpClient ¶
func NewTcpClient(loginName string, conn net.Conn, room *Room, rooms *RoomList, clients *ClientList, in chan string, out chan *Message, quit chan bool) *TcpClient
NewTcpClient creates a TcpClient.
func (*TcpClient) Close ¶
func (c *TcpClient) Close()
Close will quit the connection to the client (and removes client from rooms if necessary). It deletes the client from the client list.
func (*TcpClient) CloseUnexpectedly ¶
func (c *TcpClient) CloseUnexpectedly()
CloseUnexpectedly gets called if the client disconnects unexpectedly (e.g. Telnet closed). It deletes the client from the client list (and removes it from rooms if necessary).
func (*TcpClient) Join ¶
Join lets clients join rooms and sends a room member overview. It takes care of room hopping and refreshes the client and room list of Websocket clients.
func (*TcpClient) Leave ¶
func (c *TcpClient) Leave()
With Leave clients can leave a room. It refreshes all associated lists.
func (*TcpClient) Reader ¶
func (c *TcpClient) Reader()
Reader reads the messages of a client and forwards them to the broadcast channel. It also handles special commands like /quit. It should run as goroutine.
func (*TcpClient) RefreshClientlists ¶
func (c *TcpClient) RefreshClientlists()
RefreshClientlists refreshes the sidebar client list for all Websocket clients.
func (*TcpClient) RefreshRoomlists ¶
func (c *TcpClient) RefreshRoomlists()
RefreshRoomlists refreshes the sidebar room list for all Websocket clients.