Exemple #1
0
func (r *Room) send(cmd map[string]interface{}) error {
	b, err := json.Marshal(cmd)
	if err != nil {
		return err
	}
	return binhelper.WriteMsg(r.c.conn, b)
}
Exemple #2
0
func (c *Rooms) Publish(roomName string, msg []byte) {
	c.mut.Lock()
	defer c.mut.Unlock()
	all := 0
	errors := 0
	m := map[string]interface{}{
		"r": roomName,
		"m": string(msg), // I am so unhappy about this.
	}
	smsg, err := json.Marshal(m)
	if err != nil {
		panic(err)
	}
	for i := range c.roomToConns[roomName] {
		all++
		conn, exists := c.conns[i]
		if !exists {
			fmt.Println("Bookkeeping is buggy.")
			continue
		}
		err := binhelper.WriteMsg(conn.Conn, smsg)
		if err != nil {
			fmt.Println(err)
			errors++
		}
	}
	if errors > 0 {
		fmt.Println(errors, "errors while publishing to", all, "in room \"", roomName, "\"")
	}
}