Blame view

src/decoder/gb28181/websocket/WebsocketClient.h 1.77 KB
d8fe994c   Hu Chunming   提交解码代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  #include <map>
  #include <mutex>
  
  #include <websocketpp/config/asio_no_tls_client.hpp>
  #include <websocketpp/client.hpp>
  
  #include "Message/CatalogParser.h"
  
  #include "../rtp/RTPReceiver.h"
  
  typedef websocketpp::client<websocketpp::config::asio_client> client;
  typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
  
  class WebsocketClient
  {
  public:
      static WebsocketClient* getInstance(){
  		static WebsocketClient* singleton = nullptr;
  		if (singleton == nullptr){
  			singleton = new WebsocketClient();
  		}
  		return singleton;
  	}
  
  public:
      int init();
  
      void close();
  
      void terminate();
  
      int GetMinRtpPort();
      int GetMaxRtpPort();
  
      int InviteUdp(std::string sip_channel_id, int rtp_port, RTPReceiver* r);
      int InviteTcp(std::string sip_channel_id, int rtp_port, RTPReceiver* r);
  
      int ByeInvite(std::string sip_channel_id, int rtp_port);
  
      int DeleteReceiverPair(std::string sip_channel_id, int rtp_port);
  
  public:
      void on_open(websocketpp::connection_hdl hdl);
      void on_close(websocketpp::connection_hdl hdl);
  
      void on_message(websocketpp::connection_hdl hdl, message_ptr msg);
  
      void on_fail(websocketpp::connection_hdl hdl);
  
  private:
      bool readCfg();
      int connect();
      int reconnect();
      int check_connect();
      void send_text(std::string msg);
  
      int msg_parser(websocketpp::connection_hdl hdl, string msg);
  
      void cache_receiver(std::string sip_channel_id, int rtp_port, RTPReceiver* r);
  
      void response_invite_failed(std::string rKey);
  
  private:
    client m_client;
    websocketpp::lib::shared_ptr<websocketpp::lib::thread> thread_;
    websocketpp::connection_hdl m_hdl;
    std::string uri;
  
    ServerInfo mInfo;
  
    bool mbClosed{false};
  
    std::map<string, RTPReceiver*> m_receiver_map;
    std::mutex m_receiver_map_mtx;
  };