Documentation ¶
Overview ¶
Package client provides a ChatterBox client for communicating with a ChatterBox server.
Usage is simple:
user := "some user" channel := "some channel" c, err := New("<host:port>", user) if err != nil { // Do something } // Must subscribe before doing anything else. if err := c.Subscribe("<channel name>"); err != nil { // Do something } stop := make(chan struct{}) // Receive messages. go func() { for { select { case <-stop: fmt.Println("Exiting channel") return case m := <-c.Messages: // Ignore messages from yourself, we don't have separate panes to display in. if m.User == user { continue } fmt.Println("%s: %s", m.User, m.Text.Text) } } }() for { reader := bufio.NewReader(os.Stdin) fmt.Print(">") text, _ := reader.ReadString('\n') if text == "exit" { fmt.Printf("Exiting comm channel %s\n", channel) break } if err := c.SendText(text); err != nil { fmt.Printf("Error: %s, exiting....\n", err) break } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatterBox ¶
type ChatterBox struct { // Messages are text messages arriving from the server to this client. Messages chan messages.Server // ServerErrors are errors sent from the server to the client. ServerErrors chan error // UserUpdates are updates to the users who are in the comm channel. UserUpdates chan []string // ChannelDrop are updates saying we've been unsubscribed to a comm channel. ChannelDrop chan struct{} // Subscribed is an update saying we've been subscribed to a comm channel. Subscribed chan messages.Server // Done indicates that the server connection is dead, this client is Done. Done chan struct{} // contains filtered or unexported fields }
ChatterBox is a client for the ChatterBox service. You must service all publically available channels or the client might freeze. TODO(johnsiilver): Fix that, its ridiculous.
func (*ChatterBox) Drop ¶
func (c *ChatterBox) Drop() error
Drop disconnects from a comm channel channel.
func (*ChatterBox) SendText ¶
func (c *ChatterBox) SendText(t string) error
SendText sends a text message to others on our comm channel.
Click to show internal directories.
Click to hide internal directories.