Documentation ¶
Index ¶
- type HandleRoom
- type Peer
- type Room
- type TCPTransport
- func (t *TCPTransport) Close() error
- func (t *TCPTransport) CreateRoom(host *Peer) (string, error)
- func (t *TCPTransport) GetAllRooms() map[string]*Room
- func (t *TCPTransport) JoinRoom(roomID string, peer *Peer) error
- func (t *TCPTransport) LeaveRoom(roomID string, peerID string) error
- func (t *TCPTransport) Listen(address string) error
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandleRoom ¶
type HandleRoom interface { // JoinRoom joins a collaborative editing room using the specified room ID. // It takes the ID of the room to join and performs any necessary actions to join the room. // Returns an error if joining the room fails. JoinRoom(roomID string, peer *Peer) error // LeaveRoom leaves the current collaborative editing room. // It leaves the current room and performs any necessary cleanup actions. // Returns an error if leaving the room fails. LeaveRoom(string, string) error // CreateRoom creates a new collaborative editing room and returns the room ID. // It creates a new room for collaborative editing and returns the ID of the newly created room. // Returns the room ID and an error if creating the room fails. CreateRoom(host *Peer) (string, error) }
HandleRoom is an interface that defines the methods for handling collaborative editing rooms.
type Peer ¶
type Peer struct { ID string `json:"id"` // Unique identifier for the peer Name string `json:"name"` // Name of the peer Email string `json:"email"` // Email of the peer Address string `json:"address"` // Host:Port address of the peer Online bool `json:"online"` // Indicates whether the peer is currently online }
Peer represents a participant in the collaborative code editing network. Each peer is uniquely identified by an ID and may have associated metadata such as name, email, and network address. Peers are essential for facilitating communication, collaboration, and coordination within the distributed code editing environment.
type Room ¶
type Room struct { ID string `json:"id"` // Unique identifier for the room Host *Peer `json:"host"` // Peer representing the host of the room Peers map[string]*Peer `json:"peers"` // Map of connected peers in the room, keyed by peer ID Chat []string `json:"chat"` // Chat history within the room }
Room represents a collaborative editing room in the network. It contains information about the room ID, host, connected peers, and chat history.
type TCPTransport ¶
type TCPTransport struct { Listener net.Listener // Listener for accepting incoming connections Mutex sync.Mutex // Mutex for safe access to the rooms map Rooms map[string]*Room // Map to store rooms in the network, keyed by room ID }
TCPTransport implements the Transport interface using TCP. It manages the network transport layer responsible for facilitating communication between peers.
func NewTCPTransport ¶
func NewTCPTransport() *TCPTransport
NewTCPTransport creates a new instance of TCPTransport. It initializes the Rooms map to store rooms in the network.
func (*TCPTransport) Close ¶
func (t *TCPTransport) Close() error
Close closes the TCP transport, releasing any associated resources. It closes the network listener if it's initialized.
func (*TCPTransport) CreateRoom ¶
func (t *TCPTransport) CreateRoom(host *Peer) (string, error)
CreateRoom creates a new collaborative editing room and returns the room ID. The room is created by taking the specified host as the initial peer in the room. It generates a unique room ID, creates a new room with the host, and adds the room to the network's rooms map. It returns the room ID and an error if creating the room fails.
func (*TCPTransport) GetAllRooms ¶
func (t *TCPTransport) GetAllRooms() map[string]*Room
func (*TCPTransport) JoinRoom ¶
func (t *TCPTransport) JoinRoom(roomID string, peer *Peer) error
JoinRoom allows a peer to join a collaborative editing room by its ID. It checks if the specified room exists in the network. If the room exists, it adds the peer to the room's list of connected peers. It returns an error if the room doesn't exist or if the peer is already in the room.
func (*TCPTransport) LeaveRoom ¶
func (t *TCPTransport) LeaveRoom(roomID string, peerID string) error
LeaveRoom allows a peer to leave a collaborative editing room by its ID. It checks if the specified room exists in the network. If the room exists, it removes the peer from the room's list of connected peers. It returns an error if the room doesn't exist or if the peer is not in the room.
func (*TCPTransport) Listen ¶
func (t *TCPTransport) Listen(address string) error
Listen starts listening for incoming TCP connections on the specified address. It initializes the network listener if not already initialized.
type Transport ¶
type Transport interface { // Listen starts listening for incoming connections on the specified address. // It takes the address (host:port) on which to listen for incoming connections. // Returns an error if starting the listener fails. Listen(address string) error // Close closes the network transport, releasing any associated resources. // It stops listening for incoming connections and cleans up any resources used by the transport. // Returns an error if closing the transport fails. Close() error }
Transport represents the network transport layer responsible for facilitating communication between peers in the collaborative code editing network. It supports TCP and WebRTC protocols but can be extended to support other protocols(UDP, Sockets, RPC, ...).