model

package
v0.0.0-...-77682ad Latest Latest
Warning

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

Go to latest
Published: May 11, 2014 License: Apache-2.0 Imports: 7 Imported by: 0

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

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

type ClientList map[string]Client

ClientList represents the list of all connected clients.

type Message

type Message struct {
	Text   string
	Room   *Room
	Sender string
}

Message represents data which gets sent to the client.

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

func (r *Room) RemoveClient(loginName string)

RemoveClient removes a client from the room.

type RoomList

type RoomList map[string]*Room

ClientList represents the list of all active rooms.

func (*RoomList) GetOrCreateRoom

func (rl *RoomList) GetOrCreateRoom(roomName string) (room *Room)

GetOrCreateRoom creates a room if not existing and returns it.

func (*RoomList) RemoveRoomIfEmpty

func (rl *RoomList) RemoveRoomIfEmpty(roomName string)

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

func (c *TcpClient) 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 (*TcpClient) Leave

func (c *TcpClient) Leave()

With Leave clients can leave a room. It refreshes all associated lists.

func (*TcpClient) LoginName

func (c *TcpClient) LoginName() string

LoginName return the login name of the client.

func (*TcpClient) Read

func (c *TcpClient) Read() (line []byte, err error)

Read reads the client input from the connection buffer.

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.

func (*TcpClient) Room

func (c *TcpClient) Room() *Room

Room return the current room of the client.

func (*TcpClient) Rooms

func (c *TcpClient) Rooms()

Rooms sends a room overview to the client.

func (*TcpClient) Send

func (c *TcpClient) Send(message string)

Send sends a message to the client.

func (*TcpClient) Sender

func (c *TcpClient) Sender()

Sender listens to the input channel and send the incoming messages to the client. It should run as goroutine.

Jump to

Keyboard shortcuts

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