Beispiel #1
0
func (m Engine) Handshake(request protocol.Message, conn protocol.Connection) string {
	newClientId := ""
	version := request["version"].(string)

	response := m.responseFromRequest(request)
	response["successful"] = false

	if version == protocol.BAYEUX_VERSION {
		newClientId = m.NewClient(conn).Id()

		response.Update(map[string]interface{}{
			"clientId":                 newClientId,
			"channel":                  protocol.META_PREFIX + protocol.META_HANDSHAKE_CHANNEL,
			"version":                  protocol.BAYEUX_VERSION,
			"advice":                   protocol.DEFAULT_ADVICE,
			"supportedConnectionTypes": []string{"websocket", "long-polling"},
			"successful":               true,
		})

	} else {
		response["error"] = fmt.Sprintf("Only supported version is '%s'", protocol.BAYEUX_VERSION)
	}

	// Answer directly
	conn.Send([]protocol.Message{response})
	return newClientId
}
Beispiel #2
0
func (s Server) GetClient(request protocol.Message, conn protocol.Connection) *protocol.Client {
	clientId := request.ClientId()
	client := s.engine.GetClient(clientId)
	if client == nil {
		s.Logger().Warnf("Message %v from unknown client %v", request.Channel(), clientId)
		response := request
		response["successful"] = false
		response["advice"] = map[string]interface{}{"reconnect": "handshake", "interval": "1000"}
		conn.Send([]protocol.Message{response})
		conn.Close()
	}
	return client
}