Example #1
0
func (c *Channel) RegisterPeer(p *peer.Peer) {
	e := event.New(p.Identification(), "join", c.name, c.name)
	p.NotifyChannel(e, c.eventHandler)

	//Also binds the new peer to emitter, so it can listen to other peers' events
	p.BindChannel("join", c.eventHandler)
	p.BindChannel("message", c.eventHandler)
}
Example #2
0
func (server *Server) HandleConnection(conn net.Conn) {
	peer := new(peer.Peer)

	for {
		e, err := receiveAction(conn)
		if err != nil {
			fmt.Println(err.Error())
		}

		if e.Action == "connect" {
			peer = server.initializePeer(e.User, conn)
		}

		if peer != nil {
			handleConnectionError(conn, err)
			channel := server.channelController.SelectChannel(e.Channel)
			peer.NotifyChannel(e, channel.EventHandler())
		}
	}
}