
#ifndef _MEDIAINFOSERVICE_H_
#define _MEDIAINFOSERVICE_H_

#include "MFSPublic.h"
#include "3rd/uvw.hpp"

#include "Rtp808Service.h"
#include "BaseService.h"
#include "MediaInfoProtocol.h"

namespace mfs
{

    /**
     * 面向浏览器&手机APP 推拉流的websocket服务
     * 1、客户端建立连接，创建MediaWebSocket
     * 2、接受到客户端信息，转发给MediaWebSocket
     * 
     */ 
class MediaInfoService:public BaseService
{
private:
    MediaInfoService(const std::string& name, int port, std::shared_ptr<uvw::Loop> loop):BaseService(name,port,loop){}
public:
    static MediaInfoService* Instance();
    static MediaInfoService* SetupOnce(int port, std::shared_ptr<uvw::Loop> loop);

    
    int sendFlowInfo(Rtp808Protocol* rtpClient, int endFlag);
    void sendFlowInfo(const StreamInfo& info);

    void sendUserStart(const StreamInfo& info);
    void sendUserEnd(const StreamInfo& info);
    void sendDeviceEnd(const StreamInfo& info);


    
    virtual void Init()
    {
        LOG_DEBUG << "connect mediainfo" << LOG_ENDL;
        BaseService::Init([](std::shared_ptr<uvw::Loop> loop, std::shared_ptr<uvw::TCPHandle> client,const std::string& name){
            return new MediaInfoProtocol(loop, client, name);
	    });
    }
};

}

#endif // _MEDIAINFOSERVICE_H_