-
Notifications
You must be signed in to change notification settings - Fork 1
/
RtcWinDemoDlg.h
150 lines (116 loc) · 3.89 KB
/
RtcWinDemoDlg.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// RtcWinDemoDlg.h: 头文件
//
#pragma once
#include "rtc_manager.h"
#include "WsClient.h"
#include "RtcClient.h"
#include "rtc/video_track_receiver.h"
#include "rtc/rtc_data_manager.h"
#include "rtc/rtc_message_sender.h"
#include "rtc/video_render_gdi.h"
#include "json/cJSON.h"
#include <atomic>
enum WebSocketCommand {
kWebSocketCommandInvalid = 0,
kWebSocketRequestJoinRoom,
kWebSocketRequestLeaveRoom,
kWebSocketRequestPublish,
kWebSocketRequestUnPublish,
kWebSocketRequestSubscribe,
kWebSocketRequestUnSubscribe,
kWebSocketRequestTrickle,
kWebSocketNotifyUserJoin = 0x10,
kWebSocketNotifyUserLeave,
kWebSocketNotifyStreamAdd,
kWebSocketNotifyStreamRemove,
kWebSocketNotifyBroadcast,
};
struct RequestRecord {
RequestRecord(int request, std::string uid) {
command_ = request;
uid_ = uid;
}
int command_;
std::string uid_;
};
// CRtcWinDemoDlg 对话框
class CRtcWinDemoDlg : public CDialogEx, public WsCallback, public VideoTrackReceiver, public RtcClientStateObserver
{
// 构造
public:
CRtcWinDemoDlg(CWnd* pParent = nullptr); // 标准构造函数
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_RTCWINDEMO_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
virtual void onConnected();
virtual void onDisconnected();
virtual void onConnectionError();
virtual void onReceiveMessage(std::string& message);
virtual void AddTrack(webrtc::VideoTrackInterface* track, bool is_local);
virtual void RemoveTrack(webrtc::VideoTrackInterface* track);
virtual void SetWinUsed(HWND window);
virtual void OnIceCandidate(std::string uid, const std::string mid, const std::string sdp);
void OnWebSocketResponse(std::shared_ptr<RequestRecord> request, cJSON *json);
void OnWebSocketNotify(int notify, cJSON *json);
void JoinRoom();
void LeaveRoom();
void Publish(std::string uid, std::string &offer_sdp);
void UnPublish(std::string uid);
void Subscribe(std::string uid, std::string mid, std::string &offer_sdp);
void UnSubscribe(std::string uid, std::string mid);
void Trickle(std::string uid, std::string mid, std::string sdp);
void OnPeerNotifyEvent(bool join, cJSON *json);
void OnStreamNotifyEvent(bool add, cJSON *json);
void OnChatMessage(cJSON* json);
long AllocateSession(int request, std::string uid);
std::shared_ptr<RequestRecord> FindSession(long sessionId);
void DeallocateSession(long sessionId);
int ConvertMethodToCommand(std::string method);
HWND AllocateWindow(bool is_local, std::string track_id);
std::shared_ptr<RtcClient> AddClient(std::string uid, std::string name);
std::shared_ptr<RtcClient> GetClient(std::string uid);
void RemoveClient(std::string uid);
void RemoveAllClients();
void PublishLocalStream(bool publish);
void AppendMessage(CString strMsg, bool title);
// 实现
protected:
HICON m_hIcon;
std::shared_ptr<RTCManager> rtc_manager_;
std::shared_ptr<WsClient> websocket_;
std::map<long, std::shared_ptr<RequestRecord>> map_of_send_requests_;
std::recursive_mutex lock_request_;
std::map<std::string, std::shared_ptr<RtcClient>> map_of_users_;
std::map<std::string, std::shared_ptr<webrtc::VideoRenderGDI>> map_of_video_renders_;
std::recursive_mutex lock_;
std::string room_id_;
std::string user_name_;
std::string user_id_;
std::string mid_;
std::atomic_bool joined_room_;
std::atomic_bool local_published_;
std::atomic_bool auto_publish_;
long session_id_;
std::atomic_bool win1Used;
std::atomic_bool win2Used;
std::atomic_bool win3Used;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedBtnJoin();
afx_msg void OnBnClickedBtnLeave();
afx_msg void OnBnClickedBtnSend();
CRichEditCtrl m_richeditChat;
CEdit m_editMessage;
CEdit m_editRoomId;
CEdit m_editUserId;
afx_msg void OnDestroy();
};