#ifndef __COM_Room_H__
#define __COM_Room_H__
#include "ui_use_room.h"
#include "api/room.h"

class Use_Video;
class Use_Audio;

class Com_Room : public QWidget
	, public rtc::IRoom::IListener
{
public:
	Q_OBJECT
public:
	 Com_Room(QWidget *parent = 0);
	~Com_Room();
public:
	bool isWorking() const;
public slots:
	bool on_join_leaveRoom(bool isJoin);
	//
	bool on_sendPublicData();	// 透明通道：房间通道，发送后房间内所有与会者都能收到
	bool on_sendPrivateData();	// 透明通道：房间内私有通道，发送给房间中确定UserId的用户，其他人无法收到
	bool on_updateAppData();	// 房间数据透明通道：房间数据键值对，应用层维护此房间数据；用户加入房间后会马上接受到此房间数据
	bool on_enableStats(bool enable);
	//
	void on_timerOut();			// 获取房间内的媒体和网络统计信息
protected:
	bool joinRoom();
	bool leaveRoom();
	void resetControls(bool enable);

protected: // c or cpp api imp
	virtual bool   roomIsInit() const = 0;
	virtual void   modulesAttach() = 0;
	virtual Result api_joinRoom (const char* roomId, const char* userId, const char* userName, const char* userData) = 0;
	virtual void   api_leaveRoom() = 0;
	virtual bool   api_isWorking() const = 0;
	virtual Result api_enableStats(bool enable) = 0;
	virtual rtc::NetworkStats getRoomNetStats() const = 0;

public:
	/// IRoom::IListener implementation
	void onJoinResult(Result result);
    void onLeaveIndication(Result reason, const rtc::UserId& fromId);
    void onPublicData(const char* data, uint32 len, const rtc::UserId& fromId);
    void onPrivateData(const char* data, uint32 len, const rtc::UserId& fromId);
    void onAppDataNotify(const rtc::String& key, const rtc::String& value);
	void onRoomStatusNotify(rtc::RoomStatus status);
	void onConnectionStatus(rtc::ConnectionStatus status);
    void onOutgoingInviteStatusNotify(rtc::OutgoingInviteType type, std::string roomId, std::string addr, rtc::OutgoingStatus status, std::string  msg);
    void onStreamKeepAliveTimeoutNotify(std::string userId, std::string userName, int mediaType, std::string deviceId, int ssrc);
protected:
	Ui::Use_Room ui;
	QTimer* timer_;
    rtc::RoomId roomId_;
};

#endif //__COM_Room_H__
