Example #1
0
func (m Engine) SubscribeClient(request protocol.Message, client *protocol.Client) {
	response := m.responseFromRequest(request)
	response["successful"] = true

	subscription := request["subscription"]
	response["subscription"] = subscription

	var subs []string
	switch subscription.(type) {
	case []string:
		subs = subscription.([]string)
	case string:
		subs = []string{subscription.(string)}
	}

	for _, s := range subs {
		// Do not register clients subscribing to a service channel
		// They will be answered directly instead of through the normal subscription system
		if !protocol.NewChannel(s).IsService() {
			m.AddSubscription(client.Id(), []string{s})
		}
	}

	client.Queue(response)
}
Example #2
0
func (m Engine) Connect(request protocol.Message, client *protocol.Client, conn protocol.Connection) {
	response := m.responseFromRequest(request)
	response["successful"] = true

	timeout, _ := strconv.Atoi(protocol.DEFAULT_ADVICE["timeout"])

	response.Update(protocol.Message{
		"advice": protocol.DEFAULT_ADVICE,
	})
	client.Connect(timeout, 0, response, conn)
}
func (cr ClientRegister) AddClient(client *protocol.Client) {
	cr.clients.Put(client.Id(), client)
}