func (api *channellingAPI) HandleAuthentication(session *channelling.Session, st *channelling.SessionToken) (*channelling.DataSelf, error) {
	if err := api.SessionManager.Authenticate(session, st, ""); err != nil {
		log.Println("Authentication failed", err, st.Userid, st.Nonce)
		return nil, err
	}

	log.Println("Authentication success", session.Userid())
	self, err := api.HandleSelf(session)
	if err == nil {
		session.BroadcastStatus()
	}

	return self, err
}
Ejemplo n.º 2
0
func (api *channellingAPI) HandleChat(session *channelling.Session, chat *channelling.DataChat) {
	// TODO(longsleep): Limit sent chat messages per incoming connection.
	msg := chat.Chat
	to := chat.To

	if !msg.NoEcho {
		session.Unicast(session.Id, chat, nil)
	}
	msg.Time = time.Now().Format(time.RFC3339)
	if to == "" {
		// TODO(longsleep): Check if chat broadcast is allowed.
		if session.Hello {
			api.StatsCounter.CountBroadcastChat()
			session.Broadcast(chat)
		}
	} else {
		if msg.Status != nil {
			if msg.Status.ContactRequest != nil {
				if !api.config.WithModule("contacts") {
					return
				}
				if err := api.ContactManager.ContactrequestHandler(session, to, msg.Status.ContactRequest); err != nil {
					log.Println("Ignoring invalid contact request.", err)
					return
				}
				msg.Status.ContactRequest.Userid = session.Userid()
			}
		} else {
			api.StatsCounter.CountUnicastChat()
		}

		session.Unicast(to, chat, nil)
		if msg.Mid != "" {
			// Send out delivery confirmation status chat message.
			session.Unicast(session.Id, &channelling.DataChat{To: to, Type: "Chat", Chat: &channelling.DataChatMessage{Mid: msg.Mid, Status: &channelling.DataChatStatus{State: "sent"}}}, nil)
		}
	}
}
Ejemplo n.º 3
0
func (api *channellingAPI) HandleSelf(session *channelling.Session) (*channelling.DataSelf, error) {
	token, err := api.SessionEncoder.EncodeSessionToken(session)
	if err != nil {
		log.Println("Error in OnRegister", err)
		return nil, err
	}

	log.Println("Created new session token", len(token), token)
	self := &channelling.DataSelf{
		Type:       "Self",
		Id:         session.Id,
		Sid:        session.Sid,
		Userid:     session.Userid(),
		Suserid:    api.SessionEncoder.EncodeSessionUserID(session),
		Token:      token,
		Version:    api.config.Version,
		ApiVersion: apiVersion,
		Turn:       api.TurnDataCreator.CreateTurnData(session),
		Stun:       api.config.StunURIs,
	}
	api.BusManager.Trigger(channelling.BusManagerSession, session.Id, session.Userid(), nil, nil)

	return self, nil
}