WebHandler.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include <websocketpp/config/asio_no_tls.hpp>
  3. #include <websocketpp/server.hpp>
  4. #include <unordered_map>
  5. #include <mutex>
  6. #include <string>
  7. #include <memory>
  8. #include <vector>
  9. #include <cstdint>
  10. const char kCandidateSdpMidName[] = "sdpMid";
  11. const char kCandidateSdpMlineIndexName[] = "sdpMLineIndex";
  12. const char kCandidateSdpName[] = "candidate";
  13. // Names used for a SessionDescription JSON object.
  14. const static char kSessionDescriptionTypeName[] = "type";
  15. const static char kSessionDescriptionSdpName[] = "sdp";
  16. const static char kPeerId[] = "peer";
  17. const static char kSigin[] = "sigin";
  18. const static char kOffer[] = "offer";
  19. const static char kCandidate[] = "candidate";
  20. const static char kLeave[] = "leave";
  21. const static char kAnswer[] = "answer";
  22. const static char kReqVideo[] = "reqvideo";
  23. const static char kCloseVideo[] = "closevideo";
  24. const static char kRepVideo[] = "repvideo";
  25. const static char kCancelReq[] = "cancelreq";
  26. const static char kHeartbit[] = "heartbeat";
  27. const static char kMemberList[] = "memberlist";
  28. const static char kKickOff[] = "kickoff";
  29. const static char kNotify[] = "notify";
  30. class CIOBuffer;
  31. class CWebServer;
  32. class CWebHandler : public std::enable_shared_from_this<CWebHandler>
  33. {
  34. public:
  35. enum {
  36. ALLOC_ARG = 16,
  37. BASE_SIZE = 32
  38. };
  39. CWebHandler(CWebServer* s, int32_t uid, int32_t cid, websocketpp::connection_hdl hdl);
  40. ~CWebHandler();
  41. bool Write(CIOBuffer* pBuffer);
  42. void OnClose();
  43. websocketpp::connection_hdl GetConnectHandle();
  44. void OnWebReqVideo(int32_t peer, int32_t width, int32_t height, int32_t fps);
  45. void OnWebRepVideo(int32_t peer, std::string& desc, int32_t width, int32_t height, int32_t fps);
  46. void OnWebCancelReq(int32_t did);
  47. void OnWebLeave(int32_t peer);
  48. void OnWebHeartbeat();
  49. int32_t GetId() { return uid; }
  50. void KickOff();
  51. uint64_t GetBeatTick() {
  52. return beat_tick;
  53. }
  54. VideoDesc ReqVideo(int32_t uid, int32_t width, int32_t height, int32_t fps);
  55. void RepVideo(int32_t uid, VideoDesc ret, int32_t width, int32_t height, int32_t fps);
  56. void LeaveVideo(int32_t peer);
  57. void CancelReq(int32_t peer);
  58. //bool ChatMessage(int32_t peer, std::string& type, std::string& content);
  59. bool Notify(const char* content);
  60. private:
  61. void MessageThread();
  62. private:
  63. std::thread _thread;
  64. websocketpp::connection_hdl connect_hdl;
  65. CWebServer* server;
  66. int32_t uid;
  67. int32_t companyid;
  68. bool bHasCamera;
  69. std::atomic<bool> bRun;
  70. std::atomic<bool> bWait;
  71. std::atomic<int32_t> video_peer;
  72. std::mutex videolock;
  73. uint64_t beat_tick;
  74. };