chat

package
v0.0.0-...-0ab474c Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupRandomAddr

func SetupRandomAddr(t *testing.T) string

SetupRandomAddr generates a random address for testing purposes.

Types

type ChatService

type ChatService struct {
	TCPTransport *network.TCPTransport // Reference to the TCPTransport instance
}

ChatService represents the chat service responsible for managing the chat system. It provides methods for sending and receiving messages, as well as managing connections with peers.

func NewChatService

func NewChatService(transport *network.TCPTransport) *ChatService

NewChatService creates a new instance of ChatService with the provided transport layer. It initializes the chat service with the specified transport for communication.

func (*ChatService) Receive

func (cs *ChatService) Receive(roomID string) ([]string, error)

ReceiveMessage receives a chat message from a specific room.

func (*ChatService) Send

func (cs *ChatService) Send(roomID string, sender *network.Peer, content string) error

SendMessage sends a chat message to a specific room.

type MockTransport

type MockTransport struct {
	SendFunc       func(data []byte, peer *network.Peer) error
	ReceiveFn      func() ([]byte, *network.Peer, error)
	ListenFn       func(address string) error
	CloseFn        func() error
	ConnectFunc    func(address string) (*network.Peer, error) // Add Connect function
	JoinRoomFunc   func(roomID string) error                   // Add JoinRoom function
	LeaveRoomFunc  func() error                                // Add LeaveRoom function
	CreateRoomFunc func() (string, error)                      // Add CreateRoom function
}

Jump to

Keyboard shortcuts

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