Skip to content

Commit ea8cd06

Browse files
Converted web example to WebSocket signaling
1 parent 534201b commit ea8cd06

16 files changed

+838
-317
lines changed

.clang-format

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,12 @@ AccessModifierOffset: -4
1010
ColumnLimit: 100
1111
---
1212
Language: JavaScript
13-
ColumnLimit: 80
13+
IndentWidth: 2
14+
UseTab: Never
15+
ColumnLimit: 100
16+
---
17+
Language: Python
18+
IndentWidth: 4
19+
UseTab: Never
20+
ColumnLimit: 79
1421
...

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ insert_final_newline = true
99
indent_style = tab
1010
indent_size = 4
1111

12+
[*.js]
13+
insert_final_newline = true
14+
indent_style = space
15+
indent_size = 2
16+
17+
[*.py]
18+
insert_final_newline = false
19+
indent_style = space
20+
indent_size = 4
21+

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
build/
2+
node_modules/
23
*.d
34
*.o
45
*.a
56
*.so
67
compile_commands.json
78
tests
89
.DS_Store
10+

examples/client/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.7)
22
cmake_policy(SET CMP0079 NEW)
33

44
add_executable(datachannel-client main.cpp)
5-
set_target_properties(datachannel-client PROPERTIES CXX_STANDARD 17)
5+
set_target_properties(datachannel-client PROPERTIES
6+
CXX_STANDARD 17
7+
OUTPUT_NAME client)
68
target_link_libraries(datachannel-client datachannel nlohmann_json)
79

examples/client/main.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int main(int argc, char **argv) {
5252
rtc::InitLogger(LogLevel::Warning);
5353

5454
Configuration config;
55-
config.iceServers.emplace_back("stun.l.google.com:19302"); // change to your STUN server
55+
config.iceServers.emplace_back("stun:stun.l.google.com:19302"); // change to your STUN server
5656

5757
localId = randomId(8);
5858
cout << "The local ID is: " << localId << endl;
@@ -92,12 +92,12 @@ int main(int argc, char **argv) {
9292
}
9393

9494
if (type == "offer" || type == "answer") {
95-
auto str = message["description"].get<string>();
96-
pc->setRemoteDescription(Description(str, type));
95+
auto sdp = message["description"].get<string>();
96+
pc->setRemoteDescription(Description(sdp, type));
9797
} else if (type == "candidate") {
98-
auto str = message["candidate"].get<string>();
98+
auto sdp = message["candidate"].get<string>();
9999
auto mid = message["mid"].get<string>();
100-
pc->addRemoteCandidate(Candidate(str, mid));
100+
pc->addRemoteCandidate(Candidate(sdp, mid));
101101
}
102102
});
103103

@@ -188,8 +188,6 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
188188
cout << "DataChannel from " << id << " received with label \"" << dc->label() << "\""
189189
<< endl;
190190

191-
dc->send("Hello from " + localId);
192-
193191
dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
194192

195193
dc->onMessage([id](const variant<binary, string> &message) {
@@ -199,6 +197,8 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
199197
cout << "Message from " << id << " received: " << get<string>(message) << endl;
200198
});
201199

200+
dc->send("Hello from " + localId);
201+
202202
dataChannelMap.emplace(id, dc);
203203
});
204204

examples/web/LICENSE

+339
Large diffs are not rendered by default.

examples/web/answerScript.js

-111
This file was deleted.

examples/web/answerer.html

-22
This file was deleted.

examples/web/index.html

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<title>Web Rtc Example</title>
4+
<meta charset="UTF-8">
5+
<title>WebRTC Example</title>
6+
<link rel="stylesheet" href="style.css">
7+
<script src="script.js"></script>
58
</head>
69
<body>
7-
<h1>Web Rtc</h1>
8-
<button id="createConnectionBtn">Create Connection</button>
9-
<br/>
10-
<textarea id="sendData" placeholder="Send a message" style="width: 500px; height: 50px"></textarea>
11-
<br/>
12-
<button id="sendDataBtn">Send Data</button>
13-
<script src="/script.js"></script>
10+
<h1>WebRTC Example</h1>
11+
<h2>Local ID</h2>
12+
<p id="localId"></p>
13+
<h2>Send an offer through signaling</h2>
14+
<input type="text" id="offerId" placeholder="remote ID" disabled>
15+
<input type="button" id="offerBtn" value="Offer" disabled>
16+
<br>
17+
<h2>Send a message through DataChannel</h2>
18+
<input type="text" id="sendMsg" placeholder="message" disabled>
19+
<input type="button" id="sendBtn" value="Send" disabled>
20+
<br>
1421
</body>
15-
</html>
22+
</html>
23+

examples/web/package-lock.json

+119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)