socket_remote.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #ifdef WIN32
  3. #ifndef WIN32_LEAN_AND_MEAN
  4. #define WIN32_LEAN_AND_MEAN
  5. #endif
  6. #endif
  7. #include <WS2tcpip.h>
  8. #include <WinSock2.h>
  9. #include <thread>
  10. #include <unordered_map>
  11. #include <functional>
  12. #include "../common/comm.h"
  13. #include "include/remote_notify.h"
  14. #include "../common/remote_def.h"
  15. class CIOBuffer;
  16. class SocketRemote
  17. {
  18. public:
  19. typedef void (SocketRemote::* FN)(int8_t* Data, int16_t Size);
  20. SocketRemote(IRemoteNotify* n);
  21. bool Start(const char* ip);
  22. void Run();
  23. void Stop();
  24. void Write(CIOBuffer* pBuffer);
  25. void WriteSigin(EgoType type, std::string& account,std::string& pass,std::string& name);
  26. void WriteOffer(int32_t peer, int32_t index, const char* type, const char* sdp);
  27. void WriteAnswer(int32_t peer, int32_t index, const char* type, const char* sdp);
  28. void WriteCandidate(int32_t peer, int32_t index, const char* candidate, int32_t sdp_mline_index, const char* sdp_mid);
  29. void WriteVideoReq(int32_t peer, int32_t index);
  30. void WriteVideoRep(int32_t peer, remote::VideoDesc desc, int32_t index);
  31. void WriteVideoLeave(int32_t peer);
  32. void WriteKeepAlive();
  33. void WriteUserList();
  34. private:
  35. void NetProcess(int16_t cmd, int8_t* Data, int16_t Size);
  36. void OnNotifyRep(int8_t* Data, int16_t Size);
  37. void OnNotifyAdd(int8_t* Data, int16_t Size);
  38. void OnNotifyDel(int8_t* Data, int16_t Size);
  39. void OnSigin(int8_t* Data, int16_t Size);
  40. void OnNotifyLeave(int8_t* Data, int16_t Size);
  41. void OnNotifyOffer(int8_t* Data, int16_t Size);
  42. void OnNotifyAnswer(int8_t* Data, int16_t Size);
  43. void OnNotifyCandidate(int8_t* Data, int16_t Size);
  44. void OnNotifyState(int8_t* Data, int16_t Size);
  45. void OnNotifyReq(int8_t* Data, int16_t Size);
  46. void OnRobotRep(int8_t* Data, int16_t Size);
  47. private:
  48. std::unordered_map<int16_t, FN> FnMap;
  49. IRemoteNotify* _notify;
  50. SOCKET sockfd;
  51. std::thread _thread;
  52. bool _run;
  53. bool _connected;
  54. int32_t _uid;
  55. std::string _ip;
  56. };