Пример #1
0
func (hub *Hub) processRequest(socket *mexsocket.MexSocket, req *message.Request) {

	if req == nil {
		return
	}

	switch req.MexType {

	//create a new answer and send it over the channel
	case message.Identity:
		answer := message.NewAnswerIdentity(socket.Id)
		socket.Send(answer)

	//get the list of connected clients, remove the current one and send it over the channel
	case message.List:

		//the resulting list is []interface{}
		list := set.Difference(hub.idSet, set.New(socket.Id)).List()

		//create new answer
		answer := new(message.Answer)
		answer.MexType = message.List
		answer.Payload = convertSetList(list)
		socket.Send(answer)

	case message.Relay:

		//create an answer containing the payload
		answer := message.NewAnswerRelay(req.Body)

		//call hub to send the message to the list of clients provided
		hub.Multicast(req.Receivers, answer)
	}
}