#include "use_room.h"
#include "api/musermanager.h"

using namespace rtc;

///
Use_Room::Use_Room(QWidget *parent) : Com_Room(parent), room_(NULL) {
}
Use_Room::~Use_Room() {
}
///
void Use_Room::modulesAttach() {
	if (ui.audio) {
		ui.audio->onAttach(room_);
	}
	if (ui.video) {
		ui.video->onAttach(room_);
	}
    if(ui.screen){
        ui.screen->onAttach(room_);
    }
}
Result Use_Room::api_joinRoom(const char* roomId, const char* userId, const char* userName, const char* userData) {
	room_ = IRoom::obtain(roomId);
	if (!room_) {
		return Err_Invalid_Arg;
	}
	room_->setListener(this);
	User user;
	user.userId = userId;
	user.userName = userName;
	user.userData = userData;
	return room_->join(user, "", NULL);
}
void Use_Room::api_leaveRoom() {
	room_->leave(AVD_OK);
	room_->release();
	room_ = NULL;
}
bool  Use_Room::api_isWorking() const {
	return room_->isWorking();
}
Result Use_Room::api_enableStats(bool enable) {
	return room_->enableStats(enable);
}
rtc::NetworkStats Use_Room::getRoomNetStats() const {
	RoomStats roomstats = room_->getRoomStats();
	return roomstats;
}
