Compare commits
1025 Commits
Author | SHA1 | Date | |
---|---|---|---|
e4ab5273fc | |||
bf0b3ce1b9 | |||
655175d21e | |||
c85943e916 | |||
1cc7910bf1 | |||
62b435a4aa | |||
9da756bd12 | |||
f5b584f536 | |||
3eb8ab567e | |||
f1a7afb28e | |||
9a7b672d6e | |||
9da58f4343 | |||
ef2e7c609a | |||
d330738b41 | |||
791e6b1e32 | |||
b5884c84fc | |||
236d0e9b33 | |||
ae2cf2f0d1 | |||
238358b5a3 | |||
c0b0917601 | |||
b2d9332fcd | |||
c3e0dbf003 | |||
ac26d90dfb | |||
93e985a541 | |||
686b8c3aa5 | |||
b07ebcffa4 | |||
77dc32da37 | |||
17a649b29b | |||
82e93062d3 | |||
85b0e11cb8 | |||
294a1230b0 | |||
f61ca226fb | |||
10dcf36f3a | |||
ec1a358e66 | |||
42f59cc033 | |||
4609db256f | |||
91c28fec6c | |||
5028598728 | |||
a70afacfda | |||
7226ecb0b5 | |||
9eefc723c2 | |||
33c7518b17 | |||
d34ee67fbf | |||
6e7335e844 | |||
73e8ed7344 | |||
58fbc83df3 | |||
a624b41cee | |||
4cf5f8356a | |||
90c257eab9 | |||
aaa7073deb | |||
6b21637dd5 | |||
e33717e077 | |||
dfc9fdb9b0 | |||
460fe74767 | |||
72eb478b0d | |||
ee37c9bae4 | |||
9f17522230 | |||
50a6832fb3 | |||
fff1912d30 | |||
08a6c5c45b | |||
46f2149bae | |||
1a99ad8e91 | |||
9b36ac3dd3 | |||
09958faa1a | |||
f904063ccd | |||
016aea7805 | |||
4dc0e59309 | |||
31f384f4e0 | |||
84e114ebfc | |||
1c702a1f7f | |||
77448245a0 | |||
412f94dd96 | |||
d5890ecc05 | |||
a4ca6858a1 | |||
ec1b253d6c | |||
b0e1a7989d | |||
67644f4fc7 | |||
f83a03fcad | |||
c8c4f8db64 | |||
5fab9697f1 | |||
52494f4855 | |||
b765cba3d2 | |||
c8ce1c9379 | |||
4f7d7b9515 | |||
ed392f930b | |||
72b29da674 | |||
7e9996a2ff | |||
758f452950 | |||
e7a63577bf | |||
6e70ef35ba | |||
47b95661fa | |||
367cd09195 | |||
9cd01a265f | |||
2935717812 | |||
895fe88a62 | |||
080b8f53f8 | |||
19c91ecadb | |||
3013324e64 | |||
87f71eda79 | |||
41e2f93ab6 | |||
29479d1e91 | |||
abb01d85df | |||
e3ffbc0d01 | |||
e314318e5a | |||
3744b8f09d | |||
f3f8ecfe3b | |||
454d31bd82 | |||
8ab1d80cf8 | |||
4cda5fe27b | |||
38db6d7365 | |||
781d864b9f | |||
8cbcb35bf4 | |||
f76243fb38 | |||
b63ec9cead | |||
aa6f87f467 | |||
eec7a761e8 | |||
3e905f8b04 | |||
125edff298 | |||
0813976a5a | |||
3d6d878354 | |||
068691b9d0 | |||
2fd3f6ad45 | |||
4642504b83 | |||
5b760532c2 | |||
69bcdade50 | |||
bd3df48c0b | |||
faf3158609 | |||
b766be1880 | |||
6b4db006f4 | |||
b3edcfa05c | |||
19e148363c | |||
7f6f178177 | |||
7962069762 | |||
30117bc3a3 | |||
767694a8b8 | |||
ff34858e41 | |||
74f376e246 | |||
40a29fbd55 | |||
7670883b75 | |||
b264774c2a | |||
3d04fb794a | |||
3c9c5bb37b | |||
32c4427b96 | |||
a936fed022 | |||
9d72c1818a | |||
83453635a8 | |||
b8adccc0ec | |||
9f6e99c0a8 | |||
4b5576d30e | |||
2db14a29a9 | |||
5cbbba2e12 | |||
93aef867d0 | |||
2287f6a473 | |||
e99ba3c5d8 | |||
4dcd96d9d3 | |||
4082244eb1 | |||
3e9a769ca1 | |||
3227d58e74 | |||
e37bea360d | |||
f154f3cced | |||
d87be3dd8e | |||
dbee42b099 | |||
54d0cb898d | |||
7880d31126 | |||
0638555fef | |||
dde79d78d4 | |||
65dba2c299 | |||
6ef8f1e1a7 | |||
56dbcaad97 | |||
d748016446 | |||
e543d789a4 | |||
90e59435c0 | |||
785c3b8149 | |||
c37c88543d | |||
011bfbe46f | |||
de2ac6c0c2 | |||
75619babd7 | |||
fe9a34905b | |||
b88f1f5e72 | |||
ab7d7fefe0 | |||
e592fcf217 | |||
10567074c3 | |||
524c56dee9 | |||
efe12f0b73 | |||
82568e3aa0 | |||
7082129b54 | |||
24f8016e4e | |||
98d926a7bf | |||
ffb589d498 | |||
4db6afe9e2 | |||
bdb59905dd | |||
c2b181c6da | |||
3f53365564 | |||
95dfa1015d | |||
1f20f8f1e7 | |||
b2d1a41f7e | |||
9e2e7a7722 | |||
1e02fa34c3 | |||
882c605876 | |||
36a88c605a | |||
09dfc39fd9 | |||
986e5f985f | |||
3e2b0c43ef | |||
557b293934 | |||
7730496bf9 | |||
2b7dc4c529 | |||
b5699239cc | |||
9f3b004756 | |||
8a61043bd7 | |||
93eaa67f5c | |||
690653f8ef | |||
ab392fe0da | |||
669800b39a | |||
4ba8c9e3e8 | |||
1b74ebb0f4 | |||
433d5fbe7f | |||
3204a77e89 | |||
b347afae14 | |||
0482953062 | |||
b5589dbd57 | |||
c23fb10725 | |||
dbfade4eb3 | |||
289b71bc8e | |||
e43c3730a6 | |||
7b206899a4 | |||
c2c57b16df | |||
9805b2fcb5 | |||
569a317bf0 | |||
d262583879 | |||
100669ad0d | |||
7bda5bd77c | |||
52030ca62d | |||
959756526a | |||
1ce27423fe | |||
a0bd65a814 | |||
a7e4b56178 | |||
acaed8ca57 | |||
5728f813d1 | |||
d4d58579d8 | |||
a7620cca16 | |||
61d0cd064f | |||
f5a6342c60 | |||
478f9516cd | |||
08da5e10b2 | |||
c6cd711d74 | |||
4428e3dc3e | |||
fe4afcef85 | |||
03b64e765c | |||
c639174f39 | |||
ce7bd9f4d0 | |||
c4c150a60b | |||
e295fa6072 | |||
470d145a9a | |||
ea12530d30 | |||
329b133383 | |||
e1833cf34b | |||
a0f17cb64b | |||
8a5c38c2d8 | |||
7cddb83ce4 | |||
bb12c071cf | |||
4e3ea69073 | |||
b79c886480 | |||
08da691911 | |||
754568506a | |||
7ac351d1b9 | |||
6d5cecbca1 | |||
fb40e05bab | |||
3710a96fb9 | |||
a1a8ac5203 | |||
4db9f03dd4 | |||
256170adfe | |||
9a4b436e7f | |||
5928b8d206 | |||
1542c78ec5 | |||
cb73fa0c1a | |||
1ceb0fd292 | |||
7c14d940ef | |||
5da67f6ca3 | |||
28a2868edc | |||
3210814648 | |||
1facc8a02f | |||
09818c4ab8 | |||
9e49fcc654 | |||
e6919bdbf8 | |||
749fa32059 | |||
938bd4dd43 | |||
c43e82b8cb | |||
adb733d19a | |||
01085e4492 | |||
43d31caee3 | |||
9aee655fcd | |||
b8b5110653 | |||
e1087ce8b0 | |||
f41baa5c51 | |||
9ee9734473 | |||
3745ff5f7a | |||
3acddc6897 | |||
5d0c62e4bc | |||
06faefd1d6 | |||
4629e57931 | |||
52218272db | |||
f20faed180 | |||
2bae3f62c4 | |||
6eb663d1c5 | |||
a5cc76bb85 | |||
8419de1f1c | |||
e34a3bb8ae | |||
5b66ab2d08 | |||
769f26e94e | |||
31c154e9d9 | |||
a56b036940 | |||
d0e8b63ef0 | |||
d91401775e | |||
735cb538f7 | |||
e23d0723d1 | |||
bb530ef44d | |||
7a219b23d5 | |||
2cde11e9ea | |||
0bbb0233b7 | |||
533beda26a | |||
1427c9e1e4 | |||
6d670726ea | |||
7981fed7f4 | |||
f2caa8048f | |||
92a4ed2a81 | |||
62522d2c25 | |||
3f9565b55d | |||
7a06e48281 | |||
0610bf741f | |||
e79a6f08e3 | |||
4d407cf15e | |||
226e849915 | |||
068fdf60f9 | |||
74ada01114 | |||
cd0be9d510 | |||
b39fe51365 | |||
cf9e57564e | |||
d9aa1818b2 | |||
1d27f5b876 | |||
28e3fad254 | |||
b32a8b884b | |||
7751a9bd6b | |||
3dac651b02 | |||
f6f1efb33f | |||
435d471ad8 | |||
7aa2fdda6f | |||
67e125b22f | |||
f143582de0 | |||
4226a96640 | |||
d305c4c126 | |||
25b3e13d27 | |||
abec5fc219 | |||
684b7ba925 | |||
d8515b6362 | |||
62da885028 | |||
ff2e83bbdc | |||
8f9e8e718e | |||
c6bee7b0d4 | |||
4d93303be8 | |||
1620ddfb03 | |||
452b742adc | |||
244c834992 | |||
ffe202a6a2 | |||
ea87e5ae09 | |||
4259b4e968 | |||
6aff5dc5bc | |||
99bae7f830 | |||
7598d992dc | |||
6380038584 | |||
6144bca0f7 | |||
6ec129f8f8 | |||
be394b7185 | |||
f008b5b447 | |||
5482912e18 | |||
fcc4eaf78b | |||
cca0742973 | |||
495b389e05 | |||
e83494df09 | |||
7bf87c6989 | |||
cb591de15f | |||
eb4540e319 | |||
5d34439cb7 | |||
b19e9077af | |||
4ff010b20b | |||
442e50825c | |||
9f2801b7b9 | |||
3b0bf3a152 | |||
fe4a9ec453 | |||
dc1d14adf1 | |||
14918c16e8 | |||
a023acfa33 | |||
f098019c1f | |||
a67ca9da9b | |||
613ebf2564 | |||
dc6427770c | |||
81e0a05a1a | |||
9ea613f05f | |||
eb4a764648 | |||
baf8a3adce | |||
d9aec59352 | |||
3ff5801512 | |||
fcc2577e11 | |||
b4865f26e4 | |||
fc6d5afdd9 | |||
7a49c0b88b | |||
679c0ccd2e | |||
ee3bc9694b | |||
0c0ba77de5 | |||
8729e0d2aa | |||
12098e7c41 | |||
90eb610bfe | |||
08ddfa1276 | |||
87df64a002 | |||
5af414d0df | |||
2443c72350 | |||
f033e4ab8f | |||
1a6dcdce6f | |||
100039eba8 | |||
e2005c789a | |||
819566b4c1 | |||
82caab8906 | |||
802516b2db | |||
0fcafad9c7 | |||
aab876d346 | |||
11ec8f7247 | |||
1597c9ae6f | |||
b093c4c3d5 | |||
447624322c | |||
422713cbdc | |||
d3d4187021 | |||
f2dd46e589 | |||
5b5debf260 | |||
86c3f914fb | |||
6a1fff13c1 | |||
91a854aa5b | |||
1181fdc599 | |||
fe3d92cebf | |||
c06d77bd8e | |||
c20aebbac2 | |||
9bd12567e6 | |||
bce5faf8ba | |||
64a5d6ecb0 | |||
ed606b7d7e | |||
4a526f66b6 | |||
f8dcfc32ed | |||
cfb10e52e6 | |||
d390c04ca9 | |||
7856ad45fd | |||
fc95b397a6 | |||
db74daae1d | |||
96d6b84c30 | |||
776ff342c0 | |||
519e81727a | |||
2d403247fb | |||
cfddfae1c5 | |||
31b5d6f84a | |||
44bf8b99ef | |||
344895ced1 | |||
9e22770281 | |||
3e2f4a2ac7 | |||
a4fe5cb874 | |||
ece1bd9352 | |||
b7a682cc50 | |||
d47492a54e | |||
fcf33d32a0 | |||
a5eb653064 | |||
ae2abfebad | |||
da4bf1fb49 | |||
82fab04721 | |||
fec3b1ad8b | |||
eb61f6cb3c | |||
fe6cf79f02 | |||
a7bc03c4b3 | |||
06b46aba91 | |||
f83843d054 | |||
e7d45db210 | |||
7a388bdffe | |||
8cb00f81ee | |||
37ebe8cc58 | |||
5eaed06b01 | |||
973f58ec8b | |||
6cb9dd8bad | |||
556104e8d5 | |||
d38ce2b575 | |||
e8628b203f | |||
ffa4e4bb20 | |||
79155d618e | |||
be8ffae0fe | |||
1a723c59aa | |||
6e7c082a7c | |||
037b9c9703 | |||
202d2cb5e4 | |||
03e9eca7d1 | |||
875defd17f | |||
97e23d00be | |||
de47fec19b | |||
c85b9c31fe | |||
be96e8b1fa | |||
2bcdab027c | |||
2eca2c4040 | |||
26cd6e4a59 | |||
be7a6324dd | |||
a7d5ba0232 | |||
3e53706869 | |||
dcb0a0282e | |||
99e78b68a4 | |||
5bb0979c3a | |||
40bed4e740 | |||
8f0c91d1cb | |||
de4192747c | |||
dfe8436954 | |||
7d0d0ea229 | |||
30ca8fb9c3 | |||
4f89e479bc | |||
3faf053bbd | |||
dc91d2cb6d | |||
626ecaa5bb | |||
a88c2dd1bf | |||
ed89fe3e94 | |||
1b73c7fb45 | |||
d563d63c89 | |||
e25bda7108 | |||
12579825a9 | |||
00cccc1e7b | |||
f1fa2abd6e | |||
476528b464 | |||
bc0b14288b | |||
02e4ed5221 | |||
5e876a4686 | |||
3ac3a98e26 | |||
25077878a1 | |||
704d6ab15f | |||
5ce699d33b | |||
e91d721b20 | |||
752c4bf5a1 | |||
bb73da2351 | |||
02105f5da3 | |||
7fac0a7618 | |||
69e5cab0a5 | |||
b220c5df99 | |||
73273d6e81 | |||
61fe8732a6 | |||
9f12c19a02 | |||
72016a7d26 | |||
f40c899b4f | |||
496163dbbe | |||
c0756aaa05 | |||
2cee070cee | |||
5fec28e9b7 | |||
bbec827fef | |||
35e3c7ee3a | |||
0c47c66bb1 | |||
a3cc74c8f1 | |||
db19eded61 | |||
de73af4b80 | |||
3e70af915f | |||
97311230d0 | |||
e966710988 | |||
198d0746b9 | |||
7782f6a5fd | |||
cb71695364 | |||
3af0e3b38b | |||
89e84e7b81 | |||
68bb97b3a3 | |||
41cf60c18b | |||
01eddaca13 | |||
6ec75d7c70 | |||
6221855f27 | |||
a8490f5e1c | |||
55d3336465 | |||
d59c209c20 | |||
46c4bf3ff0 | |||
0227e1c755 | |||
456365bc7c | |||
789ecd7977 | |||
45bbe642fc | |||
2eb523e2ea | |||
5adc62b970 | |||
fcb8d7b3df | |||
1cb53362d1 | |||
0fad9c0a16 | |||
16208d00ca | |||
8dbcd155e5 | |||
46dd2fb515 | |||
129c8b187a | |||
036b972fbe | |||
51bbaa99e1 | |||
37804c0327 | |||
e1f60cd34d | |||
6d6ab9eeb7 | |||
05b7141478 | |||
c3c77010f6 | |||
0a46aa2c6d | |||
e4057c48f6 | |||
d26fa30655 | |||
137d4e3e8e | |||
1a992708a0 | |||
ff76ec1998 | |||
5df78ee3c3 | |||
549e194bb3 | |||
65631f06a6 | |||
3c1b411a76 | |||
8d8374e826 | |||
41194229d3 | |||
fc1f54a0e4 | |||
8fb4997967 | |||
efa6eb8c34 | |||
944e80e85c | |||
2cb3186661 | |||
10d3e2e3d6 | |||
a4afa7382d | |||
efe252dee3 | |||
fd1ca035f9 | |||
62973b6e2f | |||
501fa45560 | |||
1a8d8ec2f9 | |||
b3b4c27bb4 | |||
44eaaf038a | |||
c38edd089b | |||
8ea828f1b0 | |||
35da6636aa | |||
363827594b | |||
cbc027f144 | |||
ebc6a4b65c | |||
37d47d28a8 | |||
46878519c0 | |||
84c298f4f8 | |||
23aed2b844 | |||
df62d6d51c | |||
26241f00b7 | |||
873d14c824 | |||
4953a112ad | |||
c31e1bf0be | |||
98ddba192f | |||
b02b30eea8 | |||
324d97a9b7 | |||
0a1dd4db01 | |||
b1de9acb20 | |||
960300a7cd | |||
3f084d7527 | |||
64096d599c | |||
552e443ef1 | |||
52cb8d68a0 | |||
372e2b7a1f | |||
a92e63720c | |||
8d121c086e | |||
b538e454aa | |||
60d09d5c6f | |||
266159fe41 | |||
458decb12d | |||
635c2e5513 | |||
adc4223617 | |||
326ae27ad1 | |||
6d33d19816 | |||
734efb391a | |||
cba864507f | |||
3432b233ff | |||
ef9bfe811b | |||
949e1de9cd | |||
57c52cf7ae | |||
eaac06546e | |||
9e38d08c0b | |||
47db28617a | |||
de8c4a55cf | |||
08d94e59c7 | |||
e8a6698abd | |||
7348b2b350 | |||
71e5d2bf43 | |||
7188bc9d8d | |||
49180e826e | |||
c6fbbb499f | |||
7b565f0f0e | |||
a7cc637aa2 | |||
824bb93b0a | |||
a99efd27d2 | |||
6266e16644 | |||
edd4fcfcc0 | |||
30dc229477 | |||
d288885a89 | |||
bd19d9d5b4 | |||
a284af2000 | |||
88e8d028b4 | |||
8cab2b9d87 | |||
9b62a543f6 | |||
5a797e1170 | |||
14f8858d3d | |||
62f7642de9 | |||
77475b57b0 | |||
98048a178e | |||
26eb9bf300 | |||
d4ff4a3e0d | |||
488e143e1f | |||
4d5c5ef404 | |||
628742c2f3 | |||
2492a42151 | |||
4a0b6e99d4 | |||
65946fe254 | |||
3286b5c05e | |||
ac8e02604d | |||
dd296e4408 | |||
1be877132c | |||
7e79fd9721 | |||
5d78aecabb | |||
9fbc894fdb | |||
4930e666ac | |||
e5e337a0a5 | |||
704e604b8f | |||
b5d3cdc9b1 | |||
b8b6b913a9 | |||
f461a40a6d | |||
ddf71ffdac | |||
5dd57204dd | |||
9a622a5e44 | |||
42e79ce921 | |||
cdde6ad36e | |||
78769ecde2 | |||
430f6dbb1a | |||
1c01246886 | |||
1f3a0f1ba7 | |||
5622b39ed0 | |||
5e36364145 | |||
75b0b6dcdf | |||
8e5b84ccca | |||
a3b96e1abf | |||
9492a6729e | |||
4ecf9795ee | |||
ada13e21d3 | |||
a1721268a2 | |||
6a876dda49 | |||
6c02e7ed2b | |||
09b8a86d8f | |||
d718447e7a | |||
57cb6b3616 | |||
00e6de2e15 | |||
64e49f6e03 | |||
35933853a4 | |||
d64fa4a7a7 | |||
2857eb3787 | |||
7c9e3c4e57 | |||
5cb124f185 | |||
7489e3851e | |||
d323c40c0a | |||
03a78aaa0c | |||
0e31c1d985 | |||
bab30a06c7 | |||
c7d1c6ed54 | |||
7219b8e999 | |||
d9de5080e5 | |||
649a5d0e88 | |||
8323f6b82c | |||
d16f2b9e2f | |||
a43dbdd1b0 | |||
8f9945b4b9 | |||
d60ec4bf59 | |||
e8a4c859e6 | |||
359c19652b | |||
7ff0e309e5 | |||
b2b7bfe32a | |||
96e978a8e7 | |||
ccbd4497ca | |||
d49035f361 | |||
d289ccecf5 | |||
65d1268082 | |||
d1c798c695 | |||
33ff0cd7cc | |||
6ddba307e6 | |||
f720cbac0c | |||
66e05677e4 | |||
810cafe09b | |||
28e9cd5196 | |||
cc954cc74c | |||
6731e46386 | |||
b608a192c0 | |||
a18e9c50c4 | |||
d836b95c5d | |||
66e9b9dd8b | |||
6c3aaf8a77 | |||
31aac35d2c | |||
f1b680df4a | |||
4e426d75e0 | |||
d4f464bf89 | |||
d90a5d628f | |||
7775f5da4f | |||
f15204c370 | |||
fdea83cdfd | |||
f6be5d6db0 | |||
bc27393e62 | |||
71ebf7a62e | |||
24e502712f | |||
749836b1fe | |||
0b055ac17d | |||
09db03ba02 | |||
9c4428810c | |||
3e559f18d9 | |||
159da088a9 | |||
942152dd8c | |||
c001bb3f9d | |||
3c971e05dd | |||
f4ceaaa31b | |||
e6e03d4cfd | |||
0556abd4ee | |||
3a3df80c2c | |||
ac78ba48d9 | |||
6ed692325f | |||
bf044080e8 | |||
22ffaacc5c | |||
91f4c3699c | |||
07abd640fd | |||
f34d2bb2fe | |||
642861f3be | |||
fcd4228b56 | |||
c03e615483 | |||
fed51f354a | |||
29bc19aa12 | |||
0620de5e62 | |||
672287bbcf | |||
d98a056469 | |||
352f640756 | |||
3f5eecb2e0 | |||
b5f8397936 | |||
9a63919925 | |||
e1a95c2eee | |||
b7e1481621 | |||
3deb50e460 | |||
6e733dab0c | |||
4a1c866117 | |||
9c3b3ffb08 | |||
7e5edd1fa6 | |||
48443e9e95 | |||
152eacc22d | |||
a6d2729556 | |||
3f67a10720 | |||
c0ea85025b | |||
b44f90b87f | |||
498e7246a0 | |||
8b1a67760c | |||
381d0ead1a | |||
d1f77ebb10 | |||
6223967bca | |||
e2c42ff73b | |||
980ee303c8 | |||
2967444678 | |||
35cad4e916 | |||
ccc4d61fd3 | |||
aac9b101d8 | |||
8d9eeda6e5 | |||
5eaee49e1e | |||
68fd331a9c | |||
0bb246785b | |||
0fbdde73e7 | |||
98ea6102b5 | |||
ff702139e4 | |||
0593566ba6 | |||
b325100a7a | |||
e675ada081 | |||
2f8d06db81 | |||
e76d933de2 | |||
7090f2344b | |||
bd06ccbc83 | |||
e2a2040d94 | |||
b6ffa13b72 | |||
726b4c4c33 | |||
9b4c96ee18 | |||
faa03ce100 | |||
fa931aba64 | |||
1fb0d8923b | |||
cfca2f6526 | |||
fe1cc8b040 | |||
327cc9e011 | |||
bbc6307457 | |||
0ebebdc1fd | |||
791916e5c6 | |||
516a8ef848 | |||
f2bf599acb | |||
bdc30fbb56 | |||
a2d1b7eff0 | |||
69b48f50dd | |||
beb3352bf9 | |||
bc6710c4a1 | |||
907e8273c8 | |||
fdbc038d51 | |||
1724c572a5 | |||
54dbb360b7 | |||
803a2076ae | |||
ad54321c7a | |||
503a5d8a51 | |||
610cd85f9d | |||
6a5a5b7db2 | |||
4d7bf99144 | |||
190dc954fd | |||
46efdbe904 | |||
a1fb21eeb6 | |||
cffe3df7ed | |||
8aebe2a8a4 | |||
86f7bd6dba | |||
cc4346a6e8 | |||
0625508348 | |||
cc01baee7f | |||
6f7e59b973 | |||
c93f44f132 | |||
517b69043f | |||
b04db3a744 | |||
36090a24e4 | |||
6b75b3e227 | |||
afed83f5f0 | |||
75c42592bf | |||
b35bfbeb0a | |||
e481e896cb | |||
202467928a | |||
71650ce163 | |||
706a8b7160 | |||
6f419a32ea | |||
f5ff042d62 | |||
822b2e6558 | |||
5b251af1d7 | |||
5b56291b67 | |||
777f5a8dfe | |||
971e6e8b91 | |||
a3fb52c173 | |||
db00253c18 | |||
dd2967b0e1 | |||
cc4e215067 | |||
bbeed01eb0 | |||
aecc2b8fda | |||
d60e18d963 | |||
e41019a1f0 | |||
5825e44fc8 | |||
dc9a8114bc | |||
3e827f9798 | |||
0a6b263bc3 | |||
e02c30027b | |||
c4380ebcc4 | |||
add0649335 | |||
cd28340de3 | |||
c675aedb83 | |||
e32d139056 | |||
a790161168 | |||
2697ef0d76 | |||
5044aedbec | |||
44c90c1cb4 | |||
be79c68540 | |||
226a927df1 | |||
4e1b9bb3c2 | |||
8bc016cc08 | |||
5afbe10d01 | |||
8df07ca68d | |||
884bd2316e | |||
dadecce709 | |||
103935bdd5 | |||
62e6954949 | |||
3ac2d155cc | |||
6d8788c2a1 | |||
603dd01b87 | |||
8091508428 | |||
b38f63f077 | |||
d87539937e | |||
eb09cadded | |||
79e0c62321 | |||
ef38777129 | |||
313f081061 | |||
6108b05e0d | |||
f68601b45f | |||
b94f2ab339 | |||
9c79c8516b | |||
ad03549f8c | |||
5cc8eb1ce6 | |||
d19ff754b2 | |||
fb0f903e2e | |||
6628297580 | |||
ccc05b9999 | |||
fb2f480f92 | |||
cca0ac859a | |||
9fbc7c6ea8 | |||
83d65c805a | |||
0a5cef331d | |||
7c1714f83c | |||
f3024d0552 | |||
bcd1972270 | |||
57501b1739 | |||
cfe8a0e9c6 | |||
10061b3d4b | |||
52959ee700 | |||
0e86d6e3f1 | |||
62675e4c21 | |||
eafe86e4c0 | |||
a2b2126930 | |||
b9a663de75 | |||
f5faeba7b0 | |||
98f02c5195 | |||
d8ab5b4820 | |||
b569e78c02 | |||
4eac16e053 | |||
bb13b4bd37 | |||
aabb435fc7 | |||
3d7764c1e9 | |||
37687c3cd6 | |||
63f10303e0 | |||
d656d739f3 | |||
dbc706b69d | |||
1985088f4f | |||
ccbaa8beda | |||
642d304af9 | |||
df2102497d | |||
ad676815bd | |||
4bd40799fd | |||
4d1d1fa6fe | |||
50f61b19aa | |||
b7dbe7cdd9 | |||
7bfd731ed3 | |||
4da8b8c9a3 | |||
0382067d92 | |||
325230404a | |||
2a721015f8 | |||
5752b17a6f | |||
878d15b746 | |||
26d240e3ba | |||
ca7fc8b26f | |||
35cb9ea4be | |||
ec42736a2f | |||
b4f7c506da | |||
a577bb9004 | |||
bfd858ab13 | |||
18fe326090 | |||
384454b293 | |||
34db6ae673 |
3
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
github: ['paullouisageneau']
|
||||
custom: ['https://paypal.me/paullouisageneau']
|
||||
|
2
.github/dependabot.yml
vendored
@ -1,6 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "examples/web"
|
||||
directory: "examples/signaling-server-nodejs"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
13
.github/workflows/build-gnutls.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Build and test with GnuTLS
|
||||
name: Build with GnuTLS
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
@ -7,16 +7,16 @@ on:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
build-ubuntu:
|
||||
build-linux:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install packages
|
||||
run: sudo apt update && sudo apt install libgnutls28-dev nettle-dev
|
||||
run: sudo apt update && sudo apt install libgnutls28-dev nettle-dev libsrtp2-dev
|
||||
- name: submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: cmake
|
||||
run: cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=1
|
||||
run: cmake -B build -DUSE_GNUTLS=1 -DUSE_SYSTEM_SRTP=1 -DWARNINGS_AS_ERRORS=1
|
||||
- name: make
|
||||
run: (cd build; make -j2)
|
||||
- name: test
|
||||
@ -30,10 +30,7 @@ jobs:
|
||||
- name: submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: cmake
|
||||
run: cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=1
|
||||
env:
|
||||
# hack to bypass EPERM issue on sendto()
|
||||
CFLAGS: -DJUICE_ENABLE_ADDRS_LOCALHOST
|
||||
run: cmake -B build -DUSE_GNUTLS=1 -DWARNINGS_AS_ERRORS=1 -DENABLE_LOCAL_ADDRESS_TRANSLATION=1
|
||||
- name: make
|
||||
run: (cd build; make -j2)
|
||||
- name: test
|
||||
|
20
.github/workflows/build-nice.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Build and test with libnice
|
||||
name: Build with libnice
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
@ -7,7 +7,7 @@ on:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
build-ubuntu:
|
||||
build-media:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@ -16,7 +16,21 @@ jobs:
|
||||
- name: submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: cmake
|
||||
run: cmake -B build -DUSE_JUICE=0 -DUSE_GNUTLS=1
|
||||
run: cmake -B build -DUSE_GNUTLS=1 -DUSE_NICE=1 -DWARNINGS_AS_ERRORS=1
|
||||
- name: make
|
||||
run: (cd build; make -j2)
|
||||
- name: test
|
||||
run: ./build/tests
|
||||
build-no-media:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install packages
|
||||
run: sudo apt update && sudo apt install libgnutls28-dev libnice-dev
|
||||
- name: submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: cmake
|
||||
run: cmake -B build -DUSE_GNUTLS=1 -DUSE_NICE=1 -DNO_MEDIA=1 -DWARNINGS_AS_ERRORS=1
|
||||
- name: make
|
||||
run: (cd build; make -j2)
|
||||
- name: test
|
||||
|
33
.github/workflows/build-openssl.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Build and test with OpenSSL
|
||||
name: Build with OpenSSL
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
@ -7,16 +7,16 @@ on:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
build-ubuntu:
|
||||
build-linux:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install packages
|
||||
run: sudo apt update && sudo apt install libssl-dev
|
||||
run: sudo apt update && sudo apt install libssl-dev libsrtp2-dev
|
||||
- name: submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: cmake
|
||||
run: cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=0
|
||||
run: cmake -B build -DUSE_GNUTLS=0 -DUSE_SYSTEM_SRTP=1 -DWARNINGS_AS_ERRORS=1
|
||||
- name: make
|
||||
run: (cd build; make -j2)
|
||||
- name: test
|
||||
@ -26,17 +26,34 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install packages
|
||||
run: brew reinstall openssl@1.1
|
||||
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew reinstall openssl@1.1
|
||||
- name: submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: cmake
|
||||
run: cmake -B build -DUSE_JUICE=1 -DUSE_GNUTLS=0
|
||||
run: cmake -B build -DUSE_GNUTLS=0 -WARNINGS_AS_ERRORS=1 -DENABLE_LOCAL_ADDRESS_TRANSLATION=1
|
||||
env:
|
||||
OPENSSL_ROOT_DIR: /usr/local/opt/openssl
|
||||
OPENSSL_LIBRARIES: /usr/local/opt/openssl/lib
|
||||
# hack to bypass EPERM issue on sendto()
|
||||
CFLAGS: -DJUICE_ENABLE_ADDRS_LOCALHOST
|
||||
- name: make
|
||||
run: (cd build; make -j2)
|
||||
- name: test
|
||||
run: ./build/tests
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ilammy/msvc-dev-cmd@v1
|
||||
- name: install packages
|
||||
run: choco install openssl
|
||||
- name: submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: cmake
|
||||
run: cmake -B build -G "NMake Makefiles" -DUSE_GNUTLS=0 -WARNINGS_AS_ERRORS=1
|
||||
- name: nmake
|
||||
run: |
|
||||
cd build
|
||||
set CL=/MP
|
||||
nmake
|
||||
- name: test
|
||||
run: build/tests.exe
|
||||
|
||||
|
3
.gitignore
vendored
@ -5,6 +5,7 @@ node_modules/
|
||||
*.a
|
||||
*.so
|
||||
compile_commands.json
|
||||
tests
|
||||
/tests
|
||||
.DS_Store
|
||||
.idea
|
||||
|
||||
|
5
.gitmodules
vendored
@ -1,6 +1,6 @@
|
||||
[submodule "deps/plog"]
|
||||
path = deps/plog
|
||||
url = https://github.com/SergiusTheBest/plog
|
||||
url = https://github.com/SergiusTheBest/plog.git
|
||||
[submodule "usrsctp"]
|
||||
path = deps/usrsctp
|
||||
url = https://github.com/sctplab/usrsctp.git
|
||||
@ -10,3 +10,6 @@
|
||||
[submodule "deps/json"]
|
||||
path = deps/json
|
||||
url = https://github.com/nlohmann/json.git
|
||||
[submodule "deps/libsrtp"]
|
||||
path = deps/libsrtp
|
||||
url = https://github.com/cisco/libsrtp.git
|
||||
|
71
BUILDING.md
Normal file
@ -0,0 +1,71 @@
|
||||
# libdatachannel - Building instructions
|
||||
|
||||
## Clone repository and submodules
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/paullouisageneau/libdatachannel.git
|
||||
$ cd libdatachannel
|
||||
$ git submodule update --init --recursive
|
||||
```
|
||||
|
||||
## Build with CMake
|
||||
|
||||
The CMake library targets `libdatachannel` and `libdatachannel-static` respectively correspond to the shared and static libraries. The default target will build tests and examples. The option `USE_GNUTLS` allows to switch between OpenSSL (default) and GnuTLS, and the option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice.
|
||||
|
||||
If you only need Data Channels, the option `NO_MEDIA` allows to make the library lighter by removing media support. Similarly, `NO_WEBSOCKET` removes WebSocket support.
|
||||
|
||||
### POSIX-compliant operating systems (including Linux and Apple macOS)
|
||||
|
||||
```bash
|
||||
$ cmake -B build -DUSE_GNUTLS=1 -DUSE_NICE=0
|
||||
$ cd build
|
||||
$ make -j2
|
||||
```
|
||||
|
||||
### Apple macOS with XCode project
|
||||
|
||||
```bash
|
||||
$ cmake -B "$BUILD_DIR" -DUSE_GNUTLS=0 -DUSE_NICE=0 -G Xcode
|
||||
```
|
||||
|
||||
Xcode project is generated in *build/* directory.
|
||||
|
||||
#### Solving **Could NOT find OpenSSL** error
|
||||
|
||||
You need to add OpenSSL root directory if your build fails with the following message:
|
||||
|
||||
```
|
||||
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
|
||||
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
|
||||
OPENSSL_INCLUDE_DIR)
|
||||
```
|
||||
|
||||
for example:
|
||||
```bash
|
||||
$ cmake -B build -DUSE_GNUTLS=0 -DUSE_NICE=0 -G Xcode -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl\@1.1/1.1.1h/
|
||||
```
|
||||
|
||||
### Microsoft Windows with MinGW cross-compilation
|
||||
```bash
|
||||
$ cmake -B build -DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-x86_64-w64-mingw32.cmake # replace with your toolchain file
|
||||
$ cd build
|
||||
$ make -j2
|
||||
```
|
||||
|
||||
### Microsoft Windows with Microsoft Visual C++
|
||||
```bash
|
||||
$ cmake -B build -G "NMake Makefiles"
|
||||
$ cd build
|
||||
$ nmake
|
||||
```
|
||||
|
||||
## Build directly with Make (Linux only)
|
||||
|
||||
The option `USE_GNUTLS` allows to switch between OpenSSL (default) and GnuTLS, and the option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice.
|
||||
|
||||
If you only need Data Channels, the option `NO_MEDIA` removes media support. Similarly, `NO_WEBSOCKET` removes WebSocket support.
|
||||
|
||||
```bash
|
||||
$ make USE_GNUTLS=1 USE_NICE=0
|
||||
```
|
||||
|
314
CMakeLists.txt
@ -1,53 +1,68 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(libdatachannel
|
||||
DESCRIPTION "WebRTC DataChannels Library"
|
||||
VERSION 0.6.1
|
||||
VERSION 0.12.3
|
||||
LANGUAGES CXX)
|
||||
set(PROJECT_DESCRIPTION "WebRTC Data Channels Library")
|
||||
|
||||
# Options
|
||||
option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
|
||||
option(USE_JUICE "Use libjuice instead of libnice" OFF)
|
||||
option(RTC_ENABLE_WEBSOCKET "Build WebSocket support" ON)
|
||||
option(USE_NICE "Use libnice instead of libjuice" OFF)
|
||||
option(USE_SYSTEM_SRTP "Use system libSRTP" OFF)
|
||||
option(NO_WEBSOCKET "Disable WebSocket support" OFF)
|
||||
option(NO_MEDIA "Disable media transport support" OFF)
|
||||
option(NO_EXAMPLES "Disable examples" OFF)
|
||||
option(NO_TESTS "Disable tests build" OFF)
|
||||
option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
|
||||
option(CAPI_STDCALL "Set calling convention of C API callbacks stdcall" OFF)
|
||||
|
||||
if(USE_GNUTLS)
|
||||
option(USE_NETTLE "Use Nettle instead of OpenSSL in libjuice" ON)
|
||||
option(USE_NETTLE "Use Nettle in libjuice" ON)
|
||||
else()
|
||||
option(USE_NETTLE "Use Nettle instead of OpenSSL in libjuice" OFF)
|
||||
option(USE_NETTLE "Use Nettle in libjuice" OFF)
|
||||
if(NOT USE_SYSTEM_SRTP)
|
||||
option(ENABLE_OPENSSL "Enable OpenSSL crypto engine for SRTP" ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
|
||||
set(BUILD_SHARED_LIBS OFF) # to force usrsctp to be built static
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||
if (MSVC)
|
||||
if(MSVC)
|
||||
add_definitions(-DNOMINMAX)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(LIBDATACHANNEL_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/candidate.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/certificate.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/channel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/configuration.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/datachannel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/description.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/dtlssrtptransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/dtlstransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/icetransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/init.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/log.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/message.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/peerconnection.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/rtc.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/sctptransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/tls.cpp
|
||||
)
|
||||
|
||||
set(LIBDATACHANNEL_WEBSOCKET_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/base64.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/tcptransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/tlstransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpreceivingsession.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/track.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/websocket.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/wstransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizationconfig.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpsrreporter.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/opusrtppacketizer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/opuspacketizationhandler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/h264rtppacketizer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/nalunit.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/h264packetizationhandler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/mediachainablehandler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/mediahandlerelement.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/mediahandlerrootelement.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpnackresponder.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/capi.cpp
|
||||
)
|
||||
|
||||
set(LIBDATACHANNEL_HEADERS
|
||||
@ -57,63 +72,139 @@ set(LIBDATACHANNEL_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/configuration.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/datachannel.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/description.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/include.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/mediahandler.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpreceivingsession.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/common.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/init.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/log.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/message.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/peerconnection.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/queue.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/reliability.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtc.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtc.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtp.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/track.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/websocket.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtppacketizationconfig.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpsrreporter.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtppacketizer.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/opusrtppacketizer.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/opuspacketizationhandler.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h264rtppacketizer.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/nalunit.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h264packetizationhandler.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/mediachainablehandler.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/mediahandlerelement.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/mediahandlerrootelement.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpnackresponder.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/utils.hpp
|
||||
)
|
||||
|
||||
set(LIBDATACHANNEL_IMPL_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/certificate.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/channel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/datachannel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/dtlssrtptransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/dtlstransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/icetransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/peerconnection.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/logcounter.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/sctptransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/threadpool.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/tls.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/track.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/processor.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/base64.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/tcptransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/tlstransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/verifiedtlstransport.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/websocket.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/wstransport.cpp
|
||||
)
|
||||
|
||||
set(LIBDATACHANNEL_IMPL_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/certificate.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/channel.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/datachannel.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/dtlssrtptransport.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/dtlstransport.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/icetransport.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/peerconnection.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/queue.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/logcounter.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/sctptransport.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/threadpool.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/tls.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/track.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/processor.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/base64.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/tcptransport.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/tlstransport.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/verifiedtlstransport.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/websocket.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/wstransport.hpp
|
||||
)
|
||||
|
||||
set(TESTS_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/connectivity.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/capi.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/turn_connectivity.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/track.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/capi_connectivity.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/capi_track.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/websocket.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/benchmark.cpp
|
||||
)
|
||||
|
||||
set(TESTS_UWP_RESOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/tests/Logo.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/tests/package.appxManifest
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/tests/SmallLogo.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/tests/SmallLogo44x44.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/tests/SplashScreen.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/tests/StoreLogo.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/tests/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
set(BENCHMARK_UWP_RESOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/benchmark/Logo.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/benchmark/package.appxManifest
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/benchmark/SmallLogo.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/benchmark/SmallLogo44x44.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/benchmark/SplashScreen.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/benchmark/StoreLogo.png
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/benchmark/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(SRTP)
|
||||
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)
|
||||
add_subdirectory(deps/plog)
|
||||
|
||||
option(sctp_build_programs 0)
|
||||
option(sctp_build_shared_lib 0)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||
add_subdirectory(deps/usrsctp EXCLUDE_FROM_ALL)
|
||||
if (MSYS OR MINGW)
|
||||
target_compile_definitions(usrsctp PUBLIC -DSCTP_STDINT_INCLUDE=<stdint.h>)
|
||||
target_compile_definitions(usrsctp-static PUBLIC -DSCTP_STDINT_INCLUDE=<stdint.h>)
|
||||
endif()
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(usrsctp PRIVATE -Wno-error=format-truncation)
|
||||
target_compile_options(usrsctp-static PRIVATE -Wno-error=format-truncation)
|
||||
endif()
|
||||
add_library(Usrsctp::Usrsctp ALIAS usrsctp)
|
||||
add_library(Usrsctp::UsrsctpStatic ALIAS usrsctp-static)
|
||||
|
||||
if (RTC_ENABLE_WEBSOCKET)
|
||||
add_library(datachannel SHARED
|
||||
add_library(datachannel SHARED
|
||||
${LIBDATACHANNEL_SOURCES}
|
||||
${LIBDATACHANNEL_WEBSOCKET_SOURCES})
|
||||
add_library(datachannel-static STATIC EXCLUDE_FROM_ALL
|
||||
${LIBDATACHANNEL_HEADERS}
|
||||
${LIBDATACHANNEL_IMPL_SOURCES}
|
||||
${LIBDATACHANNEL_IMPL_HEADERS})
|
||||
add_library(datachannel-static STATIC EXCLUDE_FROM_ALL
|
||||
${LIBDATACHANNEL_SOURCES}
|
||||
${LIBDATACHANNEL_WEBSOCKET_SOURCES})
|
||||
target_compile_definitions(datachannel PUBLIC RTC_ENABLE_WEBSOCKET=1)
|
||||
target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_WEBSOCKET=1)
|
||||
else()
|
||||
add_library(datachannel SHARED
|
||||
${LIBDATACHANNEL_SOURCES})
|
||||
add_library(datachannel-static STATIC EXCLUDE_FROM_ALL
|
||||
${LIBDATACHANNEL_SOURCES})
|
||||
target_compile_definitions(datachannel PUBLIC RTC_ENABLE_WEBSOCKET=0)
|
||||
target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_WEBSOCKET=0)
|
||||
endif()
|
||||
${LIBDATACHANNEL_HEADERS}
|
||||
${LIBDATACHANNEL_IMPL_SOURCES}
|
||||
${LIBDATACHANNEL_IMPL_HEADERS})
|
||||
|
||||
set_target_properties(datachannel PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
@ -126,20 +217,35 @@ target_include_directories(datachannel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includ
|
||||
target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
|
||||
target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
target_link_libraries(datachannel PUBLIC Threads::Threads plog::plog)
|
||||
target_link_libraries(datachannel PRIVATE Usrsctp::UsrsctpStatic)
|
||||
target_link_libraries(datachannel PRIVATE Usrsctp::Usrsctp)
|
||||
|
||||
target_include_directories(datachannel-static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
|
||||
target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
target_link_libraries(datachannel-static PUBLIC Threads::Threads plog::plog)
|
||||
target_link_libraries(datachannel-static PRIVATE Usrsctp::UsrsctpStatic)
|
||||
target_link_libraries(datachannel-static PRIVATE Usrsctp::Usrsctp)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(datachannel PRIVATE wsock32 ws2_32) # winsock2
|
||||
target_link_libraries(datachannel-static PRIVATE wsock32 ws2_32) # winsock2
|
||||
target_link_libraries(datachannel PUBLIC ws2_32) # winsock2
|
||||
target_link_libraries(datachannel-static PUBLIC ws2_32) # winsock2
|
||||
endif()
|
||||
|
||||
if(SRTP_FOUND)
|
||||
if (NO_WEBSOCKET)
|
||||
target_compile_definitions(datachannel PUBLIC RTC_ENABLE_WEBSOCKET=0)
|
||||
target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_WEBSOCKET=0)
|
||||
else()
|
||||
target_compile_definitions(datachannel PUBLIC RTC_ENABLE_WEBSOCKET=1)
|
||||
target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_WEBSOCKET=1)
|
||||
endif()
|
||||
|
||||
if(NO_MEDIA)
|
||||
target_compile_definitions(datachannel PUBLIC RTC_ENABLE_MEDIA=0)
|
||||
target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_MEDIA=0)
|
||||
else()
|
||||
target_compile_definitions(datachannel PUBLIC RTC_ENABLE_MEDIA=1)
|
||||
target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_MEDIA=1)
|
||||
if(USE_SYSTEM_SRTP)
|
||||
find_package(SRTP REQUIRED)
|
||||
if(NOT TARGET SRTP::SRTP)
|
||||
add_library(SRTP::SRTP UNKNOWN IMPORTED)
|
||||
set_target_properties(SRTP::SRTP PROPERTIES
|
||||
@ -147,13 +253,17 @@ if(SRTP_FOUND)
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES C
|
||||
IMPORTED_LOCATION ${SRTP_LIBRARIES})
|
||||
endif()
|
||||
target_compile_definitions(datachannel PUBLIC RTC_ENABLE_MEDIA=1)
|
||||
target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_MEDIA=1)
|
||||
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_SRTP=1)
|
||||
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_SRTP=1)
|
||||
target_link_libraries(datachannel PRIVATE SRTP::SRTP)
|
||||
target_link_libraries(datachannel-static PRIVATE SRTP::SRTP)
|
||||
else()
|
||||
target_compile_definitions(datachannel PUBLIC RTC_ENABLE_MEDIA=0)
|
||||
target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_MEDIA=0)
|
||||
else()
|
||||
add_subdirectory(deps/libsrtp EXCLUDE_FROM_ALL)
|
||||
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_SRTP=0)
|
||||
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_SRTP=0)
|
||||
target_link_libraries(datachannel PRIVATE srtp2)
|
||||
target_link_libraries(datachannel-static PRIVATE srtp2)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (USE_GNUTLS)
|
||||
@ -178,18 +288,23 @@ else()
|
||||
target_link_libraries(datachannel-static PRIVATE OpenSSL::SSL)
|
||||
endif()
|
||||
|
||||
if (USE_JUICE)
|
||||
add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
|
||||
target_compile_definitions(datachannel PRIVATE USE_JUICE=1)
|
||||
target_compile_definitions(datachannel-static PRIVATE USE_JUICE=1)
|
||||
target_link_libraries(datachannel PRIVATE LibJuice::LibJuiceStatic)
|
||||
target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuiceStatic)
|
||||
else()
|
||||
if (USE_NICE)
|
||||
find_package(LibNice REQUIRED)
|
||||
target_compile_definitions(datachannel PRIVATE USE_JUICE=0)
|
||||
target_compile_definitions(datachannel-static PRIVATE USE_JUICE=0)
|
||||
target_compile_definitions(datachannel PRIVATE USE_NICE=1)
|
||||
target_compile_definitions(datachannel-static PRIVATE USE_NICE=1)
|
||||
target_link_libraries(datachannel PRIVATE LibNice::LibNice)
|
||||
target_link_libraries(datachannel-static PRIVATE LibNice::LibNice)
|
||||
else()
|
||||
add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
|
||||
target_compile_definitions(datachannel PRIVATE USE_NICE=0)
|
||||
target_compile_definitions(datachannel-static PRIVATE USE_NICE=0)
|
||||
target_link_libraries(datachannel PRIVATE LibJuice::LibJuiceStatic)
|
||||
target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuiceStatic)
|
||||
endif()
|
||||
|
||||
if(CAPI_STDCALL)
|
||||
target_compile_definitions(datachannel PUBLIC CAPI_STDCALL)
|
||||
target_compile_definitions(datachannel-static PUBLIC CAPI_STDCALL)
|
||||
endif()
|
||||
|
||||
add_library(LibDataChannel::LibDataChannel ALIAS datachannel)
|
||||
@ -198,29 +313,64 @@ add_library(LibDataChannel::LibDataChannelStatic ALIAS datachannel-static)
|
||||
install(TARGETS datachannel LIBRARY DESTINATION lib)
|
||||
install(FILES ${LIBDATACHANNEL_HEADERS} DESTINATION include/rtc)
|
||||
|
||||
# Tests
|
||||
add_executable(datachannel-tests ${TESTS_SOURCES})
|
||||
set_target_properties(datachannel-tests PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
CXX_STANDARD 17)
|
||||
set_target_properties(datachannel-tests PROPERTIES OUTPUT_NAME tests)
|
||||
target_include_directories(datachannel-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
target_link_libraries(datachannel-tests datachannel nlohmann_json::nlohmann_json)
|
||||
if(NOT MSVC)
|
||||
target_compile_options(datachannel PRIVATE -Wall -Wextra)
|
||||
target_compile_options(datachannel-static PRIVATE -Wall -Wextra)
|
||||
endif()
|
||||
|
||||
# Benchmark
|
||||
add_executable(datachannel-benchmark test/benchmark.cpp)
|
||||
set_target_properties(datachannel-benchmark PROPERTIES
|
||||
if(WARNINGS_AS_ERRORS)
|
||||
if(MSVC)
|
||||
target_compile_options(datachannel PRIVATE /WX)
|
||||
target_compile_options(datachannel-static PRIVATE /WX)
|
||||
else()
|
||||
target_compile_options(datachannel PRIVATE -Werror)
|
||||
target_compile_options(datachannel-static PRIVATE -Werror)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Tests
|
||||
if(NOT NO_TESTS)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
# Add resource files needed for UWP apps.
|
||||
add_executable(datachannel-tests ${TESTS_SOURCES} ${TESTS_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-tests ${TESTS_SOURCES})
|
||||
endif()
|
||||
set_target_properties(datachannel-tests PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
CXX_STANDARD 17)
|
||||
set_target_properties(datachannel-benchmark PROPERTIES OUTPUT_NAME benchmark)
|
||||
target_compile_definitions(datachannel-benchmark PRIVATE BENCHMARK_MAIN=1)
|
||||
target_include_directories(datachannel-benchmark PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
target_link_libraries(datachannel-benchmark datachannel)
|
||||
set_target_properties(datachannel-tests PROPERTIES OUTPUT_NAME tests)
|
||||
target_include_directories(datachannel-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
target_link_libraries(datachannel-tests datachannel)
|
||||
|
||||
# Benchmark
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
# Add resource files needed for UWP apps.
|
||||
add_executable(datachannel-benchmark test/benchmark.cpp ${BENCHMARK_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-benchmark test/benchmark.cpp)
|
||||
endif()
|
||||
set_target_properties(datachannel-benchmark PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
CXX_STANDARD 17)
|
||||
set_target_properties(datachannel-benchmark PROPERTIES OUTPUT_NAME benchmark)
|
||||
target_compile_definitions(datachannel-benchmark PRIVATE BENCHMARK_MAIN=1)
|
||||
target_include_directories(datachannel-benchmark PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
target_link_libraries(datachannel-benchmark datachannel)
|
||||
endif()
|
||||
|
||||
# Examples
|
||||
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||
add_subdirectory(deps/json)
|
||||
add_subdirectory(examples/client)
|
||||
add_subdirectory(examples/copy-paste)
|
||||
add_subdirectory(examples/copy-paste-capi)
|
||||
if(NOT NO_EXAMPLES)
|
||||
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||
add_subdirectory(deps/json)
|
||||
add_subdirectory(examples/client)
|
||||
add_subdirectory(examples/client-benchmark)
|
||||
if(NOT NO_MEDIA)
|
||||
add_subdirectory(examples/media)
|
||||
add_subdirectory(examples/sfu-media)
|
||||
add_subdirectory(examples/streamer)
|
||||
endif()
|
||||
add_subdirectory(examples/copy-paste)
|
||||
add_subdirectory(examples/copy-paste-capi)
|
||||
endif()
|
||||
|
||||
|
648
DOC.md
Normal file
@ -0,0 +1,648 @@
|
||||
# libdatachannel - C API Documentation
|
||||
|
||||
The following details the C API of libdatachannel. The C API is available by including the `rtc/rtc.h` header.
|
||||
|
||||
### General considerations
|
||||
|
||||
Unless stated otherwise, functions return `RTC_ERR_SUCCESS`, defined as `0`, on success.
|
||||
|
||||
All functions can return the following negative error codes:
|
||||
- `RTC_ERR_INVALID`: an invalid argument was provided
|
||||
- `RTC_ERR_FAILURE`: a runtime error happened
|
||||
- `RTC_ERR_NOT_AVAIL`: an element is not available at the moment
|
||||
- `RTC_ERR_TOO_SMALL`: a user-provided buffer is too small
|
||||
|
||||
All functions taking pointers as arguments (excepted the opaque user pointer) need the memory to be accessible until the call returns, but it can be safely discarded afterwards.
|
||||
|
||||
### Common
|
||||
|
||||
#### rtcInitLogger
|
||||
|
||||
```
|
||||
void rtcInitLogger(rtcLogLevel level, rtcLogCallbackFunc cb)
|
||||
```
|
||||
|
||||
Arguments:
|
||||
- `level`: the log level. It must be one of the following: `RTC_LOG_NONE`, `RTC_LOG_FATAL`, `RTC_LOG_ERROR`, `RTC_LOG_WARNING`, `RTC_LOG_INFO`, `RTC_LOG_DEBUG`, `RTC_LOG_VERBOSE`.
|
||||
- `cb` (optional): the callback to pass the log lines to. If the callback is already set, it is replaced. If NULL after a callback is set, the callback is unset. If NULL on first call, the library will log to stdout instead.
|
||||
|
||||
`cb` must have the following signature:
|
||||
`void myLogCallback(rtcLogLevel level, const char *message)`
|
||||
|
||||
Arguments:
|
||||
- `level`: the log level for the current message. It will be one of the following: `RTC_LOG_FATAL`, `RTC_LOG_ERROR`, `RTC_LOG_WARNING`, `RTC_LOG_INFO`, `RTC_LOG_DEBUG`, `RTC_LOG_VERBOSE`.
|
||||
- `message`: a null-terminated string containing the log message
|
||||
|
||||
#### rtcPreload
|
||||
|
||||
```
|
||||
void rtcPreload(void)
|
||||
```
|
||||
|
||||
An optional call to `rtcPreload` preloads the global resources used by the library. If it is not called, resources are lazy-loaded when they are required for the first time by a PeerConnection, which for instance prevents from properly timing connection establishment (as the first one will take way more time). The call blocks until preloading is finished. If resources are already loaded, the call has no effect.
|
||||
|
||||
#### rtcCleanup
|
||||
|
||||
```
|
||||
void rtcCleanup(void)
|
||||
```
|
||||
|
||||
An optional call to `rtcCleanup` requests unloading of the global resources used by the library. If all created PeerConnections are deleted, unloading will happen immediately and the call will block until unloading is done, otherwise unloading will happen as soon as the last PeerConnection is deleted. If resources are already unloaded, the call has no effect.
|
||||
|
||||
#### rtcSetUserPointer
|
||||
|
||||
```
|
||||
void rtcSetUserPointer(int id, void *user_ptr)
|
||||
```
|
||||
|
||||
Sets a opaque user pointer for a Peer Connection, Data Channel, Track, or WebSocket. The user pointer will be passed as last argument in each corresponding callback. It will never be accessed in any way. The initial user pointer of a Peer Connection or WebSocket is `NULL`, and the initial one of a Data Channel or Track is the one of the Peer Connection at the time of creation.
|
||||
|
||||
Arguments:
|
||||
- `id`: the identifier of Peer Connection, Data Channel, Track, or WebSocket
|
||||
- `user_ptr`: an opaque pointer whose meaning is up to the user
|
||||
|
||||
### PeerConnection
|
||||
|
||||
#### rtcCreatePeerConnection
|
||||
|
||||
```
|
||||
int rtcCreatePeerConnection(const rtcConfiguration *config)
|
||||
|
||||
typedef struct {
|
||||
const char **iceServers;
|
||||
int iceServersCount;
|
||||
rtcCertificateType certificateType;
|
||||
bool enableIceTcp;
|
||||
bool disableAutoNegotiation;
|
||||
uint16_t portRangeBegin;
|
||||
uint16_t portRangeEnd;
|
||||
int mtu;
|
||||
} rtcConfiguration;
|
||||
```
|
||||
|
||||
Creates a Peer Connection.
|
||||
|
||||
Arguments:
|
||||
- `config`: the configuration structure, containing:
|
||||
- `iceServers` (optional): an array of pointers on null-terminated ice server URIs (NULL if unused)
|
||||
- `iceServersCount` (optional): number of URLs in the array pointed by `iceServers` (0 if unused)
|
||||
- `certificateType` (optional): certificate type, either `RTC_CERTIFICATE_ECDSA` or `RTC_CERTIFICATE_RSA` (0 or `RTC_CERTIFICATE_DEFAULT` if default)
|
||||
- `enableIceTcp`: if true, generate TCP candidates for ICE (ignored with libjuice as ICE backend)
|
||||
- `disableAutoNegotiation`: if true, the user is responsible for calling `rtcSetLocalDescription` after creating a Data Channel and after setting the remote description
|
||||
- `portRangeBegin` (optional): first port (included) of the allowed local port range (0 if unused)
|
||||
- `portRangeEnd` (optional): last port (included) of the allowed local port (0 if unused)
|
||||
- `mtu` (optional): manually set the Maximum Transfer Unit (MTU) for the connection (0 if automatic)
|
||||
- `maxMessageSize` (optional): manually set the local maximum message size for Data Channels (0 if default)
|
||||
|
||||
Return value: the identifier of the new Peer Connection or a negative error code.
|
||||
|
||||
The Peer Connection must be deleted with `rtcDeletePeerConnection`.
|
||||
|
||||
The format of each entry in `iceServers` must match the format `[("stun"|"turn"|"turns") ":"][login ":" password "@"]hostname[":" port]["?transport=" ("udp"|"tcp"|"tls")]`. The default scheme is STUN, the default port is 3478 (5349 over TLS), and the default transport is UDP. For instance, a STUN server URI could be `mystunserver.org`, and a TURN server URI could be `turn:myuser:12345678@turnserver.org`. Note transports TCP and TLS are only available for a TURN server with libnice as ICE backend and govern only the TURN control connection, meaning relaying is always performed over UDP.
|
||||
|
||||
#### rtcDeletePeerConnection
|
||||
|
||||
```
|
||||
int rtcDeletePeerConnection(int pc)
|
||||
```
|
||||
|
||||
Deletes the specified Peer Connection.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
|
||||
Return value: `RTC_ERR_SUCCESS` or a negative error code
|
||||
|
||||
After this function has been called, `pc` must not be used in a function call anymore. This function will block until all scheduled callbacks of `pc` return (except the one this function might be called in) and no other callback will be called for `pc` after it returns.
|
||||
|
||||
#### rtcSetXCallback
|
||||
|
||||
These functions set, change, or unset (if `cb` is `NULL`) the different callbacks of a Peer Connection.
|
||||
|
||||
```
|
||||
int rtcSetLocalDescriptionCallback(int pc, rtcDescriptionCallbackFunc cb)*
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myDescriptionCallback(int pc, const char *sdp, const char *type, void *user_ptr)`
|
||||
|
||||
```
|
||||
int rtcSetLocalCandidateCallback(int pc, rtcCandidateCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myCandidateCallback(int pc, const char *cand, const char *mid, void *user_ptr)`
|
||||
|
||||
```
|
||||
int rtcSetStateChangeCallback(int pc, rtcStateChangeCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myStateChangeCallback(int pc, rtcState state, void *user_ptr)`
|
||||
|
||||
`state` will be one of the following: `RTC_CONNECTING`, `RTC_CONNECTED`, `RTC_DISCONNECTED`, `RTC_FAILED`, or `RTC_CLOSED`.
|
||||
|
||||
```
|
||||
int rtcSetGatheringStateChangeCallback(int pc, rtcGatheringStateCallbackFunc cb)
|
||||
```
|
||||
|
||||
`void myGatheringStateCallback(int pc, rtcGatheringState state, void *user_ptr)`
|
||||
|
||||
`state` will be `RTC_GATHERING_INPROGRESS` or `RTC_GATHERING_COMPLETE`.
|
||||
|
||||
```
|
||||
int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myDataChannelCallback(int pc, int dc, void *user_ptr)`
|
||||
|
||||
```
|
||||
int rtcSetTrackCallback(int pc, rtcTrackCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myTrackCallback(int pc, int tr, void *user_ptr)`
|
||||
|
||||
#### rtcSetLocalDescription
|
||||
|
||||
```
|
||||
int rtcSetLocalDescription(int pc, const char *type)
|
||||
```
|
||||
|
||||
Initiates the handshake process. Following this call, the local description callback will be called with the local description, which must be sent to the remote peer by the user's method of choice. Note this call is implicit after `rtcSetRemoteDescription` and `rtcCreateDataChannel` if `disableAutoNegotiation` was not set on Peer Connection creation.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for autodetection.
|
||||
|
||||
#### rtcSetRemoteDescription
|
||||
|
||||
```
|
||||
int rtcSetRemoteDescription(int pc, const char *sdp, const char *type)
|
||||
```
|
||||
|
||||
Sets the remote description received from the remote peer by the user's method of choice. The remote description may have candidates or not.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for autodetection.
|
||||
|
||||
If the remote description is an offer and `disableAutoNegotiation` was not set in `rtcConfiguration`, the library will automatically answer by calling `rtcSetLocalDescription` internally. Otherwise, the user must call it to answer the remote description.
|
||||
|
||||
#### rtcAddRemoteCandidate
|
||||
|
||||
```
|
||||
int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid)
|
||||
```
|
||||
|
||||
Adds a trickled remote candidate received from the remote peer by the user's method of choice.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `cand`: a null-terminated SDP string representing the candidate (with or without the `"a="` prefix)
|
||||
- `mid` (optional): a null-terminated string representing the mid of the candidate in the remote SDP description or NULL for autodetection
|
||||
|
||||
The Peer Connection must have a remote description set.
|
||||
|
||||
Return value: `RTC_ERR_SUCCESS` or a negative error code
|
||||
|
||||
#### rtcGetLocalDescription
|
||||
|
||||
```
|
||||
int rtcGetLocalDescription(int pc, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the current local description in SDP format.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `buffer`: a user-supplied buffer to store the description
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the description is not copied but the size is still returned.
|
||||
|
||||
#### rtcGetRemoteDescription
|
||||
|
||||
```
|
||||
int rtcGetRemoteDescription(int pc, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the current remote description in SDP format.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `buffer`: a user-supplied buffer to store the description
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the description is not copied but the size is still returned.
|
||||
|
||||
#### rtcGetLocalDescriptionType
|
||||
|
||||
```
|
||||
int rtcGetLocalDescriptionType(int pc, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the current local description type as string.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `buffer`: a user-supplied buffer to store the type
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the description is not copied but the size is still returned.
|
||||
|
||||
#### rtcGetRemoteDescription
|
||||
|
||||
```
|
||||
int rtcGetRemoteDescriptionType(int pc, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the current remote description type as string.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `buffer`: a user-supplied buffer to store the type
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the description is not copied but the size is still returned.
|
||||
|
||||
|
||||
#### rtcGetLocalAddress
|
||||
|
||||
```
|
||||
int rtcGetLocalAddress(int pc, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the current local address, i.e. the network address of the currently selected local candidate. The address will have the format `"IP_ADDRESS:PORT"`, where `IP_ADDRESS` may be either IPv4 or IPv6. The call might fail if the PeerConnection is not in state `RTC_CONNECTED`, and the address might change if the state is not `RTC_COMPLETED`.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `buffer`: a user-supplied buffer to store the address
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the address is not copied but the size is still returned.
|
||||
|
||||
#### rtcGetRemoteAddress
|
||||
|
||||
```
|
||||
int rtcGetRemoteAddress(int pc, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the current remote address, i.e. the network address of the currently selected remote candidate. The address will have the format `"IP_ADDRESS:PORT"`, where `IP_ADDRESS` may be either IPv4 or IPv6. The call may fail if the state is not `RTC_CONNECTED`, and the address might change if the state is not `RTC_COMPLETED`.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `buffer`: a user-supplied buffer to store the address
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the address is not copied but the size is still returned.
|
||||
|
||||
#### rtcGetSelectedCandidatePair
|
||||
|
||||
```
|
||||
int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote, int remoteSize)
|
||||
```
|
||||
|
||||
Retrieve the currently selected candidate pair. The call may fail if the state is not `RTC_CONNECTED`, and the selected candidate pair might change if the state is not `RTC_COMPLETED`.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `local`: a user-supplied buffer to store the local candidate
|
||||
- `localSize`: the size of `local`
|
||||
- `remote`: a user-supplied buffer to store the remote candidate
|
||||
- `remoteSize`: the size of `remote`
|
||||
|
||||
Return value: the maximun length of strings copied in buffers (including the terminating null character) or a negative error code
|
||||
|
||||
If `local`, `remote`, or both, are `NULL`, the corresponding candidate is not copied, but the maximum length is still returned.
|
||||
|
||||
### Data Channel
|
||||
|
||||
#### rtcCreateDataChannel
|
||||
|
||||
```
|
||||
int rtcCreateDataChannel(int pc, const char *label)
|
||||
int rtcCreateDataChannelEx(int pc, const char *label, const rtcDataChannelInit *init)
|
||||
|
||||
typedef struct {
|
||||
bool unordered;
|
||||
bool unreliable;
|
||||
unsigned int maxPacketLifeTime;
|
||||
unsigned int maxRetransmits;
|
||||
} rtcReliability;
|
||||
|
||||
typedef struct {
|
||||
rtcReliability reliability;
|
||||
const char *protocol;
|
||||
bool negotiated;
|
||||
bool manualStream;
|
||||
uint16_t stream;
|
||||
} rtcDataChannelInit;
|
||||
```
|
||||
|
||||
Adds a Data Channel on a Peer Connection. The Peer Connection does not need to be connected, however, the Data Channel will be open only when the Peer Connection is connected.
|
||||
|
||||
Arguments:
|
||||
- `pc`: identifier of the PeerConnection on which to add a Data Channel
|
||||
- `label`: a user-defined UTF-8 string representing the Data Channel name
|
||||
- `init`: a structure of initialization settings containing:
|
||||
- `reliability`: a structure of reliability settings containing:
|
||||
- `bool unordered`: if `true`, the Data Channel will not enforce message ordering, else it will be ordered
|
||||
- `bool unreliable`: if `true`, the Data Channel will not enforce strict reliability, else it will be reliable
|
||||
- `unsigned int maxPacketLifeTime`: if unreliable, maximum packet life time in milliseconds
|
||||
- `unsigned int maxRetransmits`: if unreliable and maxPacketLifeTime is 0, maximum number of retransmissions (0 means no retransmission)
|
||||
- `protocol` (optional): a user-defined UTF-8 string representing the Data Channel protocol, empty if NULL
|
||||
- `negotiated`: if `true`, the Data Channel is assumed to be negotiated by the user and won't be negotiated by the WebRTC layer
|
||||
- `manualStream`: if `true`, the Data Channel will use `stream` as stream ID, else an available id is automatically selected
|
||||
- `stream` (0-65534): if `manualStream` is `true`, the Data Channel will use it as stream ID, else it is ignored
|
||||
|
||||
`rtcDataChannel()` is equivalent to `rtcDataChannelEx()` with settings set to ordered, reliable, non-negotiated, with automatic stream ID selection (all flags set to `false`), and `protocol` set to an empty string.
|
||||
|
||||
Return value: the identifier of the new Data Channel or a negative error code.
|
||||
|
||||
The Data Channel must be deleted with `rtcDeleteDataChannel`.
|
||||
|
||||
If `disableAutoNegotiation` was not set in `rtcConfiguration`, the library will automatically initiate the negotiation by calling `rtcSetLocalDescription` internally. Otherwise, the user must call `rtcSetLocalDescription` to initiate the negotiation after creating the first Data Channel.
|
||||
|
||||
#### rtcDeleteDataChannel
|
||||
|
||||
```
|
||||
int rtcDeleteDataChannel(int dc)
|
||||
```
|
||||
|
||||
Deletes a Data Channel.
|
||||
|
||||
Arguments:
|
||||
- `dc`: the Data Channel identifier
|
||||
|
||||
After this function has been called, `dc` must not be used in a function call anymore. This function will block until all scheduled callbacks of `dc` return (except the one this function might be called in) and no other callback will be called for `dc` after it returns.
|
||||
|
||||
#### rtcGetDataChannelStream
|
||||
|
||||
```
|
||||
int rtcGetDataChannelStream(int dc)
|
||||
```
|
||||
|
||||
Retrieves the stream ID of the Data Channel.
|
||||
|
||||
Arguments:
|
||||
- `dc`: the Data Channel identifier
|
||||
|
||||
Return value: the stream ID (0-65534) or a negative error code
|
||||
|
||||
#### rtcGetDataChannelLabel
|
||||
|
||||
```
|
||||
int rtcGetDataChannelLabel(int dc, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the label of a Data Channel.
|
||||
|
||||
Arguments:
|
||||
- `dc`: the Data Channel identifier
|
||||
- `buffer`: a user-supplied buffer to store the label
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the label is not copied but the size is still returned.
|
||||
|
||||
#### rtcGetDataChannelProtocol
|
||||
|
||||
```
|
||||
int rtcGetDataChannelProtocol(int dc, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the protocol of a Data Channel.
|
||||
|
||||
Arguments:
|
||||
- `dc`: the Data Channel identifier
|
||||
- `buffer`: a user-supplied buffer to store the protocol
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the protocol is not copied but the size is still returned.
|
||||
|
||||
#### rtcGetDataChannelReliability
|
||||
|
||||
```
|
||||
int rtcGetDataChannelReliability(int dc, rtcReliability *reliability)
|
||||
```
|
||||
|
||||
Retrieves the reliability settings of a Data Channel. The function may be called irrelevant of how the Data Channel was created.
|
||||
|
||||
Arguments:
|
||||
- `dc`: the Data Channel identifier
|
||||
- `reliability` a user-supplied structure to fill
|
||||
|
||||
Return value: `RTC_ERR_SUCCESS` or a negative error code
|
||||
|
||||
### Track
|
||||
|
||||
#### rtcAddTrack
|
||||
|
||||
```
|
||||
int rtcAddTrack(int pc, const char *mediaDescriptionSdp)
|
||||
```
|
||||
|
||||
Adds a new Track on a Peer Connection. The Peer Connection does not need to be connected, however, the Track will be open only when the Peer Connection is connected.
|
||||
|
||||
Arguments:
|
||||
- `pc`: the Peer Connection identifier
|
||||
- `mediaDescriptionSdp`: a null-terminated string specifying the corresponding media SDP. It must start with a m-line and include a mid parameter.
|
||||
|
||||
Return value: the identifier of the new Track or a negative error code
|
||||
|
||||
The new track must be deleted with `rtcDeleteTrack`.
|
||||
|
||||
The user must call `rtcSetLocalDescription` to negotiate the track.
|
||||
|
||||
#### rtcDeleteTrack
|
||||
|
||||
```
|
||||
int rtcDeleteTrack(int tr)
|
||||
```
|
||||
|
||||
Deletes a Track.
|
||||
|
||||
Arguments:
|
||||
- `tr`: the Track identifier
|
||||
|
||||
After this function has been called, `tr` must not be used in a function call anymore. This function will block until all scheduled callbacks of `tr` return (except the one this function might be called in) and no other callback will be called for `tr` after it returns.
|
||||
|
||||
#### rtcGetTrackDescription
|
||||
|
||||
```
|
||||
int rtcGetTrackDescription(int tr, char *buffer, int size)
|
||||
```
|
||||
|
||||
Retrieves the SDP media description of a Track.
|
||||
|
||||
Arguments:
|
||||
- `dc`: the Track identifier
|
||||
- `buffer`: a user-supplied buffer to store the description
|
||||
- `size`: the size of `buffer`
|
||||
|
||||
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
|
||||
|
||||
If `buffer` is `NULL`, the description is not copied but the size is still returned.
|
||||
|
||||
### WebSocket
|
||||
|
||||
#### rtcCreateWebSocket
|
||||
|
||||
```
|
||||
int rtcCreateWebSocket(const char *url)
|
||||
int rtcCreateWebSocketEx(const char *url, const rtcWsConfiguration *config)
|
||||
```
|
||||
|
||||
Creates a new client WebSocket.
|
||||
|
||||
Arguments:
|
||||
- `url`: a null-terminated string representing the fully-qualified URL to open.
|
||||
- `config`: a structure with the following parameters:
|
||||
- `bool disableTlsVerification`: if true, don't verify the TLS certificate, else try to verify it if possible
|
||||
|
||||
Return value: the identifier of the new WebSocket or a negative error code
|
||||
|
||||
The new WebSocket must be deleted with `rtcDeleteWebSocket`. The scheme of the URL must be either `ws` or `wss`.
|
||||
|
||||
#### rtcDeleteWebSocket
|
||||
|
||||
```
|
||||
int rtcDeleteWebSocket(int ws)
|
||||
```
|
||||
|
||||
Arguments:
|
||||
- `ws`: the identifier of the WebSocket to delete
|
||||
|
||||
Return value: the identifier of the new WebSocket or a negative error code
|
||||
|
||||
After this function has been called, `ws` must not be used in a function call anymore. This function will block until all scheduled callbacks of `ws` return (except the one this function might be called in) and no other callback will be called for `ws` after it returns.
|
||||
|
||||
### Channel (Data Channel, Track, and WebSocket)
|
||||
|
||||
The following common functions might be called with a generic channel identifier. It may be the identifier of either a Data Channel, a Track, or a WebSocket.
|
||||
|
||||
#### rtcSetXCallback
|
||||
|
||||
These functions set, change, or unset (if `cb` is `NULL`) the different callbacks of a channel.
|
||||
|
||||
```
|
||||
int rtcSetOpenCallback(int id, rtcOpenCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myOpenCallback(int id, void *user_ptr)`
|
||||
|
||||
```
|
||||
int rtcSetClosedCallback(int id, rtcClosedCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myClosedCallback(int id, void *user_ptr)`
|
||||
|
||||
```
|
||||
int rtcSetErrorCallback(int id, rtcErrorCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myErrorCallback(int id, const char *error, void *user_ptr)`
|
||||
|
||||
```
|
||||
int rtcSetMessageCallback(int id, rtcMessageCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myMessageCallback(int id, const char *message, int size, void *user_ptr)`
|
||||
|
||||
```
|
||||
int rtcSetBufferedAmountLowCallback(int id, rtcBufferedAmountLowCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myBufferedAmountLowCallback(int id, void *user_ptr)`
|
||||
|
||||
```
|
||||
int rtcSetAvailableCallback(int id, rtcAvailableCallbackFunc cb)
|
||||
```
|
||||
|
||||
`cb` must have the following signature: `void myAvailableCallback(int id, void *user_ptr)`
|
||||
|
||||
#### rtcSendMessage
|
||||
|
||||
```
|
||||
int rtcSendMessage(int id, const char *data, int size)
|
||||
```
|
||||
|
||||
Arguments:
|
||||
- `id`: the channel identifier
|
||||
- `data`: the message data
|
||||
- `size`: if size >= 0, `data` is interpreted as a binary message of length `size`, otherwise it is interpreted as a null-terminated UTF-8 string.
|
||||
|
||||
Return value: `RTC_ERR_SUCCESS` or a negative error code
|
||||
|
||||
Sends a message immediately if possible.
|
||||
|
||||
Data Channel and WebSocket: If the message may not be sent immediately due to flow control or congestion control, it is buffered until it can actually be sent. You can retrieve the current buffered data size with `rtcGetBufferedAmount`.
|
||||
Tracks are an exception: There is no flow or congestion control, messages are never buffered and `rtcGetBufferedAmount` always returns 0.
|
||||
|
||||
#### rtcGetBufferedAmount
|
||||
|
||||
```
|
||||
int rtcGetBufferedAmount(int id)
|
||||
```
|
||||
|
||||
Retrieves the current buffered amount, i.e. the total size of currently buffered messages waiting to be actually sent in the channel. This does not account for the data buffered at the transport level.
|
||||
|
||||
Return value: the buffered amount or a negative error code
|
||||
|
||||
#### rtcGetBufferedAmountLowThreshold
|
||||
|
||||
```
|
||||
int rtcSetBufferedAmountLowThreshold(int id, int amount)
|
||||
```
|
||||
|
||||
Changes the buffered amount threshold under which `BufferedAmountLowCallback` is called. The callback is called when the buffered amount was strictly superior and gets equal to or lower than the threshold when a message is sent. The initial threshold is 0, meaning the the callback is called each time the buffered amount goes back to zero after being non-zero.
|
||||
|
||||
Arguments:
|
||||
- `id`: the channel identifier
|
||||
- `amount`: the new buffer level threshold
|
||||
|
||||
Return value: the identifier of the new WebSocket or a negative error code
|
||||
|
||||
#### rtcReceiveMessage
|
||||
|
||||
```
|
||||
int rtcReceiveMessage(int id, char *buffer, int *size)
|
||||
```
|
||||
|
||||
Receives a pending message if possible. The function may only be called if `MessageCallback` is not set.
|
||||
|
||||
Arguments:
|
||||
- `id`: the channel identifier
|
||||
- `buffer`: a user-supplied buffer where to write the message data
|
||||
- `size`: a pointer to a user-supplied int which must be initialized to the size of `buffer`. On success, the function will write the size of the message to it before returning.
|
||||
|
||||
Return value: `RTC_ERR_SUCCESS` or a negative error code (In particular, `RTC_ERR_NOT_AVAIL` is returned when there are no pending messages)
|
||||
|
||||
If `buffer` is `NULL`, the message is not copied and kept pending but the size is still written to `size`.
|
||||
|
||||
#### rtcGetAvailableAmount
|
||||
|
||||
```
|
||||
int rtcGetAvailableAmount(int id)
|
||||
```
|
||||
|
||||
Retrieves the available amount, i.e. the total size of messages pending reception with `rtcReceiveMessage`. The function may only be called if `MessageCallback` is not set.
|
||||
|
||||
Arguments:
|
||||
- `id`: the channel identifier
|
||||
|
||||
Return value: the available amount or a negative error code
|
||||
|
||||
|
247
Jamfile
@ -3,34 +3,45 @@ import feature : feature ;
|
||||
project libdatachannel ;
|
||||
path-constant CWD : . ;
|
||||
|
||||
lib libdatachannel
|
||||
: # sources
|
||||
[ glob ./src/*.cpp ]
|
||||
: # requirements
|
||||
<cxxstd>17
|
||||
<include>./include/rtc
|
||||
<define>USE_JUICE=1
|
||||
<define>RTC_ENABLE_MEDIA=0
|
||||
<define>RTC_ENABLE_WEBSOCKET=0
|
||||
<library>/libdatachannel//usrsctp
|
||||
<library>/libdatachannel//juice
|
||||
<library>/libdatachannel//plog
|
||||
: # default build
|
||||
<link>static
|
||||
: # usage requirements
|
||||
<include>./include
|
||||
<library>/libdatachannel//plog
|
||||
<cxxflags>-pthread
|
||||
<toolset>gcc:<cxxflags>"-Wno-pedantic -Wno-unused-parameter -Wno-unused-variable"
|
||||
<toolset>clang:<cxxflags>"-Wno-pedantic -Wno-unused-parameter -Wno-unused-variable"
|
||||
;
|
||||
|
||||
feature gnutls : off on : composite propagated ;
|
||||
feature.compose <gnutls>off
|
||||
: <define>USE_GNUTLS=0 ;
|
||||
feature.compose <gnutls>on
|
||||
: <define>USE_GNUTLS=1 ;
|
||||
|
||||
lib libdatachannel
|
||||
: # sources
|
||||
[ glob ./src/*.cpp ]
|
||||
[ glob ./src/impl/*.cpp ]
|
||||
: # requirements
|
||||
<cxxstd>17
|
||||
<include>./include
|
||||
<include>./include/rtc
|
||||
<include>./src
|
||||
<define>RTC_ENABLE_MEDIA=0
|
||||
<define>RTC_ENABLE_WEBSOCKET=0
|
||||
<define>USE_NICE=0
|
||||
<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
|
||||
<toolset>msvc:<define>NOMINMAX
|
||||
<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
|
||||
<toolset>msvc:<define>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
|
||||
<library>/libdatachannel//usrsctp
|
||||
<library>/libdatachannel//juice
|
||||
<library>/libdatachannel//plog
|
||||
<gnutls>on:<library>gnutls/<link>shared
|
||||
<gnutls>off:<library>ssl
|
||||
<gnutls>off:<library>crypto
|
||||
: # default build
|
||||
<link>static
|
||||
: # usage requirements
|
||||
<include>./include
|
||||
<define>RTC_ENABLE_MEDIA=0
|
||||
<define>RTC_ENABLE_WEBSOCKET=0
|
||||
<library>/libdatachannel//plog
|
||||
<toolset>gcc:<cxxflags>"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable"
|
||||
<toolset>clang:<cxxflags>"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable"
|
||||
;
|
||||
|
||||
alias plog
|
||||
: # no sources
|
||||
: # no build requirements
|
||||
@ -48,41 +59,205 @@ alias usrsctp
|
||||
<library>libusrsctp.a
|
||||
;
|
||||
|
||||
alias usrsctp
|
||||
: # no sources
|
||||
: <toolset>msvc
|
||||
: # no default build
|
||||
: # usage requirements
|
||||
<include>./deps/usrsctp/usrsctplib
|
||||
<library>usrsctp.lib
|
||||
;
|
||||
|
||||
alias juice
|
||||
: # no sources
|
||||
: # no build requirements
|
||||
: # no default build
|
||||
: # usage requirements
|
||||
<include>./deps/libjuice/include
|
||||
<library>libjuice.a
|
||||
<gnutls>on:<library>libjuice-gnutls.a
|
||||
<gnutls>on:<library>nettle/<link>shared
|
||||
<gnutls>off:<library>libjuice-openssl.a
|
||||
;
|
||||
|
||||
alias juice
|
||||
: # no sources
|
||||
: <toolset>msvc
|
||||
: # no default build
|
||||
: # usage requirements
|
||||
<include>./deps/libjuice/include
|
||||
<library>juice-static.lib
|
||||
;
|
||||
|
||||
make libusrsctp.a : : @make_libusrsctp ;
|
||||
make usrsctp.lib : : @make_libusrsctp_msvc ;
|
||||
|
||||
rule make_libusrsctp ( targets * : sources * : properties * )
|
||||
{
|
||||
local VARIANT = [ feature.get-values <variant> : $(properties) ] ;
|
||||
VARIANT on $(targets) = $(VARIANT) ;
|
||||
BUILD_DIR on $(targets) = "build-$(VARIANT)" ;
|
||||
}
|
||||
actions make_libusrsctp
|
||||
{
|
||||
(cd $(CWD)/deps/usrsctp && \
|
||||
./bootstrap && \
|
||||
./configure --enable-static --disable-debug CFLAGS="-fPIC -Wno-address-of-packed-member" && \
|
||||
make)
|
||||
cp $(CWD)/deps/usrsctp/usrsctplib/.libs/libusrsctp.a $(<)
|
||||
(cd $(CWD)/deps/usrsctp && mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=$(VARIANT) -DCMAKE_C_FLAGS="-fPIC -Wno-unknown-warning-option -Wno-format-truncation" -Dsctp_build_shared_lib=0 -Dsctp_build_programs=0 .. && make -j2 usrsctp)
|
||||
cp $(CWD)/deps/usrsctp/$(BUILD_DIR)/usrsctplib/libusrsctp.a $(<)
|
||||
}
|
||||
rule make_libusrsctp_msvc ( targets * : sources * : properties * )
|
||||
{
|
||||
local VARIANT = [ feature.get-values <variant> : $(properties) ] ;
|
||||
VARIANT on $(targets) = $(VARIANT) ;
|
||||
BUILD_DIR on $(targets) = "build-$(VARIANT)" ;
|
||||
}
|
||||
actions make_libusrsctp_msvc
|
||||
{
|
||||
SET OLDD=%CD%
|
||||
cd $(CWD)/deps/usrsctp
|
||||
mkdir $(BUILD_DIR)
|
||||
cd $(BUILD_DIR)
|
||||
cmake -G "Visual Studio 16 2019" -Dsctp_build_shared_lib=0 -Dsctp_build_programs=0 ..
|
||||
msbuild usrsctplib.sln /property:Configuration=$(VARIANT)
|
||||
cd %OLDD%
|
||||
cp $(CWD)/deps/usrsctp/$(BUILD_DIR)/usrsctplib/Release/usrsctp.lib $(<)
|
||||
}
|
||||
|
||||
make libjuice.a : : @make_libjuice ;
|
||||
make libjuice-gnutls.a : : @make_libjuice_gnutls ;
|
||||
make libjuice-openssl.a : : @make_libjuice_openssl ;
|
||||
make juice-static.lib : : @make_libjuice_msvc ;
|
||||
|
||||
rule make_libjuice ( targets * : sources * : properties * )
|
||||
rule make_libjuice_gnutls ( targets * : sources * : properties * )
|
||||
{
|
||||
if <crypto>gnutls in $(properties)
|
||||
local VARIANT = [ feature.get-values <variant> : $(properties) ] ;
|
||||
BUILD_DIR on $(targets) = "build-gnutls-$(VARIANT)" ;
|
||||
CMAKEOPTS on $(targets) = "-DCMAKE_C_FLAGS=\"-fPIC\" -DCMAKE_BUILD_TYPE=$(VARIANT) -DUSE_NETTLE=1" ;
|
||||
}
|
||||
actions make_libjuice_gnutls
|
||||
{
|
||||
(cd $(CWD)/deps/libjuice && mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake $(CMAKEOPTS) .. && make -j2 juice-static)
|
||||
cp $(CWD)/deps/libjuice/$(BUILD_DIR)/libjuice-static.a $(<)
|
||||
}
|
||||
rule make_libjuice_openssl ( targets * : sources * : properties * )
|
||||
{
|
||||
local VARIANT = [ feature.get-values <variant> : $(properties) ] ;
|
||||
BUILD_DIR on $(targets) = "build-openssl-$(VARIANT)" ;
|
||||
CMAKEOPTS on $(targets) = "-DCMAKE_C_FLAGS=\"-fPIC\" -DCMAKE_BUILD_TYPE=$(VARIANT) -DUSE_NETTLE=0" ;
|
||||
|
||||
local OPENSSL_INCLUDE = [ feature.get-values <openssl-include> : $(properties) ] ;
|
||||
if <target-os>darwin in $(properties) && $(OPENSSL_INCLUDE) = ""
|
||||
{
|
||||
MAKEOPTS on $(targets) = "USE_NETTLE=1" ;
|
||||
# on macOS, default to pick up openssl from the homebrew installation
|
||||
# brew install openssl
|
||||
OPENSSL_INCLUDE = /opt/homebrew/opt/openssl /usr/local/opt/openssl/include ;
|
||||
}
|
||||
|
||||
if $(OPENSSL_INCLUDE) != ""
|
||||
{ CMAKEOPTS on $(targets) += " -DOPENSSL_ROOT_DIR=$(OPENSSL_INCLUDE)/.." ; }
|
||||
}
|
||||
actions make_libjuice_openssl
|
||||
{
|
||||
(cd $(CWD)/deps/libjuice && mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake $(CMAKEOPTS) .. && make -j2 juice-static)
|
||||
cp $(CWD)/deps/libjuice/$(BUILD_DIR)/libjuice-static.a $(<)
|
||||
}
|
||||
rule make_libjuice_msvc ( targets * : sources * : properties * )
|
||||
{
|
||||
local VARIANT = [ feature.get-values <variant> : $(properties) ] ;
|
||||
VARIANT on $(targets) = $(VARIANT) ;
|
||||
if <gnutls>on in $(properties)
|
||||
{
|
||||
BUILD_DIR on $(targets) += "build-gnutls-$(VARIANT)" ;
|
||||
CMAKEOPTS on $(targets) = "-DUSE_NETTLE=1" ;
|
||||
}
|
||||
else
|
||||
{
|
||||
MAKEOPTS on $(targets) = "USE_NETTLE=0" ;
|
||||
BUILD_DIR on $(targets) += "build-openssl-$(VARIANT)" ;
|
||||
CMAKEOPTS on $(targets) = "-DUSE_NETTLE=0" ;
|
||||
}
|
||||
}
|
||||
actions make_libjuice
|
||||
actions make_libjuice_msvc
|
||||
{
|
||||
(cd $(CWD)/deps/libjuice && make $(MAKEOPTS))
|
||||
cp $(CWD)/deps/libjuice/libjuice.a $(<)
|
||||
SET OLDD=%CD%
|
||||
cd $(CWD)/deps/libjuice
|
||||
mkdir $(BUILD_DIR)
|
||||
cd $(BUILD_DIR)
|
||||
cmake -G "Visual Studio 16 2019" $(CMAKEOPTS) ..
|
||||
msbuild libjuice.sln /property:Configuration=$(VARIANT)
|
||||
cd %OLDD%
|
||||
cp $(CWD)/deps/libjuice/$(BUILD_DIR)/Release/juice-static.lib $(<)
|
||||
}
|
||||
|
||||
# the search path to pick up the openssl libraries from. This is the <search>
|
||||
# property of those libraries
|
||||
rule openssl-lib-path ( properties * )
|
||||
{
|
||||
local OPENSSL_LIB = [ feature.get-values <openssl-lib> : $(properties) ] ;
|
||||
|
||||
if <target-os>darwin in $(properties) && $(OPENSSL_LIB) = ""
|
||||
{
|
||||
# on macOS, default to pick up openssl from the homebrew installation
|
||||
# brew install openssl
|
||||
OPENSSL_LIB = /opt/homebrew/opt/openssl/lib /usr/local/opt/openssl/lib ;
|
||||
}
|
||||
else if <target-os>windows in $(properties) && $(OPENSSL_LIB) = ""
|
||||
{
|
||||
# on windows, assume openssl is installed to c:\OpenSSL-Win32
|
||||
if <address-model>64 in $(properties)
|
||||
{ OPENSSL_LIB = c:\\OpenSSL-Win64\\lib ; }
|
||||
else
|
||||
{ OPENSSL_LIB = c:\\OpenSSL-Win32\\lib ; }
|
||||
}
|
||||
|
||||
local result ;
|
||||
result += <search>$(OPENSSL_LIB) ;
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
# the include path to pick up openssl headers from. This is the
|
||||
# usage-requirement for the openssl-related libraries
|
||||
rule openssl-include-path ( properties * )
|
||||
{
|
||||
local OPENSSL_INCLUDE = [ feature.get-values <openssl-include> : $(properties) ] ;
|
||||
|
||||
if <target-os>darwin in $(properties) && $(OPENSSL_INCLUDE) = ""
|
||||
{
|
||||
# on macOS, default to pick up openssl from the homebrew installation
|
||||
# brew install openssl
|
||||
OPENSSL_INCLUDE = /opt/homebrew/opt/openssl/include /usr/local/opt/openssl/include ;
|
||||
}
|
||||
else if <target-os>windows in $(properties) && $(OPENSSL_INCLUDE) = ""
|
||||
{
|
||||
# on windows, assume openssl is installed to c:\OpenSSL-Win32
|
||||
if <address-model>64 in $(properties)
|
||||
{ OPENSSL_INCLUDE = c:\\OpenSSL-Win64\\include ; }
|
||||
else
|
||||
{ OPENSSL_INCLUDE = c:\\OpenSSL-Win32\\include ; }
|
||||
}
|
||||
|
||||
local result ;
|
||||
result += <include>$(OPENSSL_INCLUDE) ;
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
# libraries for OpenSSL on Windows
|
||||
lib advapi32 : : <name>advapi32 ;
|
||||
lib user32 : : <name>user32 ;
|
||||
lib shell32 : : <name>shell32 ;
|
||||
lib gdi32 : : <name>gdi32 ;
|
||||
lib bcrypt : : <name>bcrypt ;
|
||||
lib z : : <link>shared <name>z ;
|
||||
alias ssl-deps : advapi32 user32 shell32 gdi32 ;
|
||||
|
||||
# OpenSSL on Windows
|
||||
lib crypto : ssl-deps : <toolset>msvc <openssl-version>1.1 <name>libcrypto
|
||||
<conditional>@openssl-lib-path : : <conditional>@openssl-include-path ;
|
||||
lib ssl : ssl-deps : <toolset>msvc <openssl-version>1.1 <name>libssl <use>crypto
|
||||
<conditional>@openssl-lib-path : : <conditional>@openssl-include-path ;
|
||||
|
||||
# OpenSSL on other platforms
|
||||
lib crypto : : <name>crypto <use>z <conditional>@openssl-lib-path : :
|
||||
<conditional>@openssl-include-path ;
|
||||
lib ssl : : <name>ssl <use>crypto <conditional>@openssl-lib-path : :
|
||||
<conditional>@openssl-include-path ;
|
||||
|
||||
# GnuTLS
|
||||
lib gnutls : : <link>shared <name>gnutls ;
|
||||
lib nettle : : <link>shared <name>nettle ;
|
||||
|
||||
|
49
Makefile
@ -10,10 +10,11 @@ LDFLAGS=-pthread
|
||||
LIBS=
|
||||
LOCALLIBS=libusrsctp.a
|
||||
USRSCTP_DIR=deps/usrsctp
|
||||
SRTP_DIR=deps/libsrtp
|
||||
JUICE_DIR=deps/libjuice
|
||||
PLOG_DIR=deps/plog
|
||||
|
||||
INCLUDES=-Iinclude/rtc -I$(PLOG_DIR)/include -I$(USRSCTP_DIR)/usrsctplib
|
||||
INCLUDES=-Isrc -Iinclude/rtc -Iinclude -I$(PLOG_DIR)/include -I$(USRSCTP_DIR)/usrsctplib
|
||||
LDLIBS=
|
||||
|
||||
USE_GNUTLS ?= 0
|
||||
@ -25,39 +26,46 @@ else
|
||||
LIBS+=openssl
|
||||
endif
|
||||
|
||||
USE_JUICE ?= 0
|
||||
ifneq ($(USE_JUICE), 0)
|
||||
CPPFLAGS+=-DUSE_JUICE=1
|
||||
USE_NICE ?= 0
|
||||
ifneq ($(USE_NICE), 0)
|
||||
CPPFLAGS+=-DUSE_NICE=1
|
||||
LIBS+=glib-2.0 gobject-2.0 nice
|
||||
else
|
||||
CPPFLAGS+=-DUSE_NICE=0
|
||||
INCLUDES+=-I$(JUICE_DIR)/include
|
||||
LOCALLIBS+=libjuice.a
|
||||
ifneq ($(USE_GNUTLS), 0)
|
||||
LIBS+=nettle
|
||||
endif
|
||||
else
|
||||
CPPFLAGS+=-DUSE_JUICE=0
|
||||
LIBS+=glib-2.0 gobject-2.0 nice
|
||||
endif
|
||||
|
||||
RTC_ENABLE_MEDIA ?= 0
|
||||
ifneq ($(RTC_ENABLE_MEDIA), 0)
|
||||
NO_MEDIA ?= 0
|
||||
USE_SYSTEM_SRTP ?= 0
|
||||
ifeq ($(NO_MEDIA), 0)
|
||||
CPPFLAGS+=-DRTC_ENABLE_MEDIA=1
|
||||
ifneq ($(USE_SYSTEM_SRTP), 0)
|
||||
CPPFLAGS+=-DRTC_SYSTEM_SRTP=1
|
||||
LIBS+=srtp
|
||||
else
|
||||
CPPFLAGS+=-DRTC_SYSTEM_SRTP=0
|
||||
INCLUDES+=-I$(SRTP_DIR)/include
|
||||
LOCALLIBS+=libsrtp2.a
|
||||
endif
|
||||
else
|
||||
CPPFLAGS+=-DRTC_ENABLE_MEDIA=0
|
||||
endif
|
||||
|
||||
RTC_ENABLE_WEBSOCKET ?= 1
|
||||
ifneq ($(RTC_ENABLE_WEBSOCKET), 0)
|
||||
NO_WEBSOCKET ?= 0
|
||||
ifeq ($(NO_WEBSOCKET), 0)
|
||||
CPPFLAGS+=-DRTC_ENABLE_WEBSOCKET=1
|
||||
else
|
||||
CPPFLAGS+=-DRTC_ENABLE_WEBSOCKET=0
|
||||
endif
|
||||
|
||||
INCLUDES+=$(if $(LIBS),$(shell pkg-config --cflags $(LIBS)),)
|
||||
LDLIBS+=$(LOCALLIBS) $(if $(LIBS),$(shell pkg-config --libs $(LIBS)),)
|
||||
|
||||
INCLUDES+=$(shell pkg-config --cflags $(LIBS))
|
||||
LDLIBS+=$(LOCALLIBS) $(shell pkg-config --libs $(LIBS))
|
||||
|
||||
SRCS=$(shell printf "%s " src/*.cpp)
|
||||
SRCS=$(shell printf "%s " src/*.cpp src/impl/*.cpp)
|
||||
OBJS=$(subst .cpp,.o,$(SRCS))
|
||||
|
||||
TEST_SRCS=$(shell printf "%s " test/*.cpp)
|
||||
@ -73,7 +81,7 @@ test/%.o: test/%.cpp
|
||||
|
||||
-include $(subst .cpp,.d,$(SRCS))
|
||||
|
||||
$(NAME).a: $(OBJS)
|
||||
$(NAME).a: $(LOCALLIBS) $(OBJS)
|
||||
$(AR) crf $@ $(OBJS)
|
||||
|
||||
$(NAME).so: $(LOCALLIBS) $(OBJS)
|
||||
@ -97,15 +105,22 @@ dist-clean: clean
|
||||
-$(RM) src/*~
|
||||
-$(RM) test/*~
|
||||
-cd $(USRSCTP_DIR) && make clean
|
||||
-cd $(SRTP_DIR) && make clean
|
||||
-cd $(JUICE_DIR) && make clean
|
||||
|
||||
libusrsctp.a:
|
||||
cd $(USRSCTP_DIR) && \
|
||||
./bootstrap && \
|
||||
./configure --enable-static --disable-debug CFLAGS="$(CPPFLAGS) -Wno-error=format-truncation" && \
|
||||
./configure --enable-static --disable-debug CFLAGS="-fPIC" && \
|
||||
make
|
||||
cp $(USRSCTP_DIR)/usrsctplib/.libs/libusrsctp.a .
|
||||
|
||||
libsrtp2.a:
|
||||
cd $(SRTP_DIR) && \
|
||||
./configure && \
|
||||
make
|
||||
cp $(SRTP_DIR)/libsrtp2.a .
|
||||
|
||||
libjuice.a:
|
||||
ifneq ($(USE_GNUTLS), 0)
|
||||
cd $(JUICE_DIR) && make USE_NETTLE=1
|
||||
|
270
README.md
@ -1,34 +1,148 @@
|
||||
# libdatachannel - C/C++ WebRTC Data Channels
|
||||
|
||||
libdatachannel is a standalone implementation of WebRTC Data Channels and WebSockets in C++17 with C bindings for POSIX platforms (including Linux and Apple macOS) and Microsoft Windows. It enables direct connectivity between native applications and web browsers without the pain of importing the entire WebRTC stack. The interface consists of simplified versions of the JavaScript WebRTC and WebSocket APIs present in browsers, in order to ease the design of cross-environment applications.
|
||||
libdatachannel is a standalone implementation of WebRTC Data Channels, WebRTC Media Transport, and WebSockets in C++17 with C bindings for POSIX platforms (including GNU/Linux, Android, and Apple macOS) and Microsoft Windows.
|
||||
|
||||
The library aims at being both straightforward and lightweight with minimal external dependencies, to enable direct connectivity between native applications and web browsers without the pain of importing Google's bloated [reference library](https://webrtc.googlesource.com/src/). The interface consists of somewhat simplified versions of the JavaScript WebRTC and WebSocket APIs present in browsers, in order to ease the design of cross-environment applications.
|
||||
|
||||
It can be compiled with multiple backends:
|
||||
- The security layer can be provided through [GnuTLS](https://www.gnutls.org/) or [OpenSSL](https://www.openssl.org/).
|
||||
- The security layer can be provided through [OpenSSL](https://www.openssl.org/) or [GnuTLS](https://www.gnutls.org/).
|
||||
- The connectivity for WebRTC can be provided through my ad-hoc ICE library [libjuice](https://github.com/paullouisageneau/libjuice) as submodule or through [libnice](https://github.com/libnice/libnice).
|
||||
|
||||
This projet is originally inspired by [librtcdcpp](https://github.com/chadnickbok/librtcdcpp), however it is a complete rewrite from scratch, because the messy architecture of librtcdcpp made solving its implementation issues difficult.
|
||||
The WebRTC stack is fully compatible with Firefox and Chromium, see [Compatibility](#Compatibility) below.
|
||||
|
||||
Licensed under LGPLv2, see [LICENSE](https://github.com/paullouisageneau/libdatachannel/blob/master/LICENSE).
|
||||
|
||||
## Dependencies
|
||||
|
||||
Only [GnuTLS](https://www.gnutls.org/) or [OpenSSL](https://www.openssl.org/) are necessary. Optionally, [libnice](https://nice.freedesktop.org/) can be selected as an alternative ICE backend instead of libjuice.
|
||||
|
||||
Submodules:
|
||||
- libjuice: https://github.com/paullouisageneau/libjuice
|
||||
- usrsctp: https://github.com/sctplab/usrsctp
|
||||
- libsrtp: https://github.com/cisco/libsrtp (if compiled with media support)
|
||||
|
||||
## Building
|
||||
|
||||
See [BUILDING.md](https://github.com/paullouisageneau/libdatachannel/blob/master/BUILDING.md) for building instructions.
|
||||
|
||||
## Examples
|
||||
|
||||
See [examples](https://github.com/paullouisageneau/libdatachannel/blob/master/examples/) for complete usage examples with signaling server (under GPLv2).
|
||||
|
||||
Additionnaly, you might want to have a look at the [C API documentation](https://github.com/paullouisageneau/libdatachannel/blob/master/DOC.md).
|
||||
|
||||
### Signal a PeerConnection
|
||||
|
||||
```cpp
|
||||
#include "rtc/rtc.hpp"
|
||||
```
|
||||
|
||||
```cpp
|
||||
rtc::Configuration config;
|
||||
config.iceServers.emplace_back("mystunserver.org:3478");
|
||||
|
||||
rtc::PeerConection pc(config);
|
||||
|
||||
pc.onLocalDescription([](rtc::Description sdp) {
|
||||
// Send the SDP to the remote peer
|
||||
MY_SEND_DESCRIPTION_TO_REMOTE(string(sdp));
|
||||
});
|
||||
|
||||
pc.onLocalCandidate([](rtc::Candidate candidate) {
|
||||
// Send the candidate to the remote peer
|
||||
MY_SEND_CANDIDATE_TO_REMOTE(candidate.candidate(), candidate.mid());
|
||||
});
|
||||
|
||||
MY_ON_RECV_DESCRIPTION_FROM_REMOTE([&pc](string sdp) {
|
||||
pc.setRemoteDescription(rtc::Description(sdp));
|
||||
});
|
||||
|
||||
MY_ON_RECV_CANDIDATE_FROM_REMOTE([&pc](string candidate, string mid) {
|
||||
pc.addRemoteCandidate(rtc::Candidate(candidate, mid));
|
||||
});
|
||||
```
|
||||
|
||||
### Observe the PeerConnection state
|
||||
|
||||
```cpp
|
||||
pc.onStateChange([](rtc::PeerConnection::State state) {
|
||||
std::cout << "State: " << state << std::endl;
|
||||
});
|
||||
|
||||
pc.onGatheringStateChange([](rtc::PeerConnection::GatheringState state) {
|
||||
std::cout << "Gathering state: " << state << std::endl;
|
||||
});
|
||||
```
|
||||
|
||||
### Create a DataChannel
|
||||
|
||||
```cpp
|
||||
auto dc = pc.createDataChannel("test");
|
||||
|
||||
dc->onOpen([]() {
|
||||
std::cout << "Open" << std::endl;
|
||||
});
|
||||
|
||||
dc->onMessage([](std::variant<binary, string> message) {
|
||||
if (std::holds_alternative<string>(message)) {
|
||||
std::cout << "Received: " << get<string>(message) << std::endl;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Receive a DataChannel
|
||||
|
||||
```cpp
|
||||
std::shared_ptr<rtc::DataChannel> dc;
|
||||
pc.onDataChannel([&dc](std::shared_ptr<rtc::DataChannel> incoming) {
|
||||
dc = incoming;
|
||||
dc->send("Hello world!");
|
||||
});
|
||||
```
|
||||
|
||||
### Open a WebSocket
|
||||
|
||||
```cpp
|
||||
rtc::WebSocket ws;
|
||||
|
||||
ws.onOpen([]() {
|
||||
std::cout << "WebSocket open" << std::endl;
|
||||
});
|
||||
|
||||
ws.onMessage([](std::variant<binary, string> message) {
|
||||
if (std::holds_alternative<string>(message)) {
|
||||
std::cout << "WebSocket received: " << std::get<string>(message) << endl;
|
||||
}
|
||||
});
|
||||
|
||||
ws.open("wss://my.websocket/service");
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
|
||||
The library aims at implementing the following communication protocols:
|
||||
The library implements the following communication protocols:
|
||||
|
||||
### WebRTC Data Channel
|
||||
### WebRTC Data Channels and Media Transport
|
||||
|
||||
The WebRTC stack has been tested to be compatible with Firefox and Chromium.
|
||||
The library implements WebRTC Peer Connections with both Data Channels and Media Transport. Media transport is optional and can be disabled at compile time.
|
||||
|
||||
Protocol stack:
|
||||
- SCTP-based Data Channels ([draft-ietf-rtcweb-data-channel-13](https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-13))
|
||||
- SCTP-based Data Channels ([RFC8831](https://tools.ietf.org/html/rfc8831))
|
||||
- SRTP-based Media Transport ([RFC8834](https://tools.ietf.org/html/rfc8834))
|
||||
- DTLS/UDP ([RFC7350](https://tools.ietf.org/html/rfc7350) and [RFC8261](https://tools.ietf.org/html/rfc8261))
|
||||
- ICE ([RFC8445](https://tools.ietf.org/html/rfc8445)) with STUN ([RFC5389](https://tools.ietf.org/html/rfc5389))
|
||||
- ICE ([RFC8445](https://tools.ietf.org/html/rfc8445)) with STUN ([RFC8489](https://tools.ietf.org/html/rfc8489)) and its extension TURN ([RFC8656](https://tools.ietf.org/html/rfc8656))
|
||||
|
||||
Features:
|
||||
- Full IPv6 support
|
||||
- Trickle ICE ([draft-ietf-ice-trickle-21](https://tools.ietf.org/html/draft-ietf-ice-trickle-21))
|
||||
- JSEP compatible ([draft-ietf-rtcweb-jsep-26](https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-26))
|
||||
- Full IPv6 support (as mandated by [RFC8835](https://tools.ietf.org/html/rfc8835))
|
||||
- Trickle ICE ([RFC8838](https://tools.ietf.org/html/rfc8838))
|
||||
- JSEP-compatible session establishment with SDP ([RFC8829](https://tools.ietf.org/html/rfc8829))
|
||||
- SCTP over DTLS with SDP offer/answer ([RFC8841](https://tools.ietf.org/html/rfc8841))
|
||||
- DTLS with ECDSA or RSA keys ([RFC8824](https://tools.ietf.org/html/rfc8827))
|
||||
- SRTP and SRTCP key derivation from DTLS ([RFC5764](https://tools.ietf.org/html/rfc5764))
|
||||
- Multicast DNS candidates ([draft-ietf-rtcweb-mdns-ice-candidates-04](https://tools.ietf.org/html/draft-ietf-rtcweb-mdns-ice-candidates-04))
|
||||
- TURN relaying ([RFC5766](https://tools.ietf.org/html/rfc5766)) with [libnice](https://github.com/libnice/libnice) as ICE backend
|
||||
- SRTP media transport ([RFC3711](https://tools.ietf.org/html/rfc3711)) with [libSRTP](https://github.com/cisco/libsrtp)
|
||||
- Differentiated Services QoS ([draft-ietf-tsvwg-rtcweb-qos-18](https://tools.ietf.org/html/draft-ietf-tsvwg-rtcweb-qos-18))
|
||||
|
||||
Note only SDP BUNDLE mode is supported for media multiplexing ([RFC8843](https://tools.ietf.org/html/rfc8843)). The behavior is equivalent to the JSEP bundle-only policy: the library always negociates one unique network component, where SRTP media streams are multiplexed with SRTCP control packets ([RFC5761](https://tools.ietf.org/html/rfc5761)) and SCTP/DTLS data traffic ([RFC8261](https://tools.ietf.org/html/rfc8261)).
|
||||
|
||||
### WebSocket
|
||||
|
||||
@ -42,129 +156,13 @@ Features:
|
||||
- IPv6 and IPv4/IPv6 dual-stack support
|
||||
- Keepalive with ping/pong
|
||||
|
||||
## Dependencies
|
||||
## External resources
|
||||
- Rust wrapper for libdatachannel: [datachannel-rs](https://github.com/lerouxrgd/datachannel-rs)
|
||||
- Node.js wrapper for libdatachannel: [node-datachannel](https://github.com/murat-dogan/node-datachannel)
|
||||
- Unity wrapper for Windows 10 and Hololens: [datachannel-unity](https://github.com/hanseuljun/datachannel-unity)
|
||||
- WebAssembly wrapper compatible with libdatachannel: [datachannel-wasm](https://github.com/paullouisageneau/datachannel-wasm)
|
||||
|
||||
- GnuTLS: https://www.gnutls.org/ or OpenSSL: https://www.openssl.org/
|
||||
## Thanks
|
||||
|
||||
Optional:
|
||||
- libnice: https://nice.freedesktop.org/ (substituable with libjuice)
|
||||
- libSRTP: https://github.com/cisco/libsrtp
|
||||
|
||||
Submodules:
|
||||
- libjuice: https://github.com/paullouisageneau/libjuice
|
||||
- usrsctp: https://github.com/sctplab/usrsctp
|
||||
|
||||
## Building
|
||||
### Building with CMake (preferred)
|
||||
|
||||
```bash
|
||||
$ git submodule update --init --recursive
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake -DUSE_JUICE=1 -DUSE_GNUTLS=1 ..
|
||||
$ make
|
||||
```
|
||||
|
||||
### Building directly with Make
|
||||
|
||||
```bash
|
||||
$ git submodule update --init --recursive
|
||||
$ make USE_JUICE=1 USE_GNUTLS=1
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
See [examples](https://github.com/paullouisageneau/libdatachannel/blob/master/examples/) for a complete usage example with signaling server (under GPLv2).
|
||||
|
||||
Additionnaly, you might want to have a look at the [C API](https://github.com/paullouisageneau/libdatachannel/blob/dev/include/rtc/rtc.h).
|
||||
|
||||
### Signal a PeerConnection
|
||||
|
||||
```cpp
|
||||
#include "rtc/rtc.hpp"
|
||||
```
|
||||
|
||||
```cpp
|
||||
rtc::Configuration config;
|
||||
config.iceServers.emplace_back("mystunserver.org:3478");
|
||||
|
||||
auto pc = make_shared<rtc::PeerConnection>(config);
|
||||
|
||||
pc->onLocalDescription([](const rtc::Description &sdp) {
|
||||
// Send the SDP to the remote peer
|
||||
MY_SEND_DESCRIPTION_TO_REMOTE(string(sdp));
|
||||
});
|
||||
|
||||
pc->onLocalCandidate([](const rtc::Candidate &candidate) {
|
||||
// Send the candidate to the remote peer
|
||||
MY_SEND_CANDIDATE_TO_REMOTE(candidate.candidate(), candidate.mid());
|
||||
});
|
||||
|
||||
MY_ON_RECV_DESCRIPTION_FROM_REMOTE([pc](string sdp) {
|
||||
pc->setRemoteDescription(rtc::Description(sdp));
|
||||
});
|
||||
|
||||
MY_ON_RECV_CANDIDATE_FROM_REMOTE([pc](string candidate, string mid) {
|
||||
pc->addRemoteCandidate(rtc::Candidate(candidate, mid));
|
||||
});
|
||||
```
|
||||
|
||||
### Observe the PeerConnection state
|
||||
|
||||
```cpp
|
||||
pc->onStateChange([](PeerConnection::State state) {
|
||||
cout << "State: " << state << endl;
|
||||
});
|
||||
|
||||
pc->onGatheringStateChange([](PeerConnection::GatheringState state) {
|
||||
cout << "Gathering state: " << state << endl;
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### Create a DataChannel
|
||||
|
||||
```cpp
|
||||
auto dc = pc->createDataChannel("test");
|
||||
|
||||
dc->onOpen([]() {
|
||||
cout << "Open" << endl;
|
||||
});
|
||||
|
||||
dc->onMessage([](const variant<binary, string> &message) {
|
||||
if (holds_alternative<string>(message)) {
|
||||
cout << "Received: " << get<string>(message) << endl;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Receive a DataChannel
|
||||
|
||||
```cpp
|
||||
shared_ptr<rtc::DataChannel> dc;
|
||||
pc->onDataChannel([&dc](shared_ptr<rtc::DataChannel> incoming) {
|
||||
dc = incoming;
|
||||
dc->send("Hello world!");
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### Open a WebSocket
|
||||
|
||||
```cpp
|
||||
auto ws = make_shared<rtc::WebSocket>();
|
||||
|
||||
ws->onOpen([]() {
|
||||
cout << "WebSocket open" << endl;
|
||||
});
|
||||
|
||||
ws->onMessage([](const variant<binary, string> &message) {
|
||||
if (holds_alternative<string>(message)) {
|
||||
cout << "WebSocket received: " << get<string>(message) << endl;
|
||||
}
|
||||
});
|
||||
|
||||
ws->open("wss://my.websocket/service");
|
||||
|
||||
```
|
||||
Thanks to [Streamr](https://streamr.network/) for sponsoring this work!
|
||||
|
||||
|
2
deps/libjuice
vendored
1
deps/libsrtp
vendored
Submodule
2
deps/plog
vendored
2
deps/usrsctp
vendored
@ -1,10 +1,16 @@
|
||||
# Examples for libdatachannel
|
||||
# libdatachannel - Examples
|
||||
|
||||
This directory contains different WebRTC clients and WebSocket + JSON signaling servers.
|
||||
This directory contains different WebRTC clients and compatible WebSocket + JSON signaling servers.
|
||||
|
||||
- [client](client) uses libdatachannel to implement WebRTC Data Channels with WebSocket signaling
|
||||
- [web](web) contains an equivalent implementation for web browsers and a node.js signaling server
|
||||
- [client](client) contains a native client to open Data Channels with WebSocket signaling using libdatachannel
|
||||
- [client-benchmark](client-benchmark) contains a native client to open Data Channels with WebSocket signaling using libdatachannel and benchmark functionalities. See [client-benchmark/README.md](client-benchmark/README.md) for usage examples.
|
||||
- [web](web) contains a equivalent JavaScript client for web browsers
|
||||
- [signaling-server-nodejs](signaling-server-nodejs) contains a signaling server in node.js
|
||||
- [signaling-server-python](signaling-server-python) contains a similar signaling server in Python
|
||||
- [signaling-server-rust](signaling-server-rust) contains a similar signaling server in Rust (see [lerouxrgd/datachannel-rs](https://github.com/lerouxrgd/datachannel-rs) for Rust wrappers)
|
||||
|
||||
- [media](media) is a copy/paste demo to send the webcam from your browser into gstreamer.
|
||||
- [streamer](streamer) streams h264 and opus samples to web browsers (signaling-server-python is required).
|
||||
|
||||
Additionally, it contains two debugging tools for libdatachannel with copy-pasting as signaling:
|
||||
- [copy-paste](copy-paste) using the C++ API
|
||||
|
24
examples/client-benchmark/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
if(POLICY CMP0079)
|
||||
cmake_policy(SET CMP0079 NEW)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_executable(datachannel-client-benchmark main.cpp parse_cl.cpp parse_cl.h getopt.cpp getopt.h)
|
||||
target_compile_definitions(datachannel-client-benchmark PUBLIC STATIC_GETOPT)
|
||||
else()
|
||||
add_executable(datachannel-client-benchmark main.cpp parse_cl.cpp parse_cl.h)
|
||||
endif()
|
||||
|
||||
set_target_properties(datachannel-client-benchmark PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
OUTPUT_NAME client-benchmark)
|
||||
target_link_libraries(datachannel-client-benchmark datachannel nlohmann_json)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET datachannel-client-benchmark POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
|
||||
$<TARGET_FILE_DIR:datachannel-client-benchmark>
|
||||
)
|
||||
endif()
|
339
examples/client-benchmark/LICENSE
Normal file
@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
219
examples/client-benchmark/README.md
Normal file
@ -0,0 +1,219 @@
|
||||
# libdatachannel - client-benchmark
|
||||
|
||||
This directory contains a native client to open Data Channels with WebSocket signaling using libdatachannel and benchmark functionalities. It offers two functionalities;
|
||||
- Benchmark: Bi-directional data transfer benchmark (Also supports One-Way testing)
|
||||
- Constant Throughput Set: Send desired amount of data per second
|
||||
|
||||
## Start Signaling Server
|
||||
- Start one of the signaling server from the examples folder. For example start `signaling-server-nodejs` like;
|
||||
- `cd examples/signaling-server-nodejs/`
|
||||
- `npm i`
|
||||
- `npm run start `
|
||||
|
||||
## Start `client-benchmark` Applications
|
||||
|
||||
Start 2 applications by using example calls below. Than copy one of the client's ID and paste to the other peer's screen to start offering process.
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Benchmark for 300 seconds
|
||||
|
||||
> `./client-benchmark -d 300`
|
||||
|
||||
Example Output (Offering Peer's Output);
|
||||
```bash
|
||||
Stun server is stun:stun.l.google.com:19302
|
||||
The local ID is: EQmF
|
||||
Url is ws://localhost:8000/EQmF
|
||||
Waiting for signaling to be connected...
|
||||
2021-03-25 14:21:58.045 INFO [21386] [rtc::impl::TcpTransport::connect@159] Connected to localhost:8000
|
||||
2021-03-25 14:21:58.045 INFO [21386] [rtc::impl::TcpTransport::runLoop@327] TCP connected
|
||||
2021-03-25 14:21:58.046 INFO [21386] [rtc::impl::WsTransport::incoming@118] WebSocket open
|
||||
WebSocket connected, signaling ready
|
||||
Enter a remote ID to send an offer:
|
||||
0tDf
|
||||
Offering to 0tDf
|
||||
Creating DataChannel with label "benchmark"
|
||||
2021-03-25 14:22:07.972 INFO [21379] [rtc::impl::IceTransport::IceTransport@106] Using STUN server "stun.l.google.com:19302"
|
||||
2021-03-25 14:22:07.973 INFO [21379] [rtc::impl::PeerConnection::changeSignalingState@992] Changed signaling state to new
|
||||
2021-03-25 14:22:07.973 INFO [21379] [rtc::impl::PeerConnection::changeGatheringState@981] Changed gathering state to in-progress
|
||||
Gathering State: in-progress
|
||||
2021-03-25 14:22:07.974 INFO [21379] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to gathering
|
||||
2021-03-25 14:22:07.974 WARN [21379] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:239: Local description already has the maximum number of host candidates
|
||||
Benchmark will run for 300 seconds
|
||||
2021-03-25 14:22:07.976 INFO [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to connecting
|
||||
2021-03-25 14:22:07.976 INFO [21396] [rtc::impl::PeerConnection::changeState@964] Changed state to connecting
|
||||
State: connecting
|
||||
2021-03-25 14:22:08.055 INFO [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:610: Using STUN server stun.l.google.com:19302
|
||||
2021-03-25 14:22:08.055 INFO [21386] [rtc::impl::PeerConnection::changeSignalingState@992] Changed signaling state to connecting
|
||||
2021-03-25 14:22:08.105 WARN [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:426: Send failed, errno=101
|
||||
2021-03-25 14:22:08.105 WARN [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:1483: STUN message send failed, errno=101
|
||||
2021-03-25 14:22:08.105 INFO [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:843: STUN binding failed
|
||||
2021-03-25 14:22:08.107 INFO [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:1302: STUN server binding successful
|
||||
2021-03-25 14:22:08.107 INFO [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:2148: Candidate gathering done
|
||||
2021-03-25 14:22:08.107 INFO [21396] [rtc::impl::PeerConnection::changeGatheringState@981] Changed gathering state to complete
|
||||
Gathering State: complete
|
||||
2021-03-25 14:22:08.155 INFO [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to connected
|
||||
2021-03-25 14:22:08.206 INFO [21396] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to completed
|
||||
#1 Received: 0 KB/s Sent: 0 KB/s BufferSize: 0
|
||||
2021-03-25 14:22:09.059 INFO [21399] [rtc::impl::DtlsTransport::runRecvLoop@503] DTLS handshake finished
|
||||
2021-03-25 14:22:09.069 INFO [21382] [rtc::impl::SctpTransport::processNotification@708] SCTP connected
|
||||
2021-03-25 14:22:09.069 INFO [21382] [rtc::impl::PeerConnection::changeState@964] Changed state to connected
|
||||
State: connected
|
||||
DataChannel from 0tDf open
|
||||
#2 Received: 41488 KB/s Sent: 42465 KB/s BufferSize: 65535
|
||||
#3 Received: 43925 KB/s Sent: 43729 KB/s BufferSize: 65535
|
||||
#4 Received: 42491 KB/s Sent: 42361 KB/s BufferSize: 65535
|
||||
#5 Received: 45878 KB/s Sent: 45682 KB/s BufferSize: 65535
|
||||
Stats# Received Total: 174 MB Sent Total: 175 MB RTT: 17 ms
|
||||
|
||||
#6 Received: 43665 KB/s Sent: 43599 KB/s BufferSize: 65535
|
||||
#7 Received: 45749 KB/s Sent: 45488 KB/s BufferSize: 65535
|
||||
#8 Received: 44055 KB/s Sent: 44055 KB/s BufferSize: 65535
|
||||
#9 Received: 21572 KB/s Sent: 58199 KB/s BufferSize: 65535
|
||||
#10 Received: 22940 KB/s Sent: 55005 KB/s BufferSize: 65535
|
||||
Stats# Received Total: 353 MB Sent Total: 422 MB RTT: 15 ms
|
||||
|
||||
#11 Received: 27501 KB/s Sent: 53112 KB/s BufferSize: 65535
|
||||
#12 Received: 29914 KB/s Sent: 48162 KB/s BufferSize: 65535
|
||||
#13 Received: 31869 KB/s Sent: 45946 KB/s BufferSize: 65535
|
||||
#14 Received: 22484 KB/s Sent: 53636 KB/s BufferSize: 65535
|
||||
#15 Received: 16294 KB/s Sent: 56833 KB/s BufferSize: 65535
|
||||
Stats# Received Total: 482 MB Sent Total: 682 MB RTT: 13 ms
|
||||
```
|
||||
|
||||
### Benchmark for 300 seconds (Only Send, One Way)
|
||||
|
||||
Start first peer as;
|
||||
> `./client-benchmark -d 300 -o`
|
||||
|
||||
Start second peer as;
|
||||
> `./client-benchmark -d 300`
|
||||
|
||||
Example Output (Offering Peer's Output);
|
||||
```bash
|
||||
Stun server is stun:stun.l.google.com:19302
|
||||
The local ID is: XLLn
|
||||
Url is ws://localhost:8000/XLLn
|
||||
Waiting for signaling to be connected...
|
||||
2021-03-25 14:34:24.479 INFO [22332] [rtc::impl::TcpTransport::connect@159] Connected to localhost:8000
|
||||
2021-03-25 14:34:24.479 INFO [22332] [rtc::impl::TcpTransport::runLoop@327] TCP connected
|
||||
2021-03-25 14:34:24.479 INFO [22332] [rtc::impl::WsTransport::incoming@118] WebSocket open
|
||||
WebSocket connected, signaling ready
|
||||
Enter a remote ID to send an offer:
|
||||
Okt4
|
||||
Offering to Okt4
|
||||
Creating DataChannel with label "benchmark"
|
||||
2021-03-25 14:34:37.948 INFO [22325] [rtc::impl::IceTransport::IceTransport@106] Using STUN server "stun.l.google.com:19302"
|
||||
2021-03-25 14:34:37.949 INFO [22325] [rtc::impl::PeerConnection::changeSignalingState@992] Changed signaling state to new
|
||||
2021-03-25 14:34:37.949 INFO [22325] [rtc::impl::PeerConnection::changeGatheringState@981] Changed gathering state to in-progress
|
||||
Gathering State: in-progress
|
||||
2021-03-25 14:34:37.950 INFO [22325] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to gathering
|
||||
2021-03-25 14:34:37.951 WARN [22325] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:239: Local description already has the maximum number of host candidates
|
||||
Benchmark will run for 300 seconds
|
||||
2021-03-25 14:34:37.952 INFO [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to connecting
|
||||
2021-03-25 14:34:37.952 INFO [22334] [rtc::impl::PeerConnection::changeState@964] Changed state to connecting
|
||||
State: connecting
|
||||
2021-03-25 14:34:37.969 INFO [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:610: Using STUN server stun.l.google.com:19302
|
||||
2021-03-25 14:34:37.969 INFO [22332] [rtc::impl::PeerConnection::changeSignalingState@992] Changed signaling state to connecting
|
||||
2021-03-25 14:34:37.970 INFO [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to connected
|
||||
2021-03-25 14:34:37.971 INFO [22337] [rtc::impl::DtlsTransport::runRecvLoop@503] DTLS handshake finished
|
||||
2021-03-25 14:34:37.977 INFO [22327] [rtc::impl::SctpTransport::processNotification@708] SCTP connected
|
||||
2021-03-25 14:34:37.977 INFO [22327] [rtc::impl::PeerConnection::changeState@964] Changed state to connected
|
||||
State: connected
|
||||
DataChannel from Okt4 open
|
||||
2021-03-25 14:34:38.019 WARN [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:426: Send failed, errno=101
|
||||
2021-03-25 14:34:38.019 WARN [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:1483: STUN message send failed, errno=101
|
||||
2021-03-25 14:34:38.019 INFO [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:843: STUN binding failed
|
||||
2021-03-25 14:34:38.022 INFO [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:1302: STUN server binding successful
|
||||
2021-03-25 14:34:38.022 INFO [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:2148: Candidate gathering done
|
||||
2021-03-25 14:34:38.022 INFO [22334] [rtc::impl::PeerConnection::changeGatheringState@981] Changed gathering state to complete
|
||||
Gathering State: complete
|
||||
2021-03-25 14:34:38.069 INFO [22334] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to completed
|
||||
#1 Received: 0 KB/s Sent: 92223 KB/s BufferSize: 65535
|
||||
#2 Received: 0 KB/s Sent: 89291 KB/s BufferSize: 65535
|
||||
#3 Received: 0 KB/s Sent: 95087 KB/s BufferSize: 65535
|
||||
#4 Received: 0 KB/s Sent: 101050 KB/s BufferSize: 65535
|
||||
#5 Received: 0 KB/s Sent: 99778 KB/s BufferSize: 0
|
||||
Stats# Received Total: 0 MB Sent Total: 480 MB RTT: 8 ms
|
||||
|
||||
#6 Received: 0 KB/s Sent: 100366 KB/s BufferSize: 65535
|
||||
#7 Received: 0 KB/s Sent: 101201 KB/s BufferSize: 65535
|
||||
#8 Received: 0 KB/s Sent: 100892 KB/s BufferSize: 65535
|
||||
#9 Received: 0 KB/s Sent: 101288 KB/s BufferSize: 65535
|
||||
#10 Received: 0 KB/s Sent: 95676 KB/s BufferSize: 65535
|
||||
Stats# Received Total: 0 MB Sent Total: 982 MB RTT: 8 ms
|
||||
|
||||
#11 Received: 0 KB/s Sent: 96254 KB/s BufferSize: 65535
|
||||
#12 Received: 0 KB/s Sent: 105473 KB/s BufferSize: 65535
|
||||
#13 Received: 0 KB/s Sent: 95549 KB/s BufferSize: 65535
|
||||
#14 Received: 0 KB/s Sent: 100366 KB/s BufferSize: 65535
|
||||
#15 Received: 0 KB/s Sent: 101336 KB/s BufferSize: 65535
|
||||
Stats# Received Total: 0 MB Sent Total: 1484 MB RTT: 8 ms
|
||||
```
|
||||
|
||||
### Constant Throughput Set 8000 byte, for 300 seconds, send buffer 10000 byte
|
||||
|
||||
> `./client-benchmark -p -d 300 -r 8000 -b 10000`
|
||||
|
||||
Example Output (Offering Peer's Output);
|
||||
```bash
|
||||
Stun server is stun:stun.l.google.com:19302
|
||||
The local ID is: 1w9O
|
||||
Url is ws://localhost:8000/1w9O
|
||||
Waiting for signaling to be connected...
|
||||
2021-03-25 14:29:38.697 INFO [21844] [rtc::impl::TcpTransport::connect@159] Connected to localhost:8000
|
||||
2021-03-25 14:29:38.697 INFO [21844] [rtc::impl::TcpTransport::runLoop@327] TCP connected
|
||||
2021-03-25 14:29:38.698 INFO [21844] [rtc::impl::WsTransport::incoming@118] WebSocket open
|
||||
WebSocket connected, signaling ready
|
||||
Enter a remote ID to send an offer:
|
||||
zi4B
|
||||
Offering to zi4B
|
||||
Creating DataChannel with label "benchmark"
|
||||
2021-03-25 14:29:48.729 INFO [21837] [rtc::impl::IceTransport::IceTransport@106] Using STUN server "stun.l.google.com:19302"
|
||||
2021-03-25 14:29:48.729 INFO [21837] [rtc::impl::PeerConnection::changeSignalingState@992] Changed signaling state to new
|
||||
2021-03-25 14:29:48.729 INFO [21837] [rtc::impl::PeerConnection::changeGatheringState@981] Changed gathering state to in-progress
|
||||
Gathering State: in-progress
|
||||
2021-03-25 14:29:48.729 INFO [21837] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to gathering
|
||||
2021-03-25 14:29:48.730 WARN [21837] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:239: Local description already has the maximum number of host candidates
|
||||
Benchmark will run for 300 seconds
|
||||
2021-03-25 14:29:48.730 INFO [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to connecting
|
||||
2021-03-25 14:29:48.731 INFO [21866] [rtc::impl::PeerConnection::changeState@964] Changed state to connecting
|
||||
State: connecting
|
||||
2021-03-25 14:29:48.732 INFO [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:610: Using STUN server stun.l.google.com:19302
|
||||
2021-03-25 14:29:48.732 INFO [21844] [rtc::impl::PeerConnection::changeSignalingState@992] Changed signaling state to connecting
|
||||
2021-03-25 14:29:48.782 WARN [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:426: Send failed, errno=101
|
||||
2021-03-25 14:29:48.782 WARN [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:1483: STUN message send failed, errno=101
|
||||
2021-03-25 14:29:48.782 INFO [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:843: STUN binding failed
|
||||
2021-03-25 14:29:48.787 INFO [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:1302: STUN server binding successful
|
||||
2021-03-25 14:29:48.787 INFO [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:2148: Candidate gathering done
|
||||
2021-03-25 14:29:48.787 INFO [21866] [rtc::impl::PeerConnection::changeGatheringState@981] Changed gathering state to complete
|
||||
Gathering State: complete
|
||||
2021-03-25 14:29:48.832 INFO [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to connected
|
||||
2021-03-25 14:29:48.882 INFO [21866] [rtc::impl::IceTransport::LogCallback@339] juice: agent.c:787: Changing state to completed
|
||||
2021-03-25 14:29:49.735 INFO [21869] [rtc::impl::DtlsTransport::runRecvLoop@503] DTLS handshake finished
|
||||
2021-03-25 14:29:49.742 INFO [21841] [rtc::impl::SctpTransport::processNotification@708] SCTP connected
|
||||
2021-03-25 14:29:49.742 INFO [21841] [rtc::impl::PeerConnection::changeState@964] Changed state to connected
|
||||
State: connected
|
||||
DataChannel from zi4B open
|
||||
#1 Received: 0 KB/s Sent: 78 KB/s BufferSize: 0
|
||||
#2 Received: 8002 KB/s Sent: 7999 KB/s BufferSize: 0
|
||||
#3 Received: 8002 KB/s Sent: 7998 KB/s BufferSize: 0
|
||||
#4 Received: 7995 KB/s Sent: 8000 KB/s BufferSize: 0
|
||||
#5 Received: 8000 KB/s Sent: 8001 KB/s BufferSize: 0
|
||||
Stats# Received Total: 33 MB Sent Total: 33 MB RTT: 0 ms
|
||||
|
||||
#6 Received: 8001 KB/s Sent: 7999 KB/s BufferSize: 0
|
||||
#7 Received: 7997 KB/s Sent: 7998 KB/s BufferSize: 0
|
||||
#8 Received: 8001 KB/s Sent: 7999 KB/s BufferSize: 0
|
||||
#9 Received: 7998 KB/s Sent: 8001 KB/s BufferSize: 0
|
||||
#10 Received: 8003 KB/s Sent: 7998 KB/s BufferSize: 0
|
||||
Stats# Received Total: 74 MB Sent Total: 74 MB RTT: 0 ms
|
||||
|
||||
#11 Received: 7990 KB/s Sent: 7998 KB/s BufferSize: 0
|
||||
#12 Received: 7999 KB/s Sent: 8000 KB/s BufferSize: 0
|
||||
#13 Received: 8001 KB/s Sent: 8002 KB/s BufferSize: 0
|
||||
#14 Received: 7998 KB/s Sent: 7999 KB/s BufferSize: 0
|
||||
#15 Received: 8000 KB/s Sent: 7998 KB/s BufferSize: 0
|
||||
Stats# Received Total: 115 MB Sent Total: 115 MB RTT: 0 ms
|
||||
```
|
513
examples/client-benchmark/getopt.cpp
Normal file
@ -0,0 +1,513 @@
|
||||
/* Getopt for Microsoft C
|
||||
This code is a modification of the Free Software Foundation, Inc.
|
||||
Getopt library for parsing command line argument the purpose was
|
||||
to provide a Microsoft Visual C friendly derivative. This code
|
||||
provides functionality for both Unicode and Multibyte builds.
|
||||
|
||||
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
|
||||
Version: 1.0
|
||||
Comment: Supports getopt, getopt_long, and getopt_long_only
|
||||
and POSIXLY_CORRECT environment flag
|
||||
License: LGPL
|
||||
|
||||
Revisions:
|
||||
|
||||
02/03/2011 - Ludvik Jerabek - Initial Release
|
||||
02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
|
||||
07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
|
||||
08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
|
||||
08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
|
||||
02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
|
||||
08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
|
||||
10/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
|
||||
06/19/2015 - Ludvik Jerabek - Fixed maximum option limitation caused by option_a (255) and option_w (65535) structure val variable
|
||||
24/10/2020 - Paul-Louis Ageneau - Removed Unicode version
|
||||
|
||||
**DISCLAIMER**
|
||||
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
||||
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
|
||||
EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
|
||||
APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
|
||||
DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
|
||||
USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
|
||||
PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
|
||||
YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
|
||||
EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*/
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include "getopt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define _GETOPT_THROW throw()
|
||||
#else
|
||||
#define _GETOPT_THROW
|
||||
#endif
|
||||
|
||||
int optind = 1;
|
||||
int opterr = 1;
|
||||
int optopt = '?';
|
||||
enum ENUM_ORDERING { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER };
|
||||
|
||||
static struct _getopt_data_a
|
||||
{
|
||||
int optind;
|
||||
int opterr;
|
||||
int optopt;
|
||||
char *optarg;
|
||||
int __initialized;
|
||||
char *__nextchar;
|
||||
enum ENUM_ORDERING __ordering;
|
||||
int __posixly_correct;
|
||||
int __first_nonopt;
|
||||
int __last_nonopt;
|
||||
} getopt_data_a;
|
||||
char *optarg_a;
|
||||
|
||||
static void exchange_a(char **argv, struct _getopt_data_a *d)
|
||||
{
|
||||
int bottom = d->__first_nonopt;
|
||||
int middle = d->__last_nonopt;
|
||||
int top = d->optind;
|
||||
char *tem;
|
||||
while (top > middle && middle > bottom)
|
||||
{
|
||||
if (top - middle > middle - bottom)
|
||||
{
|
||||
int len = middle - bottom;
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
tem = argv[bottom + i];
|
||||
argv[bottom + i] = argv[top - (middle - bottom) + i];
|
||||
argv[top - (middle - bottom) + i] = tem;
|
||||
}
|
||||
top -= len;
|
||||
}
|
||||
else
|
||||
{
|
||||
int len = top - middle;
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
tem = argv[bottom + i];
|
||||
argv[bottom + i] = argv[middle + i];
|
||||
argv[middle + i] = tem;
|
||||
}
|
||||
bottom += len;
|
||||
}
|
||||
}
|
||||
d->__first_nonopt += (d->optind - d->__last_nonopt);
|
||||
d->__last_nonopt = d->optind;
|
||||
}
|
||||
static const char *_getopt_initialize_a (const char *optstring, struct _getopt_data_a *d, int posixly_correct)
|
||||
{
|
||||
d->__first_nonopt = d->__last_nonopt = d->optind;
|
||||
d->__nextchar = NULL;
|
||||
d->__posixly_correct = posixly_correct | !!getenv("POSIXLY_CORRECT");
|
||||
if (optstring[0] == '-')
|
||||
{
|
||||
d->__ordering = RETURN_IN_ORDER;
|
||||
++optstring;
|
||||
}
|
||||
else if (optstring[0] == '+')
|
||||
{
|
||||
d->__ordering = REQUIRE_ORDER;
|
||||
++optstring;
|
||||
}
|
||||
else if (d->__posixly_correct)
|
||||
d->__ordering = REQUIRE_ORDER;
|
||||
else
|
||||
d->__ordering = PERMUTE;
|
||||
return optstring;
|
||||
}
|
||||
int _getopt_internal_r_a (int argc, char *const *argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, struct _getopt_data_a *d, int posixly_correct)
|
||||
{
|
||||
int print_errors = d->opterr;
|
||||
if (argc < 1)
|
||||
return -1;
|
||||
d->optarg = NULL;
|
||||
if (d->optind == 0 || !d->__initialized)
|
||||
{
|
||||
if (d->optind == 0)
|
||||
d->optind = 1;
|
||||
optstring = _getopt_initialize_a (optstring, d, posixly_correct);
|
||||
d->__initialized = 1;
|
||||
}
|
||||
else if (optstring[0] == '-' || optstring[0] == '+')
|
||||
optstring++;
|
||||
if (optstring[0] == ':')
|
||||
print_errors = 0;
|
||||
if (d->__nextchar == NULL || *d->__nextchar == '\0')
|
||||
{
|
||||
if (d->__last_nonopt > d->optind)
|
||||
d->__last_nonopt = d->optind;
|
||||
if (d->__first_nonopt > d->optind)
|
||||
d->__first_nonopt = d->optind;
|
||||
if (d->__ordering == PERMUTE)
|
||||
{
|
||||
if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
|
||||
exchange_a ((char **) argv, d);
|
||||
else if (d->__last_nonopt != d->optind)
|
||||
d->__first_nonopt = d->optind;
|
||||
while (d->optind < argc && (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0'))
|
||||
d->optind++;
|
||||
d->__last_nonopt = d->optind;
|
||||
}
|
||||
if (d->optind != argc && !strcmp(argv[d->optind], "--"))
|
||||
{
|
||||
d->optind++;
|
||||
if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
|
||||
exchange_a((char **) argv, d);
|
||||
else if (d->__first_nonopt == d->__last_nonopt)
|
||||
d->__first_nonopt = d->optind;
|
||||
d->__last_nonopt = argc;
|
||||
d->optind = argc;
|
||||
}
|
||||
if (d->optind == argc)
|
||||
{
|
||||
if (d->__first_nonopt != d->__last_nonopt)
|
||||
d->optind = d->__first_nonopt;
|
||||
return -1;
|
||||
}
|
||||
if ((argv[d->optind][0] != '-' || argv[d->optind][1] == '\0'))
|
||||
{
|
||||
if (d->__ordering == REQUIRE_ORDER)
|
||||
return -1;
|
||||
d->optarg = argv[d->optind++];
|
||||
return 1;
|
||||
}
|
||||
d->__nextchar = (argv[d->optind] + 1 + (longopts != NULL && argv[d->optind][1] == '-'));
|
||||
}
|
||||
if (longopts != NULL && (argv[d->optind][1] == '-' || (long_only && (argv[d->optind][2] || !strchr(optstring, argv[d->optind][1])))))
|
||||
{
|
||||
char *nameend;
|
||||
unsigned int namelen;
|
||||
const struct option_a *p;
|
||||
const struct option_a *pfound = NULL;
|
||||
struct option_list
|
||||
{
|
||||
const struct option_a *p;
|
||||
struct option_list *next;
|
||||
} *ambig_list = NULL;
|
||||
int exact = 0;
|
||||
int indfound = -1;
|
||||
int option_index;
|
||||
for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++);
|
||||
namelen = (unsigned int)(nameend - d->__nextchar);
|
||||
for (p = longopts, option_index = 0; p->name; p++, option_index++)
|
||||
if (!strncmp(p->name, d->__nextchar, namelen))
|
||||
{
|
||||
if (namelen == (unsigned int)strlen(p->name))
|
||||
{
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
exact = 1;
|
||||
break;
|
||||
}
|
||||
else if (pfound == NULL)
|
||||
{
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
}
|
||||
else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
|
||||
{
|
||||
struct option_list *newp = (struct option_list*)alloca(sizeof(*newp));
|
||||
newp->p = p;
|
||||
newp->next = ambig_list;
|
||||
ambig_list = newp;
|
||||
}
|
||||
}
|
||||
if (ambig_list != NULL && !exact)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
struct option_list first;
|
||||
first.p = pfound;
|
||||
first.next = ambig_list;
|
||||
ambig_list = &first;
|
||||
fprintf (stderr, "%s: option '%s' is ambiguous; possibilities:", argv[0], argv[d->optind]);
|
||||
do
|
||||
{
|
||||
fprintf (stderr, " '--%s'", ambig_list->p->name);
|
||||
ambig_list = ambig_list->next;
|
||||
}
|
||||
while (ambig_list != NULL);
|
||||
fputc ('\n', stderr);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
d->optind++;
|
||||
d->optopt = 0;
|
||||
return '?';
|
||||
}
|
||||
if (pfound != NULL)
|
||||
{
|
||||
option_index = indfound;
|
||||
d->optind++;
|
||||
if (*nameend)
|
||||
{
|
||||
if (pfound->has_arg)
|
||||
d->optarg = nameend + 1;
|
||||
else
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
if (argv[d->optind - 1][1] == '-')
|
||||
{
|
||||
fprintf(stderr, "%s: option '--%s' doesn't allow an argument\n",argv[0], pfound->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s: option '%c%s' doesn't allow an argument\n",argv[0], argv[d->optind - 1][0],pfound->name);
|
||||
}
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
d->optopt = pfound->val;
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
else if (pfound->has_arg == 1)
|
||||
{
|
||||
if (d->optind < argc)
|
||||
d->optarg = argv[d->optind++];
|
||||
else
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr,"%s: option '--%s' requires an argument\n",argv[0], pfound->name);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
d->optopt = pfound->val;
|
||||
return optstring[0] == ':' ? ':' : '?';
|
||||
}
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
if (longind != NULL)
|
||||
*longind = option_index;
|
||||
if (pfound->flag)
|
||||
{
|
||||
*(pfound->flag) = pfound->val;
|
||||
return 0;
|
||||
}
|
||||
return pfound->val;
|
||||
}
|
||||
if (!long_only || argv[d->optind][1] == '-' || strchr(optstring, *d->__nextchar) == NULL)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
if (argv[d->optind][1] == '-')
|
||||
{
|
||||
fprintf(stderr, "%s: unrecognized option '--%s'\n",argv[0], d->__nextchar);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s: unrecognized option '%c%s'\n",argv[0], argv[d->optind][0], d->__nextchar);
|
||||
}
|
||||
}
|
||||
d->__nextchar = (char *)"";
|
||||
d->optind++;
|
||||
d->optopt = 0;
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
{
|
||||
char c = *d->__nextchar++;
|
||||
char *temp = (char*)strchr(optstring, c);
|
||||
if (*d->__nextchar == '\0')
|
||||
++d->optind;
|
||||
if (temp == NULL || c == ':' || c == ';')
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr, "%s: invalid option -- '%c'\n", argv[0], c);
|
||||
}
|
||||
d->optopt = c;
|
||||
return '?';
|
||||
}
|
||||
if (temp[0] == 'W' && temp[1] == ';')
|
||||
{
|
||||
char *nameend;
|
||||
const struct option_a *p;
|
||||
const struct option_a *pfound = NULL;
|
||||
int exact = 0;
|
||||
int ambig = 0;
|
||||
int indfound = 0;
|
||||
int option_index;
|
||||
if (longopts == NULL)
|
||||
goto no_longs;
|
||||
if (*d->__nextchar != '\0')
|
||||
{
|
||||
d->optarg = d->__nextchar;
|
||||
d->optind++;
|
||||
}
|
||||
else if (d->optind == argc)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr,"%s: option requires an argument -- '%c'\n",argv[0], c);
|
||||
}
|
||||
d->optopt = c;
|
||||
if (optstring[0] == ':')
|
||||
c = ':';
|
||||
else
|
||||
c = '?';
|
||||
return c;
|
||||
}
|
||||
else
|
||||
d->optarg = argv[d->optind++];
|
||||
for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '='; nameend++);
|
||||
for (p = longopts, option_index = 0; p->name; p++, option_index++)
|
||||
if (!strncmp(p->name, d->__nextchar, nameend - d->__nextchar))
|
||||
{
|
||||
if ((unsigned int) (nameend - d->__nextchar) == strlen(p->name))
|
||||
{
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
exact = 1;
|
||||
break;
|
||||
}
|
||||
else if (pfound == NULL)
|
||||
{
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
}
|
||||
else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
|
||||
ambig = 1;
|
||||
}
|
||||
if (ambig && !exact)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr, "%s: option '-W %s' is ambiguous\n",argv[0], d->optarg);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
d->optind++;
|
||||
return '?';
|
||||
}
|
||||
if (pfound != NULL)
|
||||
{
|
||||
option_index = indfound;
|
||||
if (*nameend)
|
||||
{
|
||||
if (pfound->has_arg)
|
||||
d->optarg = nameend + 1;
|
||||
else
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr, "%s: option '-W %s' doesn't allow an argument\n",argv[0], pfound->name);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
else if (pfound->has_arg == 1)
|
||||
{
|
||||
if (d->optind < argc)
|
||||
d->optarg = argv[d->optind++];
|
||||
else
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr, "%s: option '-W %s' requires an argument\n",argv[0], pfound->name);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
return optstring[0] == ':' ? ':' : '?';
|
||||
}
|
||||
}
|
||||
else
|
||||
d->optarg = NULL;
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
if (longind != NULL)
|
||||
*longind = option_index;
|
||||
if (pfound->flag)
|
||||
{
|
||||
*(pfound->flag) = pfound->val;
|
||||
return 0;
|
||||
}
|
||||
return pfound->val;
|
||||
}
|
||||
no_longs:
|
||||
d->__nextchar = NULL;
|
||||
return 'W';
|
||||
}
|
||||
if (temp[1] == ':')
|
||||
{
|
||||
if (temp[2] == ':')
|
||||
{
|
||||
if (*d->__nextchar != '\0')
|
||||
{
|
||||
d->optarg = d->__nextchar;
|
||||
d->optind++;
|
||||
}
|
||||
else
|
||||
d->optarg = NULL;
|
||||
d->__nextchar = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*d->__nextchar != '\0')
|
||||
{
|
||||
d->optarg = d->__nextchar;
|
||||
d->optind++;
|
||||
}
|
||||
else if (d->optind == argc)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr,"%s: option requires an argument -- '%c'\n",argv[0], c);
|
||||
}
|
||||
d->optopt = c;
|
||||
if (optstring[0] == ':')
|
||||
c = ':';
|
||||
else
|
||||
c = '?';
|
||||
}
|
||||
else
|
||||
d->optarg = argv[d->optind++];
|
||||
d->__nextchar = NULL;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
int _getopt_internal_a (int argc, char *const *argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, int posixly_correct)
|
||||
{
|
||||
int result;
|
||||
getopt_data_a.optind = optind;
|
||||
getopt_data_a.opterr = opterr;
|
||||
result = _getopt_internal_r_a (argc, argv, optstring, longopts,longind, long_only, &getopt_data_a,posixly_correct);
|
||||
optind = getopt_data_a.optind;
|
||||
optarg_a = getopt_data_a.optarg;
|
||||
optopt = getopt_data_a.optopt;
|
||||
return result;
|
||||
}
|
||||
int getopt_a (int argc, char *const *argv, const char *optstring) _GETOPT_THROW
|
||||
{
|
||||
return _getopt_internal_a (argc, argv, optstring, (const struct option_a *) 0, (int *) 0, 0, 0);
|
||||
}
|
||||
int getopt_long_a (int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW
|
||||
{
|
||||
return _getopt_internal_a (argc, argv, options, long_options, opt_index, 0, 0);
|
||||
}
|
||||
int getopt_long_only_a (int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW
|
||||
{
|
||||
return _getopt_internal_a (argc, argv, options, long_options, opt_index, 1, 0);
|
||||
}
|
||||
int _getopt_long_r_a (int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index, struct _getopt_data_a *d)
|
||||
{
|
||||
return _getopt_internal_r_a (argc, argv, options, long_options, opt_index,0, d, 0);
|
||||
}
|
||||
int _getopt_long_only_r_a (int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index, struct _getopt_data_a *d)
|
||||
{
|
||||
return _getopt_internal_r_a (argc, argv, options, long_options, opt_index, 1, d, 0);
|
||||
}
|
||||
|
115
examples/client-benchmark/getopt.h
Normal file
@ -0,0 +1,115 @@
|
||||
/* Getopt for Microsoft C
|
||||
This code is a modification of the Free Software Foundation, Inc.
|
||||
Getopt library for parsing command line argument the purpose was
|
||||
to provide a Microsoft Visual C friendly derivative. This code
|
||||
provides functionality for both Unicode and Multibyte builds.
|
||||
|
||||
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
|
||||
Version: 1.0
|
||||
Comment: Supports getopt, getopt_long, and getopt_long_only
|
||||
and POSIXLY_CORRECT environment flag
|
||||
License: LGPL
|
||||
|
||||
Revisions:
|
||||
|
||||
02/03/2011 - Ludvik Jerabek - Initial Release
|
||||
02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
|
||||
07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
|
||||
08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
|
||||
08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
|
||||
02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
|
||||
08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
|
||||
10/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
|
||||
06/19/2015 - Ludvik Jerabek - Fixed maximum option limitation caused by option_a (255) and option_w (65535) structure val variable
|
||||
24/10/2020 - Paul-Louis Ageneau - Removed Unicode version
|
||||
|
||||
**DISCLAIMER**
|
||||
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
||||
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
|
||||
EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
|
||||
APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
|
||||
DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
|
||||
USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
|
||||
PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
|
||||
YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
|
||||
EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*/
|
||||
#ifndef __GETOPT_H_
|
||||
#define __GETOPT_H_
|
||||
|
||||
#ifdef _GETOPT_API
|
||||
#undef _GETOPT_API
|
||||
#endif
|
||||
|
||||
#if defined(EXPORTS_GETOPT) && defined(STATIC_GETOPT)
|
||||
#error "The preprocessor definitions of EXPORTS_GETOPT and STATIC_GETOPT can only be used individually"
|
||||
#elif defined(STATIC_GETOPT)
|
||||
#pragma message("Warning static builds of getopt violate the Lesser GNU Public License")
|
||||
#define _GETOPT_API
|
||||
#elif defined(EXPORTS_GETOPT)
|
||||
#pragma message("Exporting getopt library")
|
||||
#define _GETOPT_API __declspec(dllexport)
|
||||
#else
|
||||
#pragma message("Importing getopt library")
|
||||
#define _GETOPT_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
// Change behavior for C\C++
|
||||
#ifdef __cplusplus
|
||||
#define _BEGIN_EXTERN_C extern "C" {
|
||||
#define _END_EXTERN_C }
|
||||
#define _GETOPT_THROW throw()
|
||||
#else
|
||||
#define _BEGIN_EXTERN_C
|
||||
#define _END_EXTERN_C
|
||||
#define _GETOPT_THROW
|
||||
#endif
|
||||
|
||||
// Standard GNU options
|
||||
#define null_argument 0 /*Argument Null*/
|
||||
#define no_argument 0 /*Argument Switch Only*/
|
||||
#define required_argument 1 /*Argument Required*/
|
||||
#define optional_argument 2 /*Argument Optional*/
|
||||
|
||||
// Shorter Options
|
||||
#define ARG_NULL 0 /*Argument Null*/
|
||||
#define ARG_NONE 0 /*Argument Switch Only*/
|
||||
#define ARG_REQ 1 /*Argument Required*/
|
||||
#define ARG_OPT 2 /*Argument Optional*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
_BEGIN_EXTERN_C
|
||||
|
||||
extern _GETOPT_API int optind;
|
||||
extern _GETOPT_API int opterr;
|
||||
extern _GETOPT_API int optopt;
|
||||
|
||||
struct option_a
|
||||
{
|
||||
const char* name;
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
extern _GETOPT_API char *optarg_a;
|
||||
extern _GETOPT_API int getopt_a(int argc, char *const *argv, const char *optstring) _GETOPT_THROW;
|
||||
extern _GETOPT_API int getopt_long_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
|
||||
extern _GETOPT_API int getopt_long_only_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
|
||||
|
||||
_END_EXTERN_C
|
||||
|
||||
#undef _BEGIN_EXTERN_C
|
||||
#undef _END_EXTERN_C
|
||||
#undef _GETOPT_THROW
|
||||
#undef _GETOPT_API
|
||||
|
||||
#define getopt getopt_a
|
||||
#define getopt_long getopt_long_a
|
||||
#define getopt_long_only getopt_long_only_a
|
||||
#define option option_a
|
||||
#define optarg optarg_a
|
||||
|
||||
#endif // __GETOPT_H_
|
457
examples/client-benchmark/main.cpp
Normal file
@ -0,0 +1,457 @@
|
||||
/*
|
||||
* libdatachannel client-benchmark example
|
||||
* Copyright (c) 2019-2020 Paul-Louis Ageneau
|
||||
* Copyright (c) 2019-2021 Murat Dogan
|
||||
* Copyright (c) 2020 Will Munn
|
||||
* Copyright (c) 2020 Nico Chatzi
|
||||
* Copyright (c) 2020 Lara Mackey
|
||||
* Copyright (c) 2020 Erik Cota-Robles
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "rtc/rtc.hpp"
|
||||
|
||||
#include "parse_cl.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace rtc;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
using chrono::milliseconds;
|
||||
using chrono::steady_clock;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
template <class T> weak_ptr<T> make_weak_ptr(shared_ptr<T> ptr) { return ptr; }
|
||||
|
||||
unordered_map<string, shared_ptr<PeerConnection>> peerConnectionMap;
|
||||
unordered_map<string, shared_ptr<DataChannel>> dataChannelMap;
|
||||
|
||||
string localId;
|
||||
|
||||
shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
|
||||
weak_ptr<WebSocket> wws, string id);
|
||||
string randomId(size_t length);
|
||||
|
||||
// Benchmark
|
||||
const size_t messageSize = 65535;
|
||||
binary messageData(messageSize);
|
||||
atomic<size_t> receivedSize = 0, sentSize = 0;
|
||||
bool noSend = false;
|
||||
|
||||
// Benchmark - enableThroughputSet params
|
||||
bool enableThroughputSet;
|
||||
int throughtputSetAsKB;
|
||||
int bufferSize;
|
||||
const float STEP_COUNT_FOR_1_SEC = 100.0;
|
||||
const int stepDurationInMs = 1000 / STEP_COUNT_FOR_1_SEC;
|
||||
|
||||
int main(int argc, char **argv) try {
|
||||
Cmdline params(argc, argv);
|
||||
|
||||
rtc::InitLogger(LogLevel::Info);
|
||||
|
||||
// Benchmark - construct message to send
|
||||
fill(messageData.begin(), messageData.end(), std::byte(0xFF));
|
||||
|
||||
// Benchmark - enableThroughputSet params
|
||||
enableThroughputSet = params.enableThroughputSet();
|
||||
throughtputSetAsKB = params.throughtputSetAsKB();
|
||||
bufferSize = params.bufferSize();
|
||||
|
||||
// No Send option
|
||||
noSend = params.noSend();
|
||||
if (noSend)
|
||||
cout << "Not Sending data. (One way benchmark)." << endl;
|
||||
|
||||
Configuration config;
|
||||
string stunServer = "";
|
||||
if (params.noStun()) {
|
||||
cout << "No STUN server is configured. Only local hosts and public IP addresses supported."
|
||||
<< endl;
|
||||
} else {
|
||||
if (params.stunServer().substr(0, 5).compare("stun:") != 0) {
|
||||
stunServer = "stun:";
|
||||
}
|
||||
stunServer += params.stunServer() + ":" + to_string(params.stunPort());
|
||||
cout << "Stun server is " << stunServer << endl;
|
||||
config.iceServers.emplace_back(stunServer);
|
||||
}
|
||||
|
||||
localId = randomId(4);
|
||||
cout << "The local ID is: " << localId << endl;
|
||||
|
||||
auto ws = make_shared<WebSocket>();
|
||||
|
||||
std::promise<void> wsPromise;
|
||||
auto wsFuture = wsPromise.get_future();
|
||||
|
||||
ws->onOpen([&wsPromise]() {
|
||||
cout << "WebSocket connected, signaling ready" << endl;
|
||||
wsPromise.set_value();
|
||||
});
|
||||
|
||||
ws->onError([&wsPromise](string s) {
|
||||
cout << "WebSocket error" << endl;
|
||||
wsPromise.set_exception(std::make_exception_ptr(std::runtime_error(s)));
|
||||
});
|
||||
|
||||
ws->onClosed([]() { cout << "WebSocket closed" << endl; });
|
||||
|
||||
ws->onMessage([&](variant<binary, string> data) {
|
||||
if (!holds_alternative<string>(data))
|
||||
return;
|
||||
|
||||
json message = json::parse(get<string>(data));
|
||||
|
||||
auto it = message.find("id");
|
||||
if (it == message.end())
|
||||
return;
|
||||
string id = it->get<string>();
|
||||
|
||||
it = message.find("type");
|
||||
if (it == message.end())
|
||||
return;
|
||||
string type = it->get<string>();
|
||||
|
||||
shared_ptr<PeerConnection> pc;
|
||||
if (auto jt = peerConnectionMap.find(id); jt != peerConnectionMap.end()) {
|
||||
pc = jt->second;
|
||||
} else if (type == "offer") {
|
||||
cout << "Answering to " + id << endl;
|
||||
pc = createPeerConnection(config, ws, id);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == "offer" || type == "answer") {
|
||||
auto sdp = message["description"].get<string>();
|
||||
pc->setRemoteDescription(Description(sdp, type));
|
||||
} else if (type == "candidate") {
|
||||
auto sdp = message["candidate"].get<string>();
|
||||
auto mid = message["mid"].get<string>();
|
||||
pc->addRemoteCandidate(Candidate(sdp, mid));
|
||||
}
|
||||
});
|
||||
|
||||
string wsPrefix = "";
|
||||
if (params.webSocketServer().substr(0, 5).compare("ws://") != 0) {
|
||||
wsPrefix = "ws://";
|
||||
}
|
||||
const string url = wsPrefix + params.webSocketServer() + ":" +
|
||||
to_string(params.webSocketPort()) + "/" + localId;
|
||||
cout << "Url is " << url << endl;
|
||||
ws->open(url);
|
||||
|
||||
cout << "Waiting for signaling to be connected..." << endl;
|
||||
wsFuture.get();
|
||||
|
||||
string id;
|
||||
cout << "Enter a remote ID to send an offer:" << endl;
|
||||
cin >> id;
|
||||
cin.ignore();
|
||||
if (id.empty()) {
|
||||
// Nothing to do
|
||||
return 0;
|
||||
}
|
||||
if (id == localId) {
|
||||
cout << "Invalid remote ID (This is my local ID). Exiting..." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
cout << "Offering to " + id << endl;
|
||||
auto pc = createPeerConnection(config, ws, id);
|
||||
|
||||
// We are the offerer, so create a data channel to initiate the process
|
||||
const string label = "benchmark";
|
||||
cout << "Creating DataChannel with label \"" << label << "\"" << endl;
|
||||
auto dc = pc->createDataChannel(label);
|
||||
|
||||
// Set Buffer Size
|
||||
dc->setBufferedAmountLowThreshold(bufferSize);
|
||||
|
||||
dc->onOpen([id, wdc = make_weak_ptr(dc)]() {
|
||||
cout << "DataChannel from " << id << " open" << endl;
|
||||
if (noSend)
|
||||
return;
|
||||
|
||||
if (enableThroughputSet)
|
||||
return;
|
||||
|
||||
if (auto dcLocked = wdc.lock()) {
|
||||
try {
|
||||
while (dcLocked->bufferedAmount() <= bufferSize) {
|
||||
dcLocked->send(messageData);
|
||||
sentSize += messageData.size();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << "Send failed: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dc->onBufferedAmountLow([wdc = make_weak_ptr(dc)]() {
|
||||
if (noSend)
|
||||
return;
|
||||
|
||||
if (enableThroughputSet)
|
||||
return;
|
||||
|
||||
auto dcLocked = wdc.lock();
|
||||
if (!dcLocked)
|
||||
return;
|
||||
|
||||
// Continue sending
|
||||
try {
|
||||
while (dcLocked->isOpen() && dcLocked->bufferedAmount() <= bufferSize) {
|
||||
dcLocked->send(messageData);
|
||||
sentSize += messageData.size();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << "Send failed: " << e.what() << std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
|
||||
|
||||
dc->onMessage([id, wdc = make_weak_ptr(dc)](variant<binary, string> data) {
|
||||
if (holds_alternative<binary>(data))
|
||||
receivedSize += get<binary>(data).size();
|
||||
});
|
||||
|
||||
dataChannelMap.emplace(id, dc);
|
||||
|
||||
const int duration = params.durationInSec() > 0 ? params.durationInSec() : INT32_MAX;
|
||||
cout << "Benchmark will run for " << duration << " seconds" << endl;
|
||||
|
||||
int printCounter = 0;
|
||||
int printStatCounter = 0;
|
||||
steady_clock::time_point printTime = steady_clock::now();
|
||||
steady_clock::time_point stepTime = steady_clock::now();
|
||||
// Byte count to send for every loop
|
||||
int byteToSendOnEveryLoop = throughtputSetAsKB * stepDurationInMs;
|
||||
for (int i = 1; i <= duration * STEP_COUNT_FOR_1_SEC; ++i) {
|
||||
this_thread::sleep_for(milliseconds(stepDurationInMs));
|
||||
printCounter++;
|
||||
|
||||
if (enableThroughputSet) {
|
||||
const double elapsedTimeInSecs =
|
||||
std::chrono::duration<double>(steady_clock::now() - stepTime).count();
|
||||
|
||||
stepTime = steady_clock::now();
|
||||
|
||||
int byteToSendThisLoop = static_cast<int>(
|
||||
byteToSendOnEveryLoop * ((elapsedTimeInSecs * 1000.0) / stepDurationInMs));
|
||||
|
||||
binary tempMessageData(byteToSendThisLoop);
|
||||
fill(tempMessageData.begin(), tempMessageData.end(), std::byte(0xFF));
|
||||
|
||||
if (dc->isOpen() && dc->bufferedAmount() <= bufferSize * byteToSendOnEveryLoop) {
|
||||
dc->send(tempMessageData);
|
||||
sentSize += tempMessageData.size();
|
||||
}
|
||||
}
|
||||
|
||||
if (printCounter >= STEP_COUNT_FOR_1_SEC) {
|
||||
unsigned long _receivedSize = receivedSize.exchange(0);
|
||||
unsigned long _sentSize = sentSize.exchange(0);
|
||||
const double elapsedTimeInSecs =
|
||||
std::chrono::duration<double>(steady_clock::now() - printTime).count();
|
||||
printTime = steady_clock::now();
|
||||
|
||||
cout << "#" << i / STEP_COUNT_FOR_1_SEC
|
||||
<< " Received: " << static_cast<int>(_receivedSize / (elapsedTimeInSecs * 1000))
|
||||
<< " KB/s"
|
||||
<< " Sent: " << static_cast<int>(_sentSize / (elapsedTimeInSecs * 1000))
|
||||
<< " KB/s"
|
||||
<< " BufferSize: " << dc->bufferedAmount() << endl;
|
||||
printStatCounter++;
|
||||
printCounter = 0;
|
||||
}
|
||||
|
||||
if (printStatCounter >= 5) {
|
||||
cout << "Stats# "
|
||||
<< "Received Total: " << pc->bytesReceived() / (1000 * 1000) << " MB"
|
||||
<< " Sent Total: " << pc->bytesSent() / (1000 * 1000) << " MB"
|
||||
<< " RTT: " << pc->rtt().value_or(0ms).count() << " ms" << endl;
|
||||
cout << endl;
|
||||
printStatCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Cleaning up..." << endl;
|
||||
|
||||
dataChannelMap.clear();
|
||||
peerConnectionMap.clear();
|
||||
return 0;
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << "Error: " << e.what() << std::endl;
|
||||
dataChannelMap.clear();
|
||||
peerConnectionMap.clear();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create and setup a PeerConnection
|
||||
shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
|
||||
weak_ptr<WebSocket> wws, string id) {
|
||||
auto pc = make_shared<PeerConnection>(config);
|
||||
|
||||
pc->onStateChange([](PeerConnection::State state) { cout << "State: " << state << endl; });
|
||||
|
||||
pc->onGatheringStateChange(
|
||||
[](PeerConnection::GatheringState state) { cout << "Gathering State: " << state << endl; });
|
||||
|
||||
pc->onLocalDescription([wws, id](Description description) {
|
||||
json message = {
|
||||
{"id", id}, {"type", description.typeString()}, {"description", string(description)}};
|
||||
|
||||
if (auto ws = wws.lock())
|
||||
ws->send(message.dump());
|
||||
});
|
||||
|
||||
pc->onLocalCandidate([wws, id](Candidate candidate) {
|
||||
json message = {{"id", id},
|
||||
{"type", "candidate"},
|
||||
{"candidate", string(candidate)},
|
||||
{"mid", candidate.mid()}};
|
||||
|
||||
if (auto ws = wws.lock())
|
||||
ws->send(message.dump());
|
||||
});
|
||||
|
||||
pc->onDataChannel([id](shared_ptr<DataChannel> dc) {
|
||||
cout << "DataChannel from " << id << " received with label \"" << dc->label() << "\""
|
||||
<< endl;
|
||||
|
||||
cout << "###########################################" << endl;
|
||||
cout << "### Check other peer's screen for stats ###" << endl;
|
||||
cout << "###########################################" << endl;
|
||||
|
||||
// Set Buffer Size
|
||||
dc->setBufferedAmountLowThreshold(bufferSize);
|
||||
|
||||
if (!noSend && !enableThroughputSet) {
|
||||
try {
|
||||
while (dc->bufferedAmount() <= bufferSize) {
|
||||
dc->send(messageData);
|
||||
sentSize += messageData.size();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << "Send failed: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!noSend && enableThroughputSet) {
|
||||
// Create Send Data Thread
|
||||
// Thread will join when data channel destroyed or closed
|
||||
std::thread([wdc = make_weak_ptr(dc)]() {
|
||||
steady_clock::time_point stepTime = steady_clock::now();
|
||||
// Byte count to send for every loop
|
||||
int byteToSendOnEveryLoop = throughtputSetAsKB * stepDurationInMs;
|
||||
while (true) {
|
||||
this_thread::sleep_for(milliseconds(stepDurationInMs));
|
||||
|
||||
auto dcLocked = wdc.lock();
|
||||
if (!dcLocked)
|
||||
break;
|
||||
|
||||
if (!dcLocked->isOpen())
|
||||
break;
|
||||
|
||||
try {
|
||||
const double elapsedTimeInSecs =
|
||||
std::chrono::duration<double>(steady_clock::now() - stepTime).count();
|
||||
|
||||
stepTime = steady_clock::now();
|
||||
|
||||
int byteToSendThisLoop =
|
||||
static_cast<int>(byteToSendOnEveryLoop *
|
||||
((elapsedTimeInSecs * 1000.0) / stepDurationInMs));
|
||||
|
||||
binary tempMessageData(byteToSendThisLoop);
|
||||
fill(tempMessageData.begin(), tempMessageData.end(), std::byte(0xFF));
|
||||
|
||||
if (dcLocked->bufferedAmount() <= bufferSize) {
|
||||
dcLocked->send(tempMessageData);
|
||||
sentSize += tempMessageData.size();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << "Send failed: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
cout << "Send Data Thread exiting..." << endl;
|
||||
}).detach();
|
||||
}
|
||||
|
||||
dc->onBufferedAmountLow([wdc = make_weak_ptr(dc)]() {
|
||||
if (noSend)
|
||||
return;
|
||||
|
||||
if (enableThroughputSet)
|
||||
return;
|
||||
|
||||
auto dcLocked = wdc.lock();
|
||||
if (!dcLocked)
|
||||
return;
|
||||
|
||||
// Continue sending
|
||||
try {
|
||||
while (dcLocked->isOpen() && dcLocked->bufferedAmount() <= bufferSize) {
|
||||
dcLocked->send(messageData);
|
||||
sentSize += messageData.size();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << "Send failed: " << e.what() << std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
|
||||
|
||||
dc->onMessage([id, wdc = make_weak_ptr(dc)](variant<binary, string> data) {
|
||||
if (holds_alternative<binary>(data))
|
||||
receivedSize += get<binary>(data).size();
|
||||
});
|
||||
|
||||
dataChannelMap.emplace(id, dc);
|
||||
});
|
||||
|
||||
peerConnectionMap.emplace(id, pc);
|
||||
return pc;
|
||||
};
|
||||
|
||||
// Helper function to generate a random ID
|
||||
string randomId(size_t length) {
|
||||
static const string characters(
|
||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
|
||||
string id(length, '0');
|
||||
default_random_engine rng(random_device{}());
|
||||
uniform_int_distribution<int> dist(0, int(characters.size() - 1));
|
||||
generate(id.begin(), id.end(), [&]() { return characters.at(dist(rng)); });
|
||||
return id;
|
||||
}
|
203
examples/client-benchmark/parse_cl.cpp
Normal file
@ -0,0 +1,203 @@
|
||||
/******************************************************************************
|
||||
**
|
||||
** parse_cl.cpp
|
||||
**
|
||||
** Thu Aug 6 19:42:25 2020
|
||||
** Linux 5.4.0-42-generic (#46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020) x86_64
|
||||
** cerik@Erik-VBox-Ubuntu (Erik Cota-Robles)
|
||||
**
|
||||
** Copyright (c) 2020 Erik Cota-Robles
|
||||
**
|
||||
** Definition of command line parser class
|
||||
**
|
||||
** Automatically created by genparse v0.9.3
|
||||
**
|
||||
** See http://genparse.sourceforge.net for details and updates
|
||||
**
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#include "getopt.h"
|
||||
#else
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#include "parse_cl.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
**
|
||||
** Cmdline::Cmdline ()
|
||||
**
|
||||
** Constructor method.
|
||||
**
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
Cmdline::Cmdline(int argc, char *argv[]) // ISO C++17 not allowed: throw (std::string )
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
int c;
|
||||
|
||||
static struct option long_options[] = {{"noStun", no_argument, NULL, 'n'},
|
||||
{"stunServer", required_argument, NULL, 's'},
|
||||
{"stunPort", required_argument, NULL, 't'},
|
||||
{"webSocketServer", required_argument, NULL, 'w'},
|
||||
{"webSocketPort", required_argument, NULL, 'x'},
|
||||
{"durationInSec", required_argument, NULL, 'd'},
|
||||
{"noSend", no_argument, NULL, 'o'},
|
||||
{"enableThroughputSet", no_argument, NULL, 'p'},
|
||||
{"throughtputSetAsKB", required_argument, NULL, 'r'},
|
||||
{"bufferSize", required_argument, NULL, 'b'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{NULL, 0, NULL, 0}};
|
||||
|
||||
_program_name += argv[0];
|
||||
|
||||
/* default values */
|
||||
_n = false;
|
||||
_s = "stun.l.google.com";
|
||||
_t = 19302;
|
||||
_w = "localhost";
|
||||
_x = 8000;
|
||||
_h = false;
|
||||
_d = 300;
|
||||
_o = false;
|
||||
_p = false;
|
||||
_r = 300;
|
||||
_b = 0;
|
||||
|
||||
optind = 0;
|
||||
while ((c = getopt_long(argc, argv, "s:t:w:x:d:r:b:enhvop", long_options, &optind)) != -1) {
|
||||
switch (c) {
|
||||
case 'n':
|
||||
_n = true;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
_s = optarg;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
_t = atoi(optarg);
|
||||
if (_t < 0) {
|
||||
std::string err;
|
||||
err += "parameter range error: t must be >= 0";
|
||||
throw(std::range_error(err));
|
||||
}
|
||||
if (_t > 65535) {
|
||||
std::string err;
|
||||
err += "parameter range error: t must be <= 65535";
|
||||
throw(std::range_error(err));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
_w = optarg;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
_x = atoi(optarg);
|
||||
if (_x < 0) {
|
||||
std::string err;
|
||||
err += "parameter range error: x must be >= 0";
|
||||
throw(std::range_error(err));
|
||||
}
|
||||
if (_x > 65535) {
|
||||
std::string err;
|
||||
err += "parameter range error: x must be <= 65535";
|
||||
throw(std::range_error(err));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
_d = atoi(optarg);
|
||||
if (_d < 0) {
|
||||
std::string err;
|
||||
err += "parameter range error: d must be >= 0";
|
||||
throw(std::range_error(err));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
_o = true;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
_b = atoi(optarg);
|
||||
if (_b < 0) {
|
||||
std::string err;
|
||||
err += "parameter range error: b must be >= 0";
|
||||
throw(std::range_error(err));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
_p = true;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
_r = atoi(optarg);
|
||||
if (_r <= 0) {
|
||||
std::string err;
|
||||
err += "parameter range error: r must be > 0";
|
||||
throw(std::range_error(err));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
_h = true;
|
||||
this->usage(EXIT_SUCCESS);
|
||||
break;
|
||||
|
||||
default:
|
||||
this->usage(EXIT_FAILURE);
|
||||
}
|
||||
} /* while */
|
||||
|
||||
_optind = optind;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
**
|
||||
** Cmdline::usage () and version()
|
||||
**
|
||||
** Print out usage (or version) information, then exit.
|
||||
**
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
void Cmdline::usage(int status) {
|
||||
if (status != EXIT_SUCCESS)
|
||||
std::cerr << "Try `" << _program_name << " --help' for more information.\n";
|
||||
else {
|
||||
std::cout << "\
|
||||
usage: " << _program_name
|
||||
<< " [ -enstwxdobprhv ] \n\
|
||||
libdatachannel client implementing WebRTC Data Channels with WebSocket signaling\n\
|
||||
[ -n ] [ --noStun ] (type=FLAG)\n\
|
||||
Do NOT use a stun server (overrides -s and -t).\n\
|
||||
[ -s ] [ --stunServer ] (type=STRING, default=stun.l.google.com)\n\
|
||||
Stun server URL or IP address.\n\
|
||||
[ -t ] [ --stunPort ] (type=INTEGER, range=0...65535, default=19302)\n\
|
||||
Stun server port.\n\
|
||||
[ -w ] [ --webSocketServer ] (type=STRING, default=localhost)\n\
|
||||
Web socket server URL or IP address.\n\
|
||||
[ -x ] [ --webSocketPort ] (type=INTEGER, range=0...65535, default=8000)\n\
|
||||
Web socket server port.\n\
|
||||
[ -d ] [ --durationInSec ] (type=INTEGER, range>=0...INT32_MAX, 0:infinite(INT32_MAX), Valid only for offering client, default=300)\n\
|
||||
Benchmark duration in seconds.\n\
|
||||
[ -o ] [ --noSend ] (type=FLAG)\n\
|
||||
Do NOT send message (Only Receive, for one-way testing purposes).\n\
|
||||
[ -b ] [ --bufferSize ] (type=INTEGER, range>0...INT_MAX, default=0)\n\
|
||||
Set internal buffer size .\n\
|
||||
[ -p ] [ --enableThroughputSet ] (type=FLAG)\n\
|
||||
Send a constant data per second (KB). See throughtputSetAsKB params.\n\
|
||||
[ -r ] [ --throughtputSetAsKB ] (type=INTEGER, range>0...INT_MAX, default=300)\n\
|
||||
Send constant data per second (KB).\n\
|
||||
[ -h ] [ --help ] (type=FLAG)\n\
|
||||
Display this help and exit.\n";
|
||||
}
|
||||
exit(status);
|
||||
}
|
77
examples/client-benchmark/parse_cl.h
Normal file
@ -0,0 +1,77 @@
|
||||
/******************************************************************************
|
||||
**
|
||||
** parse_cl.h
|
||||
**
|
||||
** Thu Aug 6 19:42:25 2020
|
||||
** Linux 5.4.0-42-generic (#46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020) x86_64
|
||||
** cerik@Erik-VBox-Ubuntu (Erik Cota-Robles)
|
||||
**
|
||||
** Copyright (c) 2020 Erik Cota-Robles
|
||||
**
|
||||
** Header file for command line parser class
|
||||
**
|
||||
** Automatically created by genparse v0.9.3
|
||||
**
|
||||
** See http://genparse.sourceforge.net for details and updates
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CMDLINE_H
|
||||
#define CMDLINE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
**
|
||||
** class Cmdline
|
||||
**
|
||||
** command line parser class
|
||||
**
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
class Cmdline
|
||||
{
|
||||
private:
|
||||
/* parameters */
|
||||
bool _n;
|
||||
std::string _s;
|
||||
int _t;
|
||||
std::string _w;
|
||||
int _x;
|
||||
bool _h;
|
||||
int _d;
|
||||
bool _o;
|
||||
bool _p;
|
||||
int _r;
|
||||
int _b;
|
||||
|
||||
/* other stuff to keep track of */
|
||||
std::string _program_name;
|
||||
int _optind;
|
||||
|
||||
public:
|
||||
/* constructor and destructor */
|
||||
Cmdline (int, char **); // ISO C++17 not allowed: throw (std::string);
|
||||
~Cmdline (){}
|
||||
|
||||
/* usage function */
|
||||
void usage (int status);
|
||||
|
||||
/* return next (non-option) parameter */
|
||||
int next_param () { return _optind; }
|
||||
|
||||
bool noStun () const { return _n; }
|
||||
std::string stunServer () const { return _s; }
|
||||
int stunPort () const { return _t; }
|
||||
std::string webSocketServer () const { return _w; }
|
||||
int webSocketPort () const { return _x; }
|
||||
bool h () const { return _h; }
|
||||
int durationInSec () const { return _d; }
|
||||
bool noSend () const { return _o; }
|
||||
int bufferSize() const { return _b;}
|
||||
bool enableThroughputSet () const { return _p; }
|
||||
int throughtputSetAsKB() const { return _r;}
|
||||
};
|
||||
|
||||
#endif
|
@ -3,9 +3,36 @@ if(POLICY CMP0079)
|
||||
cmake_policy(SET CMP0079 NEW)
|
||||
endif()
|
||||
|
||||
add_executable(datachannel-client main.cpp)
|
||||
set(CLIENT_UWP_RESOURCES
|
||||
uwp/Logo.png
|
||||
uwp/package.appxManifest
|
||||
uwp/SmallLogo.png
|
||||
uwp/SmallLogo44x44.png
|
||||
uwp/SplashScreen.png
|
||||
uwp/StoreLogo.png
|
||||
uwp/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
add_executable(datachannel-client main.cpp parse_cl.cpp parse_cl.h getopt.cpp getopt.h ${CLIENT_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-client main.cpp parse_cl.cpp parse_cl.h getopt.cpp getopt.h)
|
||||
endif()
|
||||
target_compile_definitions(datachannel-client PUBLIC STATIC_GETOPT)
|
||||
else()
|
||||
add_executable(datachannel-client main.cpp parse_cl.cpp parse_cl.h)
|
||||
endif()
|
||||
|
||||
set_target_properties(datachannel-client PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
OUTPUT_NAME client)
|
||||
target_link_libraries(datachannel-client datachannel nlohmann_json)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET datachannel-client POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
|
||||
$<TARGET_FILE_DIR:datachannel-client>
|
||||
)
|
||||
endif()
|
||||
|
513
examples/client/getopt.cpp
Normal file
@ -0,0 +1,513 @@
|
||||
/* Getopt for Microsoft C
|
||||
This code is a modification of the Free Software Foundation, Inc.
|
||||
Getopt library for parsing command line argument the purpose was
|
||||
to provide a Microsoft Visual C friendly derivative. This code
|
||||
provides functionality for both Unicode and Multibyte builds.
|
||||
|
||||
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
|
||||
Version: 1.0
|
||||
Comment: Supports getopt, getopt_long, and getopt_long_only
|
||||
and POSIXLY_CORRECT environment flag
|
||||
License: LGPL
|
||||
|
||||
Revisions:
|
||||
|
||||
02/03/2011 - Ludvik Jerabek - Initial Release
|
||||
02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
|
||||
07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
|
||||
08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
|
||||
08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
|
||||
02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
|
||||
08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
|
||||
10/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
|
||||
06/19/2015 - Ludvik Jerabek - Fixed maximum option limitation caused by option_a (255) and option_w (65535) structure val variable
|
||||
24/10/2020 - Paul-Louis Ageneau - Removed Unicode version
|
||||
|
||||
**DISCLAIMER**
|
||||
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
||||
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
|
||||
EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
|
||||
APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
|
||||
DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
|
||||
USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
|
||||
PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
|
||||
YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
|
||||
EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*/
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include "getopt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define _GETOPT_THROW throw()
|
||||
#else
|
||||
#define _GETOPT_THROW
|
||||
#endif
|
||||
|
||||
int optind = 1;
|
||||
int opterr = 1;
|
||||
int optopt = '?';
|
||||
enum ENUM_ORDERING { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER };
|
||||
|
||||
static struct _getopt_data_a
|
||||
{
|
||||
int optind;
|
||||
int opterr;
|
||||
int optopt;
|
||||
char *optarg;
|
||||
int __initialized;
|
||||
char *__nextchar;
|
||||
enum ENUM_ORDERING __ordering;
|
||||
int __posixly_correct;
|
||||
int __first_nonopt;
|
||||
int __last_nonopt;
|
||||
} getopt_data_a;
|
||||
char *optarg_a;
|
||||
|
||||
static void exchange_a(char **argv, struct _getopt_data_a *d)
|
||||
{
|
||||
int bottom = d->__first_nonopt;
|
||||
int middle = d->__last_nonopt;
|
||||
int top = d->optind;
|
||||
char *tem;
|
||||
while (top > middle && middle > bottom)
|
||||
{
|
||||
if (top - middle > middle - bottom)
|
||||
{
|
||||
int len = middle - bottom;
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
tem = argv[bottom + i];
|
||||
argv[bottom + i] = argv[top - (middle - bottom) + i];
|
||||
argv[top - (middle - bottom) + i] = tem;
|
||||
}
|
||||
top -= len;
|
||||
}
|
||||
else
|
||||
{
|
||||
int len = top - middle;
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
tem = argv[bottom + i];
|
||||
argv[bottom + i] = argv[middle + i];
|
||||
argv[middle + i] = tem;
|
||||
}
|
||||
bottom += len;
|
||||
}
|
||||
}
|
||||
d->__first_nonopt += (d->optind - d->__last_nonopt);
|
||||
d->__last_nonopt = d->optind;
|
||||
}
|
||||
static const char *_getopt_initialize_a (const char *optstring, struct _getopt_data_a *d, int posixly_correct)
|
||||
{
|
||||
d->__first_nonopt = d->__last_nonopt = d->optind;
|
||||
d->__nextchar = NULL;
|
||||
d->__posixly_correct = posixly_correct | !!getenv("POSIXLY_CORRECT");
|
||||
if (optstring[0] == '-')
|
||||
{
|
||||
d->__ordering = RETURN_IN_ORDER;
|
||||
++optstring;
|
||||
}
|
||||
else if (optstring[0] == '+')
|
||||
{
|
||||
d->__ordering = REQUIRE_ORDER;
|
||||
++optstring;
|
||||
}
|
||||
else if (d->__posixly_correct)
|
||||
d->__ordering = REQUIRE_ORDER;
|
||||
else
|
||||
d->__ordering = PERMUTE;
|
||||
return optstring;
|
||||
}
|
||||
int _getopt_internal_r_a (int argc, char *const *argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, struct _getopt_data_a *d, int posixly_correct)
|
||||
{
|
||||
int print_errors = d->opterr;
|
||||
if (argc < 1)
|
||||
return -1;
|
||||
d->optarg = NULL;
|
||||
if (d->optind == 0 || !d->__initialized)
|
||||
{
|
||||
if (d->optind == 0)
|
||||
d->optind = 1;
|
||||
optstring = _getopt_initialize_a (optstring, d, posixly_correct);
|
||||
d->__initialized = 1;
|
||||
}
|
||||
else if (optstring[0] == '-' || optstring[0] == '+')
|
||||
optstring++;
|
||||
if (optstring[0] == ':')
|
||||
print_errors = 0;
|
||||
if (d->__nextchar == NULL || *d->__nextchar == '\0')
|
||||
{
|
||||
if (d->__last_nonopt > d->optind)
|
||||
d->__last_nonopt = d->optind;
|
||||
if (d->__first_nonopt > d->optind)
|
||||
d->__first_nonopt = d->optind;
|
||||
if (d->__ordering == PERMUTE)
|
||||
{
|
||||
if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
|
||||
exchange_a ((char **) argv, d);
|
||||
else if (d->__last_nonopt != d->optind)
|
||||
d->__first_nonopt = d->optind;
|
||||
while (d->optind < argc && (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0'))
|
||||
d->optind++;
|
||||
d->__last_nonopt = d->optind;
|
||||
}
|
||||
if (d->optind != argc && !strcmp(argv[d->optind], "--"))
|
||||
{
|
||||
d->optind++;
|
||||
if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
|
||||
exchange_a((char **) argv, d);
|
||||
else if (d->__first_nonopt == d->__last_nonopt)
|
||||
d->__first_nonopt = d->optind;
|
||||
d->__last_nonopt = argc;
|
||||
d->optind = argc;
|
||||
}
|
||||
if (d->optind == argc)
|
||||
{
|
||||
if (d->__first_nonopt != d->__last_nonopt)
|
||||
d->optind = d->__first_nonopt;
|
||||
return -1;
|
||||
}
|
||||
if ((argv[d->optind][0] != '-' || argv[d->optind][1] == '\0'))
|
||||
{
|
||||
if (d->__ordering == REQUIRE_ORDER)
|
||||
return -1;
|
||||
d->optarg = argv[d->optind++];
|
||||
return 1;
|
||||
}
|
||||
d->__nextchar = (argv[d->optind] + 1 + (longopts != NULL && argv[d->optind][1] == '-'));
|
||||
}
|
||||
if (longopts != NULL && (argv[d->optind][1] == '-' || (long_only && (argv[d->optind][2] || !strchr(optstring, argv[d->optind][1])))))
|
||||
{
|
||||
char *nameend;
|
||||
unsigned int namelen;
|
||||
const struct option_a *p;
|
||||
const struct option_a *pfound = NULL;
|
||||
struct option_list
|
||||
{
|
||||
const struct option_a *p;
|
||||
struct option_list *next;
|
||||
} *ambig_list = NULL;
|
||||
int exact = 0;
|
||||
int indfound = -1;
|
||||
int option_index;
|
||||
for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++);
|
||||
namelen = (unsigned int)(nameend - d->__nextchar);
|
||||
for (p = longopts, option_index = 0; p->name; p++, option_index++)
|
||||
if (!strncmp(p->name, d->__nextchar, namelen))
|
||||
{
|
||||
if (namelen == (unsigned int)strlen(p->name))
|
||||
{
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
exact = 1;
|
||||
break;
|
||||
}
|
||||
else if (pfound == NULL)
|
||||
{
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
}
|
||||
else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
|
||||
{
|
||||
struct option_list *newp = (struct option_list*)alloca(sizeof(*newp));
|
||||
newp->p = p;
|
||||
newp->next = ambig_list;
|
||||
ambig_list = newp;
|
||||
}
|
||||
}
|
||||
if (ambig_list != NULL && !exact)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
struct option_list first;
|
||||
first.p = pfound;
|
||||
first.next = ambig_list;
|
||||
ambig_list = &first;
|
||||
fprintf (stderr, "%s: option '%s' is ambiguous; possibilities:", argv[0], argv[d->optind]);
|
||||
do
|
||||
{
|
||||
fprintf (stderr, " '--%s'", ambig_list->p->name);
|
||||
ambig_list = ambig_list->next;
|
||||
}
|
||||
while (ambig_list != NULL);
|
||||
fputc ('\n', stderr);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
d->optind++;
|
||||
d->optopt = 0;
|
||||
return '?';
|
||||
}
|
||||
if (pfound != NULL)
|
||||
{
|
||||
option_index = indfound;
|
||||
d->optind++;
|
||||
if (*nameend)
|
||||
{
|
||||
if (pfound->has_arg)
|
||||
d->optarg = nameend + 1;
|
||||
else
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
if (argv[d->optind - 1][1] == '-')
|
||||
{
|
||||
fprintf(stderr, "%s: option '--%s' doesn't allow an argument\n",argv[0], pfound->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s: option '%c%s' doesn't allow an argument\n",argv[0], argv[d->optind - 1][0],pfound->name);
|
||||
}
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
d->optopt = pfound->val;
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
else if (pfound->has_arg == 1)
|
||||
{
|
||||
if (d->optind < argc)
|
||||
d->optarg = argv[d->optind++];
|
||||
else
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr,"%s: option '--%s' requires an argument\n",argv[0], pfound->name);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
d->optopt = pfound->val;
|
||||
return optstring[0] == ':' ? ':' : '?';
|
||||
}
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
if (longind != NULL)
|
||||
*longind = option_index;
|
||||
if (pfound->flag)
|
||||
{
|
||||
*(pfound->flag) = pfound->val;
|
||||
return 0;
|
||||
}
|
||||
return pfound->val;
|
||||
}
|
||||
if (!long_only || argv[d->optind][1] == '-' || strchr(optstring, *d->__nextchar) == NULL)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
if (argv[d->optind][1] == '-')
|
||||
{
|
||||
fprintf(stderr, "%s: unrecognized option '--%s'\n",argv[0], d->__nextchar);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s: unrecognized option '%c%s'\n",argv[0], argv[d->optind][0], d->__nextchar);
|
||||
}
|
||||
}
|
||||
d->__nextchar = (char *)"";
|
||||
d->optind++;
|
||||
d->optopt = 0;
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
{
|
||||
char c = *d->__nextchar++;
|
||||
char *temp = (char*)strchr(optstring, c);
|
||||
if (*d->__nextchar == '\0')
|
||||
++d->optind;
|
||||
if (temp == NULL || c == ':' || c == ';')
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr, "%s: invalid option -- '%c'\n", argv[0], c);
|
||||
}
|
||||
d->optopt = c;
|
||||
return '?';
|
||||
}
|
||||
if (temp[0] == 'W' && temp[1] == ';')
|
||||
{
|
||||
char *nameend;
|
||||
const struct option_a *p;
|
||||
const struct option_a *pfound = NULL;
|
||||
int exact = 0;
|
||||
int ambig = 0;
|
||||
int indfound = 0;
|
||||
int option_index;
|
||||
if (longopts == NULL)
|
||||
goto no_longs;
|
||||
if (*d->__nextchar != '\0')
|
||||
{
|
||||
d->optarg = d->__nextchar;
|
||||
d->optind++;
|
||||
}
|
||||
else if (d->optind == argc)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr,"%s: option requires an argument -- '%c'\n",argv[0], c);
|
||||
}
|
||||
d->optopt = c;
|
||||
if (optstring[0] == ':')
|
||||
c = ':';
|
||||
else
|
||||
c = '?';
|
||||
return c;
|
||||
}
|
||||
else
|
||||
d->optarg = argv[d->optind++];
|
||||
for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '='; nameend++);
|
||||
for (p = longopts, option_index = 0; p->name; p++, option_index++)
|
||||
if (!strncmp(p->name, d->__nextchar, nameend - d->__nextchar))
|
||||
{
|
||||
if ((unsigned int) (nameend - d->__nextchar) == strlen(p->name))
|
||||
{
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
exact = 1;
|
||||
break;
|
||||
}
|
||||
else if (pfound == NULL)
|
||||
{
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
}
|
||||
else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
|
||||
ambig = 1;
|
||||
}
|
||||
if (ambig && !exact)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr, "%s: option '-W %s' is ambiguous\n",argv[0], d->optarg);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
d->optind++;
|
||||
return '?';
|
||||
}
|
||||
if (pfound != NULL)
|
||||
{
|
||||
option_index = indfound;
|
||||
if (*nameend)
|
||||
{
|
||||
if (pfound->has_arg)
|
||||
d->optarg = nameend + 1;
|
||||
else
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr, "%s: option '-W %s' doesn't allow an argument\n",argv[0], pfound->name);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
else if (pfound->has_arg == 1)
|
||||
{
|
||||
if (d->optind < argc)
|
||||
d->optarg = argv[d->optind++];
|
||||
else
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr, "%s: option '-W %s' requires an argument\n",argv[0], pfound->name);
|
||||
}
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
return optstring[0] == ':' ? ':' : '?';
|
||||
}
|
||||
}
|
||||
else
|
||||
d->optarg = NULL;
|
||||
d->__nextchar += strlen(d->__nextchar);
|
||||
if (longind != NULL)
|
||||
*longind = option_index;
|
||||
if (pfound->flag)
|
||||
{
|
||||
*(pfound->flag) = pfound->val;
|
||||
return 0;
|
||||
}
|
||||
return pfound->val;
|
||||
}
|
||||
no_longs:
|
||||
d->__nextchar = NULL;
|
||||
return 'W';
|
||||
}
|
||||
if (temp[1] == ':')
|
||||
{
|
||||
if (temp[2] == ':')
|
||||
{
|
||||
if (*d->__nextchar != '\0')
|
||||
{
|
||||
d->optarg = d->__nextchar;
|
||||
d->optind++;
|
||||
}
|
||||
else
|
||||
d->optarg = NULL;
|
||||
d->__nextchar = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*d->__nextchar != '\0')
|
||||
{
|
||||
d->optarg = d->__nextchar;
|
||||
d->optind++;
|
||||
}
|
||||
else if (d->optind == argc)
|
||||
{
|
||||
if (print_errors)
|
||||
{
|
||||
fprintf(stderr,"%s: option requires an argument -- '%c'\n",argv[0], c);
|
||||
}
|
||||
d->optopt = c;
|
||||
if (optstring[0] == ':')
|
||||
c = ':';
|
||||
else
|
||||
c = '?';
|
||||
}
|
||||
else
|
||||
d->optarg = argv[d->optind++];
|
||||
d->__nextchar = NULL;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
int _getopt_internal_a (int argc, char *const *argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, int posixly_correct)
|
||||
{
|
||||
int result;
|
||||
getopt_data_a.optind = optind;
|
||||
getopt_data_a.opterr = opterr;
|
||||
result = _getopt_internal_r_a (argc, argv, optstring, longopts,longind, long_only, &getopt_data_a,posixly_correct);
|
||||
optind = getopt_data_a.optind;
|
||||
optarg_a = getopt_data_a.optarg;
|
||||
optopt = getopt_data_a.optopt;
|
||||
return result;
|
||||
}
|
||||
int getopt_a (int argc, char *const *argv, const char *optstring) _GETOPT_THROW
|
||||
{
|
||||
return _getopt_internal_a (argc, argv, optstring, (const struct option_a *) 0, (int *) 0, 0, 0);
|
||||
}
|
||||
int getopt_long_a (int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW
|
||||
{
|
||||
return _getopt_internal_a (argc, argv, options, long_options, opt_index, 0, 0);
|
||||
}
|
||||
int getopt_long_only_a (int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW
|
||||
{
|
||||
return _getopt_internal_a (argc, argv, options, long_options, opt_index, 1, 0);
|
||||
}
|
||||
int _getopt_long_r_a (int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index, struct _getopt_data_a *d)
|
||||
{
|
||||
return _getopt_internal_r_a (argc, argv, options, long_options, opt_index,0, d, 0);
|
||||
}
|
||||
int _getopt_long_only_r_a (int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index, struct _getopt_data_a *d)
|
||||
{
|
||||
return _getopt_internal_r_a (argc, argv, options, long_options, opt_index, 1, d, 0);
|
||||
}
|
||||
|
115
examples/client/getopt.h
Normal file
@ -0,0 +1,115 @@
|
||||
/* Getopt for Microsoft C
|
||||
This code is a modification of the Free Software Foundation, Inc.
|
||||
Getopt library for parsing command line argument the purpose was
|
||||
to provide a Microsoft Visual C friendly derivative. This code
|
||||
provides functionality for both Unicode and Multibyte builds.
|
||||
|
||||
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
|
||||
Version: 1.0
|
||||
Comment: Supports getopt, getopt_long, and getopt_long_only
|
||||
and POSIXLY_CORRECT environment flag
|
||||
License: LGPL
|
||||
|
||||
Revisions:
|
||||
|
||||
02/03/2011 - Ludvik Jerabek - Initial Release
|
||||
02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
|
||||
07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
|
||||
08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
|
||||
08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
|
||||
02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
|
||||
08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
|
||||
10/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
|
||||
06/19/2015 - Ludvik Jerabek - Fixed maximum option limitation caused by option_a (255) and option_w (65535) structure val variable
|
||||
24/10/2020 - Paul-Louis Ageneau - Removed Unicode version
|
||||
|
||||
**DISCLAIMER**
|
||||
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
||||
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
|
||||
EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
|
||||
APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
|
||||
DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
|
||||
USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
|
||||
PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
|
||||
YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
|
||||
EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*/
|
||||
#ifndef __GETOPT_H_
|
||||
#define __GETOPT_H_
|
||||
|
||||
#ifdef _GETOPT_API
|
||||
#undef _GETOPT_API
|
||||
#endif
|
||||
|
||||
#if defined(EXPORTS_GETOPT) && defined(STATIC_GETOPT)
|
||||
#error "The preprocessor definitions of EXPORTS_GETOPT and STATIC_GETOPT can only be used individually"
|
||||
#elif defined(STATIC_GETOPT)
|
||||
#pragma message("Warning static builds of getopt violate the Lesser GNU Public License")
|
||||
#define _GETOPT_API
|
||||
#elif defined(EXPORTS_GETOPT)
|
||||
#pragma message("Exporting getopt library")
|
||||
#define _GETOPT_API __declspec(dllexport)
|
||||
#else
|
||||
#pragma message("Importing getopt library")
|
||||
#define _GETOPT_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
// Change behavior for C\C++
|
||||
#ifdef __cplusplus
|
||||
#define _BEGIN_EXTERN_C extern "C" {
|
||||
#define _END_EXTERN_C }
|
||||
#define _GETOPT_THROW throw()
|
||||
#else
|
||||
#define _BEGIN_EXTERN_C
|
||||
#define _END_EXTERN_C
|
||||
#define _GETOPT_THROW
|
||||
#endif
|
||||
|
||||
// Standard GNU options
|
||||
#define null_argument 0 /*Argument Null*/
|
||||
#define no_argument 0 /*Argument Switch Only*/
|
||||
#define required_argument 1 /*Argument Required*/
|
||||
#define optional_argument 2 /*Argument Optional*/
|
||||
|
||||
// Shorter Options
|
||||
#define ARG_NULL 0 /*Argument Null*/
|
||||
#define ARG_NONE 0 /*Argument Switch Only*/
|
||||
#define ARG_REQ 1 /*Argument Required*/
|
||||
#define ARG_OPT 2 /*Argument Optional*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
_BEGIN_EXTERN_C
|
||||
|
||||
extern _GETOPT_API int optind;
|
||||
extern _GETOPT_API int opterr;
|
||||
extern _GETOPT_API int optopt;
|
||||
|
||||
struct option_a
|
||||
{
|
||||
const char* name;
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
extern _GETOPT_API char *optarg_a;
|
||||
extern _GETOPT_API int getopt_a(int argc, char *const *argv, const char *optstring) _GETOPT_THROW;
|
||||
extern _GETOPT_API int getopt_long_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
|
||||
extern _GETOPT_API int getopt_long_only_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
|
||||
|
||||
_END_EXTERN_C
|
||||
|
||||
#undef _BEGIN_EXTERN_C
|
||||
#undef _END_EXTERN_C
|
||||
#undef _GETOPT_THROW
|
||||
#undef _GETOPT_API
|
||||
|
||||
#define getopt getopt_a
|
||||
#define getopt_long getopt_long_a
|
||||
#define getopt_long_only getopt_long_only_a
|
||||
#define option option_a
|
||||
#define optarg optarg_a
|
||||
|
||||
#endif // __GETOPT_H_
|
@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2020 Will Munn
|
||||
* Copyright (c) 2020 Nico Chatzi
|
||||
* Copyright (c) 2020 Lara Mackey
|
||||
* Copyright (c) 2020 Erik Cota-Robles
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -22,12 +23,16 @@
|
||||
|
||||
#include "rtc/rtc.hpp"
|
||||
|
||||
#include "parse_cl.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
@ -48,24 +53,46 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
|
||||
weak_ptr<WebSocket> wws, string id);
|
||||
string randomId(size_t length);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
rtc::InitLogger(LogLevel::Warning);
|
||||
int main(int argc, char **argv) try {
|
||||
Cmdline params(argc, argv);
|
||||
|
||||
rtc::InitLogger(LogLevel::Info);
|
||||
|
||||
Configuration config;
|
||||
config.iceServers.emplace_back("stun:stun.l.google.com:19302"); // change to your STUN server
|
||||
string stunServer = "";
|
||||
if (params.noStun()) {
|
||||
cout << "No STUN server is configured. Only local hosts and public IP addresses supported."
|
||||
<< endl;
|
||||
} else {
|
||||
if (params.stunServer().substr(0, 5).compare("stun:") != 0) {
|
||||
stunServer = "stun:";
|
||||
}
|
||||
stunServer += params.stunServer() + ":" + to_string(params.stunPort());
|
||||
cout << "Stun server is " << stunServer << endl;
|
||||
config.iceServers.emplace_back(stunServer);
|
||||
}
|
||||
|
||||
localId = randomId(4);
|
||||
cout << "The local ID is: " << localId << endl;
|
||||
|
||||
auto ws = make_shared<WebSocket>();
|
||||
|
||||
ws->onOpen([]() { cout << "WebSocket connected, signaling ready" << endl; });
|
||||
std::promise<void> wsPromise;
|
||||
auto wsFuture = wsPromise.get_future();
|
||||
|
||||
ws->onOpen([&wsPromise]() {
|
||||
cout << "WebSocket connected, signaling ready" << endl;
|
||||
wsPromise.set_value();
|
||||
});
|
||||
|
||||
ws->onError([&wsPromise](string s) {
|
||||
cout << "WebSocket error" << endl;
|
||||
wsPromise.set_exception(std::make_exception_ptr(std::runtime_error(s)));
|
||||
});
|
||||
|
||||
ws->onClosed([]() { cout << "WebSocket closed" << endl; });
|
||||
|
||||
ws->onError([](const string &error) { cout << "WebSocket failed: " << error << endl; });
|
||||
|
||||
ws->onMessage([&](const variant<binary, string> &data) {
|
||||
ws->onMessage([&](variant<binary, string> data) {
|
||||
if (!holds_alternative<string>(data))
|
||||
return;
|
||||
|
||||
@ -101,15 +128,17 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
});
|
||||
|
||||
const string url = "ws://localhost:8000/" + localId;
|
||||
string wsPrefix = "";
|
||||
if (params.webSocketServer().substr(0, 5).compare("ws://") != 0) {
|
||||
wsPrefix = "ws://";
|
||||
}
|
||||
const string url = wsPrefix + params.webSocketServer() + ":" +
|
||||
to_string(params.webSocketPort()) + "/" + localId;
|
||||
cout << "Url is " << url << endl;
|
||||
ws->open(url);
|
||||
|
||||
cout << "Waiting for signaling to be connected..." << endl;
|
||||
while (!ws->isOpen()) {
|
||||
if (ws->isClosed())
|
||||
return 1;
|
||||
this_thread::sleep_for(100ms);
|
||||
}
|
||||
wsFuture.get();
|
||||
|
||||
while (true) {
|
||||
string id;
|
||||
@ -137,16 +166,15 @@ int main(int argc, char **argv) {
|
||||
|
||||
dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
|
||||
|
||||
dc->onMessage([id](const variant<binary, string> &message) {
|
||||
if (!holds_alternative<string>(message))
|
||||
return;
|
||||
|
||||
cout << "Message from " << id << " received: " << get<string>(message) << endl;
|
||||
dc->onMessage([id, wdc = make_weak_ptr(dc)](variant<binary, string> data) {
|
||||
if (holds_alternative<string>(data))
|
||||
cout << "Message from " << id << " received: " << get<string>(data) << endl;
|
||||
else
|
||||
cout << "Binary message from " << id
|
||||
<< " received, size=" << get<binary>(data).size() << endl;
|
||||
});
|
||||
|
||||
dataChannelMap.emplace(id, dc);
|
||||
|
||||
this_thread::sleep_for(1s);
|
||||
}
|
||||
|
||||
cout << "Cleaning up..." << endl;
|
||||
@ -154,6 +182,12 @@ int main(int argc, char **argv) {
|
||||
dataChannelMap.clear();
|
||||
peerConnectionMap.clear();
|
||||
return 0;
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << "Error: " << e.what() << std::endl;
|
||||
dataChannelMap.clear();
|
||||
peerConnectionMap.clear();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create and setup a PeerConnection
|
||||
@ -166,7 +200,7 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
|
||||
pc->onGatheringStateChange(
|
||||
[](PeerConnection::GatheringState state) { cout << "Gathering State: " << state << endl; });
|
||||
|
||||
pc->onLocalDescription([wws, id](const Description &description) {
|
||||
pc->onLocalDescription([wws, id](Description description) {
|
||||
json message = {
|
||||
{"id", id}, {"type", description.typeString()}, {"description", string(description)}};
|
||||
|
||||
@ -174,7 +208,7 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
|
||||
ws->send(message.dump());
|
||||
});
|
||||
|
||||
pc->onLocalCandidate([wws, id](const Candidate &candidate) {
|
||||
pc->onLocalCandidate([wws, id](Candidate candidate) {
|
||||
json message = {{"id", id},
|
||||
{"type", "candidate"},
|
||||
{"candidate", string(candidate)},
|
||||
@ -190,11 +224,12 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
|
||||
|
||||
dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
|
||||
|
||||
dc->onMessage([id](const variant<binary, string> &message) {
|
||||
if (!holds_alternative<string>(message))
|
||||
return;
|
||||
|
||||
cout << "Message from " << id << " received: " << get<string>(message) << endl;
|
||||
dc->onMessage([id, wdc = make_weak_ptr(dc)](variant<binary, string> data) {
|
||||
if (holds_alternative<string>(data))
|
||||
cout << "Message from " << id << " received: " << get<string>(data) << endl;
|
||||
else
|
||||
cout << "Binary message from " << id
|
||||
<< " received, size=" << get<binary>(data).size() << endl;
|
||||
});
|
||||
|
||||
dc->send("Hello from " + localId);
|
||||
@ -212,7 +247,8 @@ string randomId(size_t length) {
|
||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
|
||||
string id(length, '0');
|
||||
default_random_engine rng(random_device{}());
|
||||
uniform_int_distribution<int> dist(0, characters.size() - 1);
|
||||
uniform_int_distribution<int> dist(0, int(characters.size() - 1));
|
||||
generate(id.begin(), id.end(), [&]() { return characters.at(dist(rng)); });
|
||||
return id;
|
||||
}
|
||||
|
||||
|
160
examples/client/parse_cl.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
/******************************************************************************
|
||||
**
|
||||
** parse_cl.cpp
|
||||
**
|
||||
** Thu Aug 6 19:42:25 2020
|
||||
** Linux 5.4.0-42-generic (#46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020) x86_64
|
||||
** cerik@Erik-VBox-Ubuntu (Erik Cota-Robles)
|
||||
**
|
||||
** Copyright (c) 2020 Erik Cota-Robles
|
||||
**
|
||||
** Definition of command line parser class
|
||||
**
|
||||
** Automatically created by genparse v0.9.3
|
||||
**
|
||||
** See http://genparse.sourceforge.net for details and updates
|
||||
**
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#include "getopt.h"
|
||||
#else
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#include "parse_cl.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
**
|
||||
** Cmdline::Cmdline ()
|
||||
**
|
||||
** Constructor method.
|
||||
**
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::string )
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
int c;
|
||||
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"noStun", no_argument, NULL, 'n'},
|
||||
{"stunServer", required_argument, NULL, 's'},
|
||||
{"stunPort", required_argument, NULL, 't'},
|
||||
{"webSocketServer", required_argument, NULL, 'w'},
|
||||
{"webSocketPort", required_argument, NULL, 'x'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
_program_name += argv[0];
|
||||
|
||||
/* default values */
|
||||
_n = false;
|
||||
_s = "stun.l.google.com";
|
||||
_t = 19302;
|
||||
_w = "localhost";
|
||||
_x = 8000;
|
||||
_h = false;
|
||||
|
||||
optind = 0;
|
||||
while ((c = getopt_long (argc, argv, "s:t:w:x:enhv", long_options, &optind)) != - 1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'n':
|
||||
_n = true;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
_s = optarg;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
_t = atoi (optarg);
|
||||
if (_t < 0)
|
||||
{
|
||||
std::string err;
|
||||
err += "parameter range error: t must be >= 0";
|
||||
throw (std::range_error(err));
|
||||
}
|
||||
if (_t > 65535)
|
||||
{
|
||||
std::string err;
|
||||
err += "parameter range error: t must be <= 65535";
|
||||
throw (std::range_error(err));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
_w = optarg;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
_x = atoi (optarg);
|
||||
if (_x < 0)
|
||||
{
|
||||
std::string err;
|
||||
err += "parameter range error: x must be >= 0";
|
||||
throw (std::range_error(err));
|
||||
}
|
||||
if (_x > 65535)
|
||||
{
|
||||
std::string err;
|
||||
err += "parameter range error: x must be <= 65535";
|
||||
throw (std::range_error(err));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
_h = true;
|
||||
this->usage (EXIT_SUCCESS);
|
||||
break;
|
||||
|
||||
default:
|
||||
this->usage (EXIT_FAILURE);
|
||||
|
||||
}
|
||||
} /* while */
|
||||
|
||||
_optind = optind;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
**
|
||||
** Cmdline::usage () and version()
|
||||
**
|
||||
** Print out usage (or version) information, then exit.
|
||||
**
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
void Cmdline::usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
std::cerr << "Try `" << _program_name << " --help' for more information.\n";
|
||||
else
|
||||
{
|
||||
std::cout << "\
|
||||
usage: " << _program_name << " [ -enstwxhv ] \n\
|
||||
libdatachannel client implementing WebRTC Data Channels with WebSocket signaling\n\
|
||||
[ -n ] [ --noStun ] (type=FLAG)\n\
|
||||
Do NOT use a stun server (overrides -s and -t).\n\
|
||||
[ -s ] [ --stunServer ] (type=STRING, default=stun.l.google.com)\n\
|
||||
Stun server URL or IP address.\n\
|
||||
[ -t ] [ --stunPort ] (type=INTEGER, range=0...65535, default=19302)\n\
|
||||
Stun server port.\n\
|
||||
[ -w ] [ --webSocketServer ] (type=STRING, default=localhost)\n\
|
||||
Web socket server URL or IP address.\n\
|
||||
[ -x ] [ --webSocketPort ] (type=INTEGER, range=0...65535, default=8000)\n\
|
||||
Web socket server port.\n\
|
||||
[ -h ] [ --help ] (type=FLAG)\n\
|
||||
Display this help and exit.\n";
|
||||
}
|
||||
exit (status);
|
||||
}
|
||||
|
67
examples/client/parse_cl.h
Normal file
@ -0,0 +1,67 @@
|
||||
/******************************************************************************
|
||||
**
|
||||
** parse_cl.h
|
||||
**
|
||||
** Thu Aug 6 19:42:25 2020
|
||||
** Linux 5.4.0-42-generic (#46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020) x86_64
|
||||
** cerik@Erik-VBox-Ubuntu (Erik Cota-Robles)
|
||||
**
|
||||
** Copyright (c) 2020 Erik Cota-Robles
|
||||
**
|
||||
** Header file for command line parser class
|
||||
**
|
||||
** Automatically created by genparse v0.9.3
|
||||
**
|
||||
** See http://genparse.sourceforge.net for details and updates
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CMDLINE_H
|
||||
#define CMDLINE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
**
|
||||
** class Cmdline
|
||||
**
|
||||
** command line parser class
|
||||
**
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
class Cmdline
|
||||
{
|
||||
private:
|
||||
/* parameters */
|
||||
bool _n;
|
||||
std::string _s;
|
||||
int _t;
|
||||
std::string _w;
|
||||
int _x;
|
||||
bool _h;
|
||||
|
||||
/* other stuff to keep track of */
|
||||
std::string _program_name;
|
||||
int _optind;
|
||||
|
||||
public:
|
||||
/* constructor and destructor */
|
||||
Cmdline (int, char **); // ISO C++17 not allowed: throw (std::string);
|
||||
~Cmdline (){}
|
||||
|
||||
/* usage function */
|
||||
void usage (int status);
|
||||
|
||||
/* return next (non-option) parameter */
|
||||
int next_param () { return _optind; }
|
||||
|
||||
bool noStun () const { return _n; }
|
||||
std::string stunServer () const { return _s; }
|
||||
int stunPort () const { return _t; }
|
||||
std::string webSocketServer () const { return _w; }
|
||||
int webSocketPort () const { return _x; }
|
||||
bool h () const { return _h; }
|
||||
};
|
||||
|
||||
#endif
|
BIN
examples/client/uwp/Logo.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
examples/client/uwp/SmallLogo.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
examples/client/uwp/SmallLogo44x44.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
examples/client/uwp/SplashScreen.png
Normal file
After Width: | Height: | Size: 909 B |
BIN
examples/client/uwp/StoreLogo.png
Normal file
After Width: | Height: | Size: 227 B |
BIN
examples/client/uwp/Windows_TemporaryKey.pfx
Normal file
42
examples/client/uwp/package.appxManifest
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
|
||||
xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity Name="274EF42C-A3FB-3D6C-B127-E39C508A4F0E" Publisher="CN=CMake" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="274EF42C-A3FB-3D6C-B127-E39C508A4F0E" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
<Properties>
|
||||
<DisplayName>datachannel-client</DisplayName>
|
||||
<PublisherDisplayName>CMake</PublisherDisplayName>
|
||||
<Logo>StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application
|
||||
Id="App"
|
||||
Executable="client.exe"
|
||||
EntryPoint="datachannel-client.App"
|
||||
desktop4:Subsystem="console"
|
||||
desktop4:SupportsMultipleInstances="true"
|
||||
iot2:Subsystem="console"
|
||||
iot2:SupportsMultipleInstances="true">
|
||||
<uap:VisualElements
|
||||
DisplayName="datachannel-client"
|
||||
Description="datachannel-client"
|
||||
BackgroundColor="#336699"
|
||||
Square150x150Logo="Logo.png"
|
||||
Square44x44Logo="SmallLogo44x44.png">
|
||||
<uap:SplashScreen Image="SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
@ -2,14 +2,54 @@ cmake_minimum_required(VERSION 3.5.1)
|
||||
project(offerer C)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_FLAGS "-Wall -g -O2")
|
||||
|
||||
add_executable(datachannel-copy-paste-capi-offerer offerer.c)
|
||||
set(OFFERER_UWP_RESOURCES
|
||||
uwp/offerer/Logo.png
|
||||
uwp/offerer/package.appxManifest
|
||||
uwp/offerer/SmallLogo.png
|
||||
uwp/offerer/SmallLogo44x44.png
|
||||
uwp/offerer/SplashScreen.png
|
||||
uwp/offerer/StoreLogo.png
|
||||
uwp/offerer/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
set(ANSWERER_UWP_RESOURCES
|
||||
uwp/answerer/Logo.png
|
||||
uwp/answerer/package.appxManifest
|
||||
uwp/answerer/SmallLogo.png
|
||||
uwp/answerer/SmallLogo44x44.png
|
||||
uwp/answerer/SplashScreen.png
|
||||
uwp/answerer/StoreLogo.png
|
||||
uwp/answerer/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
add_executable(datachannel-copy-paste-capi-offerer offerer.c ${OFFERER_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-copy-paste-capi-offerer offerer.c)
|
||||
endif()
|
||||
set_target_properties(datachannel-copy-paste-capi-offerer PROPERTIES
|
||||
OUTPUT_NAME offerer)
|
||||
target_link_libraries(datachannel-copy-paste-capi-offerer datachannel)
|
||||
|
||||
add_executable(datachannel-copy-paste-capi-answerer answerer.c)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
add_executable(datachannel-copy-paste-capi-answerer answerer.c ${ANSWERER_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-copy-paste-capi-answerer answerer.c)
|
||||
endif()
|
||||
set_target_properties(datachannel-copy-paste-capi-answerer PROPERTIES
|
||||
OUTPUT_NAME answerer)
|
||||
target_link_libraries(datachannel-copy-paste-capi-answerer datachannel)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET datachannel-copy-paste-capi-offerer POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
|
||||
$<TARGET_FILE_DIR:datachannel-copy-paste-capi-offerer>
|
||||
)
|
||||
add_custom_command(TARGET datachannel-copy-paste-capi-answerer POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
|
||||
$<TARGET_FILE_DIR:datachannel-copy-paste-capi-answerer>
|
||||
)
|
||||
endif()
|
||||
|
@ -41,30 +41,22 @@ typedef struct {
|
||||
bool connected;
|
||||
} Peer;
|
||||
|
||||
Peer *peer = NULL;
|
||||
|
||||
static void dataChannelCallback(int dc, void *ptr);
|
||||
|
||||
static void descriptionCallback(const char *sdp, const char *type, void *ptr);
|
||||
|
||||
static void candidateCallback(const char *cand, const char *mid, void *ptr);
|
||||
|
||||
static void stateChangeCallback(rtcState state, void *ptr);
|
||||
|
||||
static void gatheringStateCallback(rtcGatheringState state, void *ptr);
|
||||
|
||||
static void closedCallback(void *ptr);
|
||||
|
||||
static void messageCallback(const char *message, int size, void *ptr);
|
||||
|
||||
static void RTC_API dataChannelCallback(int pc, int dc, void *ptr);
|
||||
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr);
|
||||
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr);
|
||||
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr);
|
||||
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr);
|
||||
static void RTC_API closedCallback(int id, void *ptr);
|
||||
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr);
|
||||
static void deletePeer(Peer *peer);
|
||||
|
||||
char *state_print(rtcState state);
|
||||
char *rtcGatheringState_print(rtcGatheringState state);
|
||||
|
||||
int all_space(const char *str);
|
||||
char* state_print(rtcState state);
|
||||
char* rtcGatheringState_print(rtcState state);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
rtcInitLogger(RTC_LOG_DEBUG);
|
||||
rtcInitLogger(RTC_LOG_DEBUG, NULL);
|
||||
|
||||
// Create peer
|
||||
rtcConfiguration config;
|
||||
@ -96,7 +88,8 @@ int main(int argc, char **argv) {
|
||||
bool exit = false;
|
||||
while (!exit) {
|
||||
printf("\n");
|
||||
printf("***************************************************************************************\n");
|
||||
printf("***********************************************************************************"
|
||||
"****\n");
|
||||
printf("* 0: Exit /"
|
||||
" 1: Enter remote description /"
|
||||
" 2: Enter remote candidate /"
|
||||
@ -126,27 +119,25 @@ int main(int argc, char **argv) {
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
size_t read = 0;
|
||||
char *sdp = (char*) malloc(sizeof(char));
|
||||
char *sdp = (char *)malloc(sizeof(char));
|
||||
while ((read = getline(&line, &len, stdin)) != -1 && !all_space(line)) {
|
||||
sdp = (char*) realloc (sdp,(strlen(sdp)+1) +strlen(line)+1);
|
||||
sdp = (char *)realloc(sdp, (strlen(sdp) + 1) + strlen(line) + 1);
|
||||
strcat(sdp, line);
|
||||
|
||||
}
|
||||
printf("%s\n",sdp);
|
||||
printf("%s\n", sdp);
|
||||
rtcSetRemoteDescription(peer->pc, sdp, "offer");
|
||||
free(sdp);
|
||||
free(line);
|
||||
break;
|
||||
|
||||
}
|
||||
case 2: {
|
||||
// Parse Candidate
|
||||
printf("[Candidate]: ");
|
||||
char* candidate = NULL;
|
||||
char *candidate = NULL;
|
||||
size_t candidate_size = 0;
|
||||
|
||||
if(getline(&candidate, &candidate_size, stdin)) {
|
||||
rtcAddRemoteCandidate(peer->pc, candidate, "0");
|
||||
if (getline(&candidate, &candidate_size, stdin)) {
|
||||
rtcAddRemoteCandidate(peer->pc, candidate, NULL);
|
||||
free(candidate);
|
||||
|
||||
} else {
|
||||
@ -158,15 +149,15 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
case 3: {
|
||||
// Send Message
|
||||
if(!peer->connected) {
|
||||
if (!peer->connected) {
|
||||
printf("** Channel is not Open **");
|
||||
break;
|
||||
}
|
||||
printf("[Message]: ");
|
||||
char* message = NULL;
|
||||
char *message = NULL;
|
||||
size_t message_size = 0;
|
||||
|
||||
if(getline(&message, &message_size, stdin)) {
|
||||
if (getline(&message, &message_size, stdin)) {
|
||||
rtcSendMessage(peer->dc, message, -1);
|
||||
free(message);
|
||||
} else {
|
||||
@ -177,7 +168,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
case 4: {
|
||||
// Connection Info
|
||||
if(!peer->connected) {
|
||||
if (!peer->connected) {
|
||||
printf("** Channel is not Open **");
|
||||
break;
|
||||
}
|
||||
@ -202,35 +193,32 @@ int main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void descriptionCallback(const char *sdp, const char *type, void *ptr) {
|
||||
// Peer *peer = (Peer *)ptr;
|
||||
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
|
||||
printf("Description %s:\n%s\n", "answerer", sdp);
|
||||
}
|
||||
|
||||
static void candidateCallback(const char *cand, const char *mid, void *ptr) {
|
||||
// Peer *peer = (Peer *)ptr;
|
||||
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
|
||||
printf("Candidate %s: %s\n", "answerer", cand);
|
||||
|
||||
}
|
||||
|
||||
static void stateChangeCallback(rtcState state, void *ptr) {
|
||||
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->state = state;
|
||||
printf("State %s: %s\n", "answerer", state_print(state));
|
||||
}
|
||||
|
||||
static void gatheringStateCallback(rtcGatheringState state, void *ptr) {
|
||||
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->gatheringState = state;
|
||||
printf("Gathering state %s: %s\n", "answerer", rtcGatheringState_print(state));
|
||||
}
|
||||
|
||||
static void closedCallback(void *ptr) {
|
||||
static void RTC_API closedCallback(int id, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->connected = false;
|
||||
}
|
||||
|
||||
static void messageCallback(const char *message, int size, void *ptr) {
|
||||
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr) {
|
||||
if (size < 0) { // negative size indicates a null-terminated string
|
||||
printf("Message %s: %s\n", "answerer", message);
|
||||
} else {
|
||||
@ -238,6 +226,17 @@ static void messageCallback(const char *message, int size, void *ptr) {
|
||||
}
|
||||
}
|
||||
|
||||
static void RTC_API dataChannelCallback(int pc, int dc, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->dc = dc;
|
||||
peer->connected = true;
|
||||
rtcSetClosedCallback(dc, closedCallback);
|
||||
rtcSetMessageCallback(dc, messageCallback);
|
||||
char buffer[256];
|
||||
if (rtcGetDataChannelLabel(dc, buffer, 256) >= 0)
|
||||
printf("DataChannel %s: Received with label \"%s\"\n", "answerer", buffer);
|
||||
}
|
||||
|
||||
static void deletePeer(Peer *peer) {
|
||||
if (peer) {
|
||||
if (peer->dc)
|
||||
@ -248,28 +247,7 @@ static void deletePeer(Peer *peer) {
|
||||
}
|
||||
}
|
||||
|
||||
static void dataChannelCallback(int dc, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->dc = dc;
|
||||
peer->connected = true;
|
||||
rtcSetClosedCallback(dc, closedCallback);
|
||||
rtcSetMessageCallback(dc, messageCallback);
|
||||
char buffer[256];
|
||||
if (rtcGetDataChannelLabel(dc, buffer, 256) >= 0)
|
||||
printf("DataChannel %s: Received with label \"%s\"\n", "answerer", buffer);
|
||||
}
|
||||
|
||||
int all_space(const char *str) {
|
||||
while (*str) {
|
||||
if (!isspace(*str++)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* state_print(rtcState state) {
|
||||
char *state_print(rtcState state) {
|
||||
char *str = NULL;
|
||||
switch (state) {
|
||||
case RTC_NEW:
|
||||
@ -297,8 +275,8 @@ char* state_print(rtcState state) {
|
||||
return str;
|
||||
}
|
||||
|
||||
char* rtcGatheringState_print(rtcState state) {
|
||||
char* str = NULL;
|
||||
char *rtcGatheringState_print(rtcGatheringState state) {
|
||||
char *str = NULL;
|
||||
switch (state) {
|
||||
case RTC_GATHERING_NEW:
|
||||
str = "RTC_GATHERING_NEW";
|
||||
@ -315,3 +293,13 @@ char* rtcGatheringState_print(rtcState state) {
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
int all_space(const char *str) {
|
||||
while (*str) {
|
||||
if (!isspace(*str++)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
// Simple POSIX getline() implementation
|
||||
// This code is public domain
|
||||
|
||||
#include "malloc.h"
|
||||
#include "stdio.h"
|
||||
#include <malloc.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
int getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
if (!lineptr || !stream || !n)
|
||||
return -1;
|
||||
|
||||
@ -20,7 +21,7 @@ ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
*n = 128;
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
int pos = 0;
|
||||
while(c != EOF) {
|
||||
if (pos + 1 >= *n) {
|
||||
size_t new_size = *n + (*n >> 2);
|
||||
@ -45,4 +46,3 @@ ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
(*lineptr)[pos] = '\0';
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,6 @@ static void sleep(unsigned int secs) { Sleep(secs * 1000); }
|
||||
#include <unistd.h> // for sleep
|
||||
#endif
|
||||
|
||||
char* state_print(rtcState state);
|
||||
char* rtcGatheringState_print(rtcState state);
|
||||
|
||||
typedef struct {
|
||||
rtcState state;
|
||||
rtcGatheringState gatheringState;
|
||||
@ -44,28 +41,22 @@ typedef struct {
|
||||
bool connected;
|
||||
} Peer;
|
||||
|
||||
Peer *peer = NULL;
|
||||
|
||||
static void descriptionCallback(const char *sdp, const char *type, void *ptr);
|
||||
|
||||
static void candidateCallback(const char *cand, const char *mid, void *ptr);
|
||||
|
||||
static void stateChangeCallback(rtcState state, void *ptr);
|
||||
|
||||
static void gatheringStateCallback(rtcGatheringState state, void *ptr);
|
||||
|
||||
static void openCallback(void *ptr);
|
||||
|
||||
static void closedCallback(void *ptr);
|
||||
|
||||
static void messageCallback(const char *message, int size, void *ptr);
|
||||
|
||||
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr);
|
||||
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr);
|
||||
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr);
|
||||
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr);
|
||||
static void RTC_API openCallback(int id, void *ptr);
|
||||
static void RTC_API closedCallback(int id, void *ptr);
|
||||
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr);
|
||||
static void deletePeer(Peer *peer);
|
||||
|
||||
char *state_print(rtcState state);
|
||||
char *rtcGatheringState_print(rtcGatheringState state);
|
||||
|
||||
int all_space(const char *str);
|
||||
|
||||
int main(int argc, char **argv){
|
||||
rtcInitLogger(RTC_LOG_DEBUG);
|
||||
int main(int argc, char **argv) {
|
||||
rtcInitLogger(RTC_LOG_DEBUG, NULL);
|
||||
|
||||
// Create peer
|
||||
rtcConfiguration config;
|
||||
@ -88,7 +79,7 @@ int main(int argc, char **argv){
|
||||
rtcSetStateChangeCallback(peer->pc, stateChangeCallback);
|
||||
rtcSetGatheringStateChangeCallback(peer->pc, gatheringStateCallback);
|
||||
|
||||
// Since this is the offere, we will create a datachannel
|
||||
// Since we are the offerer, we will create a datachannel
|
||||
peer->dc = rtcCreateDataChannel(peer->pc, "test");
|
||||
rtcSetOpenCallback(peer->dc, openCallback);
|
||||
rtcSetClosedCallback(peer->dc, closedCallback);
|
||||
@ -100,7 +91,8 @@ int main(int argc, char **argv){
|
||||
while (!exit) {
|
||||
|
||||
printf("\n");
|
||||
printf("***************************************************************************************\n");
|
||||
printf("***********************************************************************************"
|
||||
"****\n");
|
||||
printf("* 0: Exit /"
|
||||
" 1: Enter remote description /"
|
||||
" 2: Enter remote candidate /"
|
||||
@ -128,53 +120,49 @@ int main(int argc, char **argv){
|
||||
// Parse Description
|
||||
printf("[Description]: ");
|
||||
|
||||
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
size_t read = 0;
|
||||
char *sdp = (char*) malloc(sizeof(char));
|
||||
char *sdp = (char *)malloc(sizeof(char));
|
||||
while ((read = getline(&line, &len, stdin)) != -1 && !all_space(line)) {
|
||||
sdp = (char*) realloc (sdp,(strlen(sdp)+1) +strlen(line)+1);
|
||||
sdp = (char *)realloc(sdp, (strlen(sdp) + 1) + strlen(line) + 1);
|
||||
strcat(sdp, line);
|
||||
|
||||
}
|
||||
printf("%s\n",sdp);
|
||||
printf("%s\n", sdp);
|
||||
rtcSetRemoteDescription(peer->pc, sdp, "answer");
|
||||
free(sdp);
|
||||
free(line);
|
||||
break;
|
||||
|
||||
}
|
||||
case 2: {
|
||||
// Parse Candidate
|
||||
printf("[Candidate]: ");
|
||||
char* candidate = NULL;
|
||||
char *candidate = NULL;
|
||||
size_t candidate_size = 0;
|
||||
if(getline(&candidate, &candidate_size, stdin)) {
|
||||
rtcAddRemoteCandidate(peer->pc, candidate, "0");
|
||||
if (getline(&candidate, &candidate_size, stdin)) {
|
||||
rtcAddRemoteCandidate(peer->pc, candidate, NULL);
|
||||
free(candidate);
|
||||
|
||||
}else {
|
||||
} else {
|
||||
printf("Error reading line\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
// Send Message
|
||||
if(!peer->connected) {
|
||||
if (!peer->connected) {
|
||||
printf("** Channel is not Open **");
|
||||
break;
|
||||
}
|
||||
printf("[Message]: ");
|
||||
char* message = NULL;
|
||||
char *message = NULL;
|
||||
size_t message_size = 0;
|
||||
if(getline(&message, &message_size, stdin)) {
|
||||
if (getline(&message, &message_size, stdin)) {
|
||||
rtcSendMessage(peer->dc, message, -1);
|
||||
free(message);
|
||||
}else {
|
||||
} else {
|
||||
printf("Error reading line\n");
|
||||
break;
|
||||
}
|
||||
@ -183,7 +171,7 @@ int main(int argc, char **argv){
|
||||
}
|
||||
case 4: {
|
||||
// Connection Info
|
||||
if(!peer->connected) {
|
||||
if (!peer->connected) {
|
||||
printf("** Channel is not Open **");
|
||||
break;
|
||||
}
|
||||
@ -208,44 +196,40 @@ int main(int argc, char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void descriptionCallback(const char *sdp, const char *type, void *ptr) {
|
||||
// Peer *peer = (Peer *)ptr;
|
||||
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
|
||||
printf("Description %s:\n%s\n", "offerer", sdp);
|
||||
}
|
||||
|
||||
static void candidateCallback(const char *cand, const char *mid, void *ptr) {
|
||||
// Peer *peer = (Peer *)ptr;
|
||||
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
|
||||
printf("Candidate %s: %s\n", "offerer", cand);
|
||||
|
||||
}
|
||||
|
||||
static void stateChangeCallback(rtcState state, void *ptr) {
|
||||
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->state = state;
|
||||
printf("State %s: %s\n", "offerer", state_print(state));
|
||||
}
|
||||
|
||||
static void gatheringStateCallback(rtcGatheringState state, void *ptr) {
|
||||
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->gatheringState = state;
|
||||
printf("Gathering state %s: %s\n", "offerer", rtcGatheringState_print(state));
|
||||
}
|
||||
|
||||
static void openCallback(void *ptr) {
|
||||
static void RTC_API openCallback(int id, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->connected = true;
|
||||
char buffer[256];
|
||||
if (rtcGetDataChannelLabel(peer->dc, buffer, 256) >= 0)
|
||||
printf("DataChannel %s: Received with label \"%s\"\n","offerer", buffer);
|
||||
printf("DataChannel %s: Received with label \"%s\"\n", "offerer", buffer);
|
||||
}
|
||||
|
||||
static void closedCallback(void *ptr) {
|
||||
static void RTC_API closedCallback(int id, void *ptr) {
|
||||
Peer *peer = (Peer *)ptr;
|
||||
peer->connected = false;
|
||||
}
|
||||
|
||||
static void messageCallback(const char *message, int size, void *ptr) {
|
||||
// Peer *peer = (Peer *)ptr;
|
||||
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr) {
|
||||
if (size < 0) { // negative size indicates a null-terminated string
|
||||
printf("Message %s: %s\n", "offerer", message);
|
||||
} else {
|
||||
@ -263,17 +247,7 @@ static void deletePeer(Peer *peer) {
|
||||
}
|
||||
}
|
||||
|
||||
int all_space(const char *str) {
|
||||
while (*str) {
|
||||
if (!isspace(*str++)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* state_print(rtcState state) {
|
||||
char *state_print(rtcState state) {
|
||||
char *str = NULL;
|
||||
switch (state) {
|
||||
case RTC_NEW:
|
||||
@ -299,11 +273,10 @@ char* state_print(rtcState state) {
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
char* rtcGatheringState_print(rtcState state) {
|
||||
char* str = NULL;
|
||||
char *rtcGatheringState_print(rtcGatheringState state) {
|
||||
char *str = NULL;
|
||||
switch (state) {
|
||||
case RTC_GATHERING_NEW:
|
||||
str = "RTC_GATHERING_NEW";
|
||||
@ -320,3 +293,13 @@ char* rtcGatheringState_print(rtcState state) {
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
int all_space(const char *str) {
|
||||
while (*str) {
|
||||
if (!isspace(*str++)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
BIN
examples/copy-paste-capi/uwp/answerer/Logo.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
examples/copy-paste-capi/uwp/answerer/SmallLogo.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
examples/copy-paste-capi/uwp/answerer/SmallLogo44x44.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
examples/copy-paste-capi/uwp/answerer/SplashScreen.png
Normal file
After Width: | Height: | Size: 909 B |
BIN
examples/copy-paste-capi/uwp/answerer/StoreLogo.png
Normal file
After Width: | Height: | Size: 227 B |
BIN
examples/copy-paste-capi/uwp/answerer/Windows_TemporaryKey.pfx
Normal file
42
examples/copy-paste-capi/uwp/answerer/package.appxManifest
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
|
||||
xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity Name="9751ACA6-5428-3AF2-AED6-2DDA8D2FD777" Publisher="CN=CMake" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="9751ACA6-5428-3AF2-AED6-2DDA8D2FD777" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
<Properties>
|
||||
<DisplayName>datachannel-copy-paste-capi-answerer</DisplayName>
|
||||
<PublisherDisplayName>CMake</PublisherDisplayName>
|
||||
<Logo>StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application
|
||||
Id="App"
|
||||
Executable="answerer.exe"
|
||||
EntryPoint="datachannel-copy-paste-capi-answerer.App"
|
||||
desktop4:Subsystem="console"
|
||||
desktop4:SupportsMultipleInstances="true"
|
||||
iot2:Subsystem="console"
|
||||
iot2:SupportsMultipleInstances="true">
|
||||
<uap:VisualElements
|
||||
DisplayName="datachannel-copy-paste-capi-answerer"
|
||||
Description="datachannel-copy-paste-capi-answerer"
|
||||
BackgroundColor="#336699"
|
||||
Square150x150Logo="Logo.png"
|
||||
Square44x44Logo="SmallLogo44x44.png">
|
||||
<uap:SplashScreen Image="SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
BIN
examples/copy-paste-capi/uwp/offerer/Logo.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
examples/copy-paste-capi/uwp/offerer/SmallLogo.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
examples/copy-paste-capi/uwp/offerer/SmallLogo44x44.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
examples/copy-paste-capi/uwp/offerer/SplashScreen.png
Normal file
After Width: | Height: | Size: 909 B |
BIN
examples/copy-paste-capi/uwp/offerer/StoreLogo.png
Normal file
After Width: | Height: | Size: 227 B |
BIN
examples/copy-paste-capi/uwp/offerer/Windows_TemporaryKey.pfx
Normal file
42
examples/copy-paste-capi/uwp/offerer/package.appxManifest
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
|
||||
xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity Name="D63472B9-2085-3CA0-96B2-895D164F4155" Publisher="CN=CMake" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="D63472B9-2085-3CA0-96B2-895D164F4155" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
<Properties>
|
||||
<DisplayName>datachannel-copy-paste-capi-offerer</DisplayName>
|
||||
<PublisherDisplayName>CMake</PublisherDisplayName>
|
||||
<Logo>StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application
|
||||
Id="App"
|
||||
Executable="offerer.exe"
|
||||
EntryPoint="datachannel-copy-paste-capi-offerer.App"
|
||||
desktop4:Subsystem="console"
|
||||
desktop4:SupportsMultipleInstances="true"
|
||||
iot2:Subsystem="console"
|
||||
iot2:SupportsMultipleInstances="true">
|
||||
<uap:VisualElements
|
||||
DisplayName="datachannel-copy-paste-capi-offerer"
|
||||
Description="datachannel-copy-paste-capi-offerer"
|
||||
BackgroundColor="#336699"
|
||||
Square150x150Logo="Logo.png"
|
||||
Square44x44Logo="SmallLogo44x44.png">
|
||||
<uap:SplashScreen Image="SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
@ -1,14 +1,54 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
add_executable(datachannel-copy-paste-offerer offerer.cpp)
|
||||
set(OFFERER_UWP_RESOURCES
|
||||
uwp/offerer/Logo.png
|
||||
uwp/offerer/package.appxManifest
|
||||
uwp/offerer/SmallLogo.png
|
||||
uwp/offerer/SmallLogo44x44.png
|
||||
uwp/offerer/SplashScreen.png
|
||||
uwp/offerer/StoreLogo.png
|
||||
uwp/offerer/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
set(ANSWERER_UWP_RESOURCES
|
||||
uwp/answerer/Logo.png
|
||||
uwp/answerer/package.appxManifest
|
||||
uwp/answerer/SmallLogo.png
|
||||
uwp/answerer/SmallLogo44x44.png
|
||||
uwp/answerer/SplashScreen.png
|
||||
uwp/answerer/StoreLogo.png
|
||||
uwp/answerer/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
add_executable(datachannel-copy-paste-offerer offerer.cpp ${OFFERER_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-copy-paste-offerer offerer.cpp)
|
||||
endif()
|
||||
set_target_properties(datachannel-copy-paste-offerer PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
OUTPUT_NAME offerer)
|
||||
target_link_libraries(datachannel-copy-paste-offerer datachannel)
|
||||
|
||||
add_executable(datachannel-copy-paste-answerer answerer.cpp)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
add_executable(datachannel-copy-paste-answerer answerer.cpp ${ANSWERER_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-copy-paste-answerer answerer.cpp)
|
||||
endif()
|
||||
set_target_properties(datachannel-copy-paste-answerer PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
OUTPUT_NAME answerer)
|
||||
target_link_libraries(datachannel-copy-paste-answerer datachannel)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET datachannel-copy-paste-offerer POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
|
||||
$<TARGET_FILE_DIR:datachannel-copy-paste-offerer>
|
||||
)
|
||||
add_custom_command(TARGET datachannel-copy-paste-answerer POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
|
||||
$<TARGET_FILE_DIR:datachannel-copy-paste-answerer>
|
||||
)
|
||||
endif()
|
||||
|
@ -36,12 +36,12 @@ int main(int argc, char **argv) {
|
||||
|
||||
auto pc = std::make_shared<PeerConnection>(config);
|
||||
|
||||
pc->onLocalDescription([](const Description &description) {
|
||||
pc->onLocalDescription([](Description description) {
|
||||
cout << "Local Description (Paste this to the other peer):" << endl;
|
||||
cout << string(description) << endl;
|
||||
});
|
||||
|
||||
pc->onLocalCandidate([](const Candidate &candidate) {
|
||||
pc->onLocalCandidate([](Candidate candidate) {
|
||||
cout << "Local Candidate (Paste this to the other peer after the local description):"
|
||||
<< endl;
|
||||
cout << string(candidate) << endl << endl;
|
||||
@ -60,7 +60,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
dc->onClosed([&]() { cout << "[DataChannel closed: " << dc->label() << "]" << endl; });
|
||||
|
||||
dc->onMessage([](const variant<binary, string> &message) {
|
||||
dc->onMessage([](variant<binary, string> message) {
|
||||
if (holds_alternative<string>(message)) {
|
||||
cout << "[Received message: " << get<string>(message) << "]" << endl;
|
||||
}
|
||||
@ -127,13 +127,11 @@ int main(int argc, char **argv) {
|
||||
cout << "** Channel is not Open ** ";
|
||||
break;
|
||||
}
|
||||
CandidateInfo local, remote;
|
||||
Candidate local, remote;
|
||||
std::optional<std::chrono::milliseconds> rtt = pc->rtt();
|
||||
if (pc->getSelectedCandidatePair(&local, &remote)) {
|
||||
cout << "Local: " << local.address << ":" << local.port << " " << local.type << " "
|
||||
<< local.transportType << endl;
|
||||
cout << "Remote: " << remote.address << ":" << remote.port << " " << remote.type
|
||||
<< " " << remote.transportType << endl;
|
||||
cout << "Local: " << local << endl;
|
||||
cout << "Remote: " << remote << endl;
|
||||
cout << "Bytes Sent:" << pc->bytesSent()
|
||||
<< " / Bytes Received:" << pc->bytesReceived() << " / Round-Trip Time:";
|
||||
if (rtt.has_value())
|
||||
|
@ -36,12 +36,12 @@ int main(int argc, char **argv) {
|
||||
|
||||
auto pc = std::make_shared<PeerConnection>(config);
|
||||
|
||||
pc->onLocalDescription([](const Description &description) {
|
||||
pc->onLocalDescription([](Description description) {
|
||||
cout << "Local Description (Paste this to the other peer):" << endl;
|
||||
cout << string(description) << endl;
|
||||
});
|
||||
|
||||
pc->onLocalCandidate([](const Candidate &candidate) {
|
||||
pc->onLocalCandidate([](Candidate candidate) {
|
||||
cout << "Local Candidate (Paste this to the other peer after the local description):"
|
||||
<< endl;
|
||||
cout << string(candidate) << endl << endl;
|
||||
@ -60,7 +60,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
dc->onClosed([&]() { cout << "[DataChannel closed: " << dc->label() << "]" << endl; });
|
||||
|
||||
dc->onMessage([](const variant<binary, string> &message) {
|
||||
dc->onMessage([](variant<binary, string> message) {
|
||||
if (holds_alternative<string>(message)) {
|
||||
cout << "[Received: " << get<string>(message) << "]" << endl;
|
||||
}
|
||||
@ -127,13 +127,11 @@ int main(int argc, char **argv) {
|
||||
cout << "** Channel is not Open ** ";
|
||||
break;
|
||||
}
|
||||
CandidateInfo local, remote;
|
||||
Candidate local, remote;
|
||||
std::optional<std::chrono::milliseconds> rtt = pc->rtt();
|
||||
if (pc->getSelectedCandidatePair(&local, &remote)) {
|
||||
cout << "Local: " << local.address << ":" << local.port << " " << local.type << " "
|
||||
<< local.transportType << endl;
|
||||
cout << "Remote: " << remote.address << ":" << remote.port << " " << remote.type
|
||||
<< " " << remote.transportType << endl;
|
||||
cout << "Local: " << local << endl;
|
||||
cout << "Remote: " << remote << endl;
|
||||
cout << "Bytes Sent:" << pc->bytesSent()
|
||||
<< " / Bytes Received:" << pc->bytesReceived() << " / Round-Trip Time:";
|
||||
if (rtt.has_value())
|
||||
|
BIN
examples/copy-paste/uwp/answerer/Logo.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
examples/copy-paste/uwp/answerer/SmallLogo.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
examples/copy-paste/uwp/answerer/SmallLogo44x44.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
examples/copy-paste/uwp/answerer/SplashScreen.png
Normal file
After Width: | Height: | Size: 909 B |
BIN
examples/copy-paste/uwp/answerer/StoreLogo.png
Normal file
After Width: | Height: | Size: 227 B |
BIN
examples/copy-paste/uwp/answerer/Windows_TemporaryKey.pfx
Normal file
42
examples/copy-paste/uwp/answerer/package.appxManifest
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
|
||||
xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity Name="86FAC2A3-40CD-393F-9F55-52A30E0D3B8F" Publisher="CN=CMake" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="86FAC2A3-40CD-393F-9F55-52A30E0D3B8F" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
<Properties>
|
||||
<DisplayName>datachannel-copy-paste-answerer</DisplayName>
|
||||
<PublisherDisplayName>CMake</PublisherDisplayName>
|
||||
<Logo>StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application
|
||||
Id="App"
|
||||
Executable="answerer.exe"
|
||||
EntryPoint="datachannel-copy-paste-answerer.App"
|
||||
desktop4:Subsystem="console"
|
||||
desktop4:SupportsMultipleInstances="true"
|
||||
iot2:Subsystem="console"
|
||||
iot2:SupportsMultipleInstances="true">
|
||||
<uap:VisualElements
|
||||
DisplayName="datachannel-copy-paste-answerer"
|
||||
Description="datachannel-copy-paste-answerer"
|
||||
BackgroundColor="#336699"
|
||||
Square150x150Logo="Logo.png"
|
||||
Square44x44Logo="SmallLogo44x44.png">
|
||||
<uap:SplashScreen Image="SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
BIN
examples/copy-paste/uwp/offerer/Logo.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
examples/copy-paste/uwp/offerer/SmallLogo.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
examples/copy-paste/uwp/offerer/SmallLogo44x44.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
examples/copy-paste/uwp/offerer/SplashScreen.png
Normal file
After Width: | Height: | Size: 909 B |
BIN
examples/copy-paste/uwp/offerer/StoreLogo.png
Normal file
After Width: | Height: | Size: 227 B |
BIN
examples/copy-paste/uwp/offerer/Windows_TemporaryKey.pfx
Normal file
42
examples/copy-paste/uwp/offerer/package.appxManifest
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
|
||||
xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity Name="68160929-CE5F-3FC1-A120-BCB1C223FC2F" Publisher="CN=CMake" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="68160929-CE5F-3FC1-A120-BCB1C223FC2F" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
<Properties>
|
||||
<DisplayName>datachannel-copy-paste-offerer</DisplayName>
|
||||
<PublisherDisplayName>CMake</PublisherDisplayName>
|
||||
<Logo>StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application
|
||||
Id="App"
|
||||
Executable="offerer.exe"
|
||||
EntryPoint="datachannel-copy-paste-offerer.App"
|
||||
desktop4:Subsystem="console"
|
||||
desktop4:SupportsMultipleInstances="true"
|
||||
iot2:Subsystem="console"
|
||||
iot2:SupportsMultipleInstances="true">
|
||||
<uap:VisualElements
|
||||
DisplayName="datachannel-copy-paste-offerer"
|
||||
Description="datachannel-copy-paste-offerer"
|
||||
BackgroundColor="#336699"
|
||||
Square150x150Logo="Logo.png"
|
||||
Square44x44Logo="SmallLogo44x44.png">
|
||||
<uap:SplashScreen Image="SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
29
examples/media/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
set(MEDIA_UWP_RESOURCES
|
||||
uwp/Logo.png
|
||||
uwp/package.appxManifest
|
||||
uwp/SmallLogo.png
|
||||
uwp/SmallLogo44x44.png
|
||||
uwp/SplashScreen.png
|
||||
uwp/StoreLogo.png
|
||||
uwp/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
add_executable(datachannel-media main.cpp ${MEDIA_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-media main.cpp)
|
||||
endif()
|
||||
set_target_properties(datachannel-media PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
OUTPUT_NAME media)
|
||||
target_link_libraries(datachannel-media datachannel nlohmann_json)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET datachannel-media POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
|
||||
$<TARGET_FILE_DIR:datachannel-media>
|
||||
)
|
||||
endif()
|
19
examples/media/README.md
Normal file
@ -0,0 +1,19 @@
|
||||
# Example Webcam from Browser to Port 5000
|
||||
This is an example copy/paste demo to send your webcam from your browser and out port 5000 through the demo application.
|
||||
|
||||
## How to use
|
||||
Open main.html in your browser (you must open it either as HTTPS or as a domain of http://localhost).
|
||||
|
||||
Start the application and copy it's offer into the text box of the web page.
|
||||
|
||||
Copy the answer of the webpage back into the application.
|
||||
|
||||
You will now see RTP traffic on `localhost:5000` of the computer that the application is running on.
|
||||
|
||||
Use the following gstreamer demo pipeline to display the traffic
|
||||
(you might need to wave your hand in front of your camera to force an I-frame).
|
||||
|
||||
```
|
||||
$ gst-launch-1.0 udpsrc address=127.0.0.1 port=5000 caps="application/x-rtp" ! queue ! rtph264depay ! video/x-h264,stream-format=byte-stream ! queue ! avdec_h264 ! queue ! autovideosink
|
||||
```
|
||||
|
97
examples/media/main.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* libdatachannel client example
|
||||
* Copyright (c) 2020 Staz Modrzynski
|
||||
* Copyright (c) 2020 Paul-Louis Ageneau
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
|
||||
#include "rtc/rtc.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
typedef int SOCKET;
|
||||
#endif
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
int main() {
|
||||
try {
|
||||
rtc::InitLogger(rtc::LogLevel::Debug);
|
||||
auto pc = std::make_shared<rtc::PeerConnection>();
|
||||
|
||||
pc->onStateChange(
|
||||
[](rtc::PeerConnection::State state) { std::cout << "State: " << state << std::endl; });
|
||||
|
||||
pc->onGatheringStateChange([pc](rtc::PeerConnection::GatheringState state) {
|
||||
std::cout << "Gathering State: " << state << std::endl;
|
||||
if (state == rtc::PeerConnection::GatheringState::Complete) {
|
||||
auto description = pc->localDescription();
|
||||
json message = {{"type", description->typeString()},
|
||||
{"sdp", std::string(description.value())}};
|
||||
std::cout << message << std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
sockaddr_in addr;
|
||||
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
addr.sin_port = htons(5000);
|
||||
addr.sin_family = AF_INET;
|
||||
|
||||
rtc::Description::Video media("video", rtc::Description::Direction::RecvOnly);
|
||||
media.addH264Codec(96);
|
||||
media.setBitrate(
|
||||
3000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam)
|
||||
|
||||
auto track = pc->addTrack(media);
|
||||
|
||||
auto session = std::make_shared<rtc::RtcpReceivingSession>();
|
||||
track->setMediaHandler(session);
|
||||
|
||||
track->onMessage(
|
||||
[session, sock, addr](rtc::binary message) {
|
||||
// This is an RTP packet
|
||||
sendto(sock, reinterpret_cast<const char *>(message.data()), int(message.size()), 0,
|
||||
reinterpret_cast<const struct sockaddr *>(&addr), sizeof(addr));
|
||||
},
|
||||
nullptr);
|
||||
|
||||
pc->setLocalDescription();
|
||||
|
||||
std::cout << "Expect RTP video traffic on localhost:5000" << std::endl;
|
||||
std::cout << "Please copy/paste the answer provided by the browser: " << std::endl;
|
||||
std::string sdp;
|
||||
std::getline(std::cin, sdp);
|
||||
std::cout << "Got answer" << sdp << std::endl;
|
||||
json j = json::parse(sdp);
|
||||
rtc::Description answer(j["sdp"].get<std::string>(), j["type"].get<std::string>());
|
||||
pc->setRemoteDescription(answer);
|
||||
std::cout << "Press any key to exit." << std::endl;
|
||||
std::cin >> sdp;
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
45
examples/media/main.html
Normal file
@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>libdatachannel media example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Please enter the offer provided to you by the application: </p>
|
||||
<textarea cols="50" rows="50"></textarea>
|
||||
<button>Submit</button>
|
||||
|
||||
<script>
|
||||
document.querySelector('button').addEventListener('click', async () => {
|
||||
let offer = JSON.parse(document.querySelector('textarea').value);
|
||||
rtc = new RTCPeerConnection({
|
||||
// Recommended for libdatachannel
|
||||
bundlePolicy: "max-bundle",
|
||||
});
|
||||
|
||||
rtc.onicegatheringstatechange = (state) => {
|
||||
if (rtc.iceGatheringState === 'complete') {
|
||||
// We only want to provide an answer once all of our candidates have been added to the SDP.
|
||||
let answer = rtc.localDescription;
|
||||
document.querySelector('textarea').value = JSON.stringify({"type": answer.type, sdp: answer.sdp});
|
||||
document.querySelector('p').value = 'Please paste the answer in the application.';
|
||||
alert('Please paste the answer in the application.');
|
||||
}
|
||||
}
|
||||
await rtc.setRemoteDescription(offer);
|
||||
|
||||
let media = await navigator.mediaDevices.getUserMedia({
|
||||
video: {
|
||||
width: 1280,
|
||||
height: 720
|
||||
}
|
||||
});
|
||||
media.getTracks().forEach(track => rtc.addTrack(track, media));
|
||||
let answer = await rtc.createAnswer();
|
||||
await rtc.setLocalDescription(answer);
|
||||
})
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
BIN
examples/media/uwp/Logo.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
examples/media/uwp/SmallLogo.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
examples/media/uwp/SmallLogo44x44.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
examples/media/uwp/SplashScreen.png
Normal file
After Width: | Height: | Size: 909 B |
BIN
examples/media/uwp/StoreLogo.png
Normal file
After Width: | Height: | Size: 227 B |
BIN
examples/media/uwp/Windows_TemporaryKey.pfx
Normal file
42
examples/media/uwp/package.appxManifest
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
|
||||
xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity Name="6597869B-290B-3EC7-AC50-87D2B9B408A2" Publisher="CN=CMake" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="6597869B-290B-3EC7-AC50-87D2B9B408A2" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
<Properties>
|
||||
<DisplayName>datachannel-media</DisplayName>
|
||||
<PublisherDisplayName>CMake</PublisherDisplayName>
|
||||
<Logo>StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application
|
||||
Id="App"
|
||||
Executable="media.exe"
|
||||
EntryPoint="datachannel-media.App"
|
||||
desktop4:Subsystem="console"
|
||||
desktop4:SupportsMultipleInstances="true"
|
||||
iot2:Subsystem="console"
|
||||
iot2:SupportsMultipleInstances="true">
|
||||
<uap:VisualElements
|
||||
DisplayName="datachannel-media"
|
||||
Description="datachannel-media"
|
||||
BackgroundColor="#336699"
|
||||
Square150x150Logo="Logo.png"
|
||||
Square44x44Logo="SmallLogo44x44.png">
|
||||
<uap:SplashScreen Image="SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
29
examples/sfu-media/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
set(SFU_MEDIA_UWP_RESOURCES
|
||||
uwp/Logo.png
|
||||
uwp/package.appxManifest
|
||||
uwp/SmallLogo.png
|
||||
uwp/SmallLogo44x44.png
|
||||
uwp/SplashScreen.png
|
||||
uwp/StoreLogo.png
|
||||
uwp/Windows_TemporaryKey.pfx
|
||||
)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
add_executable(datachannel-sfu-media main.cpp ${SFU_MEDIA_UWP_RESOURCES})
|
||||
else()
|
||||
add_executable(datachannel-sfu-media main.cpp)
|
||||
endif()
|
||||
set_target_properties(datachannel-sfu-media PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
OUTPUT_NAME sfu-media)
|
||||
target_link_libraries(datachannel-sfu-media datachannel nlohmann_json)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET datachannel-sfu-media POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
|
||||
$<TARGET_FILE_DIR:datachannel-sfu-media>
|
||||
)
|
||||
endif()
|
134
examples/sfu-media/main.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* libdatachannel client example
|
||||
* Copyright (c) 2020 Staz Modrzynski
|
||||
* Copyright (c) 2020 Paul-Louis Ageneau
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
|
||||
#include "rtc/rtc.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
struct Receiver {
|
||||
std::shared_ptr<rtc::PeerConnection> conn;
|
||||
std::shared_ptr<rtc::Track> track;
|
||||
};
|
||||
int main() {
|
||||
std::vector<std::shared_ptr<Receiver>> receivers;
|
||||
|
||||
try {
|
||||
rtc::InitLogger(rtc::LogLevel::Info);
|
||||
|
||||
auto pc = std::make_shared<rtc::PeerConnection>();
|
||||
pc->onStateChange(
|
||||
[](rtc::PeerConnection::State state) { std::cout << "State: " << state << std::endl; });
|
||||
pc->onGatheringStateChange([pc](rtc::PeerConnection::GatheringState state) {
|
||||
std::cout << "Gathering State: " << state << std::endl;
|
||||
if (state == rtc::PeerConnection::GatheringState::Complete) {
|
||||
auto description = pc->localDescription();
|
||||
json message = {{"type", description->typeString()},
|
||||
{"sdp", std::string(description.value())}};
|
||||
std::cout << "Please copy/paste this offer to the SENDER: " << message << std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
rtc::Description::Video media("video", rtc::Description::Direction::RecvOnly);
|
||||
media.addH264Codec(96);
|
||||
media.setBitrate(
|
||||
3000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam)
|
||||
|
||||
auto track = pc->addTrack(media);
|
||||
pc->setLocalDescription();
|
||||
|
||||
auto session = std::make_shared<rtc::RtcpReceivingSession>();
|
||||
track->setMediaHandler(session);
|
||||
|
||||
const rtc::SSRC targetSSRC = 4;
|
||||
|
||||
track->onMessage(
|
||||
[&receivers, targetSSRC](rtc::binary message) {
|
||||
// This is an RTP packet
|
||||
auto rtp = (rtc::RTP *)message.data();
|
||||
rtp->setSsrc(targetSSRC);
|
||||
for (auto pc : receivers) {
|
||||
if (pc->track != nullptr && pc->track->isOpen()) {
|
||||
pc->track->send(message);
|
||||
}
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
|
||||
// Set the SENDERS Answer
|
||||
{
|
||||
std::cout << "Please copy/paste the answer provided by the SENDER: " << std::endl;
|
||||
std::string sdp;
|
||||
std::getline(std::cin, sdp);
|
||||
std::cout << "Got answer" << sdp << std::endl;
|
||||
json j = json::parse(sdp);
|
||||
rtc::Description answer(j["sdp"].get<std::string>(), j["type"].get<std::string>());
|
||||
pc->setRemoteDescription(answer);
|
||||
}
|
||||
|
||||
// For each receiver
|
||||
while (true) {
|
||||
auto pc = std::make_shared<Receiver>();
|
||||
pc->conn = std::make_shared<rtc::PeerConnection>();
|
||||
pc->conn->onStateChange([](rtc::PeerConnection::State state) {
|
||||
std::cout << "State: " << state << std::endl;
|
||||
});
|
||||
pc->conn->onGatheringStateChange([pc](rtc::PeerConnection::GatheringState state) {
|
||||
std::cout << "Gathering State: " << state << std::endl;
|
||||
if (state == rtc::PeerConnection::GatheringState::Complete) {
|
||||
auto description = pc->conn->localDescription();
|
||||
json message = {{"type", description->typeString()},
|
||||
{"sdp", std::string(description.value())}};
|
||||
std::cout << "Please copy/paste this offer to the RECEIVER: " << message
|
||||
<< std::endl;
|
||||
}
|
||||
});
|
||||
rtc::Description::Video media("video", rtc::Description::Direction::SendOnly);
|
||||
media.addH264Codec(96);
|
||||
media.setBitrate(
|
||||
3000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam)
|
||||
|
||||
media.addSSRC(targetSSRC, "video-send");
|
||||
|
||||
pc->track = pc->conn->addTrack(media);
|
||||
pc->conn->setLocalDescription();
|
||||
|
||||
pc->track->onMessage([](rtc::binary var) {}, nullptr);
|
||||
|
||||
std::cout << "Please copy/paste the answer provided by the RECEIVER: " << std::endl;
|
||||
std::string sdp;
|
||||
std::getline(std::cin, sdp);
|
||||
std::cout << "Got answer" << sdp << std::endl;
|
||||
json j = json::parse(sdp);
|
||||
rtc::Description answer(j["sdp"].get<std::string>(), j["type"].get<std::string>());
|
||||
pc->conn->setRemoteDescription(answer);
|
||||
|
||||
receivers.push_back(pc);
|
||||
}
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
87
examples/sfu-media/main.html
Normal file
@ -0,0 +1,87 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>libdatachannel media example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div style="display:inline-block; width:40%;">
|
||||
<h1>SENDER</h1>
|
||||
<p id="send-help">Please enter the offer provided to you by the application: </p>
|
||||
<textarea style="width:100%;" id=send-text rows="50"></textarea>
|
||||
<button id=send-btn>Submit</button>
|
||||
</div>
|
||||
<div style="display:inline-block; width:40%;">
|
||||
<h1>RECEIVER</h1>
|
||||
<p id="recv-help">Please enter the offer provided to you by the application: </p>
|
||||
<textarea id=recv-text style="width:100%;" rows="50"></textarea>
|
||||
<button id=recv-btn>Submit</button>
|
||||
</div>
|
||||
<div id="videos">
|
||||
|
||||
</div>
|
||||
<script>
|
||||
document.querySelector('#send-btn').addEventListener('click', async () => {
|
||||
let offer = JSON.parse(document.querySelector('#send-text').value);
|
||||
rtc = new RTCPeerConnection({
|
||||
// Recommended for libdatachannel
|
||||
bundlePolicy: "max-bundle",
|
||||
});
|
||||
|
||||
rtc.onicegatheringstatechange = (state) => {
|
||||
if (rtc.iceGatheringState === 'complete') {
|
||||
// We only want to provide an answer once all of our candidates have been added to the SDP.
|
||||
let answer = rtc.localDescription;
|
||||
document.querySelector('#send-text').value = JSON.stringify({"type": answer.type, sdp: answer.sdp});
|
||||
document.querySelector('#send-help').value = 'Please paste the answer in the application.';
|
||||
alert('Please paste the answer in the application.');
|
||||
}
|
||||
}
|
||||
await rtc.setRemoteDescription(offer);
|
||||
|
||||
let media = await navigator.mediaDevices.getUserMedia({
|
||||
video: {
|
||||
width: 1280,
|
||||
height: 720
|
||||
}
|
||||
});
|
||||
media.getTracks().forEach(track => rtc.addTrack(track, media));
|
||||
let answer = await rtc.createAnswer();
|
||||
await rtc.setLocalDescription(answer);
|
||||
});
|
||||
|
||||
document.querySelector('#recv-btn').addEventListener('click', async () => {
|
||||
let offer = JSON.parse(document.querySelector('#recv-text').value);
|
||||
rtc = new RTCPeerConnection({
|
||||
// Recommended for libdatachannel
|
||||
bundlePolicy: "max-bundle",
|
||||
});
|
||||
|
||||
rtc.onicegatheringstatechange = (state) => {
|
||||
if (rtc.iceGatheringState === 'complete') {
|
||||
// We only want to provide an answer once all of our candidates have been added to the SDP.
|
||||
let answer = rtc.localDescription;
|
||||
document.querySelector('#recv-text').value = JSON.stringify({"type": answer.type, sdp: answer.sdp});
|
||||
document.querySelector('#recv-help').value = 'Please paste the answer in the application.';
|
||||
alert('Please paste the answer in the application.');
|
||||
}
|
||||
}
|
||||
let trackCount = 0;
|
||||
rtc.ontrack = (ev) => {
|
||||
let thisID = trackCount++;
|
||||
|
||||
document.querySelector("#videos").innerHTML += "<video width=100% height=100% id='video-" + thisID + "'></video>";
|
||||
let tracks = [];
|
||||
rtc.getReceivers().forEach(recv => tracks.push(recv.track));
|
||||
document.querySelector("#video-" + thisID).srcObject = new MediaStream(tracks);
|
||||
document.querySelector("#video-" + thisID).play();
|
||||
};
|
||||
await rtc.setRemoteDescription(offer);
|
||||
let answer = await rtc.createAnswer();
|
||||
await rtc.setLocalDescription(answer);
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
BIN
examples/sfu-media/uwp/Logo.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
examples/sfu-media/uwp/SmallLogo.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
examples/sfu-media/uwp/SmallLogo44x44.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
examples/sfu-media/uwp/SplashScreen.png
Normal file
After Width: | Height: | Size: 909 B |
BIN
examples/sfu-media/uwp/StoreLogo.png
Normal file
After Width: | Height: | Size: 227 B |
BIN
examples/sfu-media/uwp/Windows_TemporaryKey.pfx
Normal file
42
examples/sfu-media/uwp/package.appxManifest
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
|
||||
xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity Name="A2137F64-F4DB-39E1-8A6E-19BF1A64645A" Publisher="CN=CMake" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="A2137F64-F4DB-39E1-8A6E-19BF1A64645A" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
<Properties>
|
||||
<DisplayName>datachannel-sfu-media</DisplayName>
|
||||
<PublisherDisplayName>CMake</PublisherDisplayName>
|
||||
<Logo>StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application
|
||||
Id="App"
|
||||
Executable="sfu-media.exe"
|
||||
EntryPoint="datachannel-sfu-media.App"
|
||||
desktop4:Subsystem="console"
|
||||
desktop4:SupportsMultipleInstances="true"
|
||||
iot2:Subsystem="console"
|
||||
iot2:SupportsMultipleInstances="true">
|
||||
<uap:VisualElements
|
||||
DisplayName="datachannel-sfu-media"
|
||||
Description="datachannel-sfu-media"
|
||||
BackgroundColor="#336699"
|
||||
Square150x150Logo="Logo.png"
|
||||
Square44x44Logo="SmallLogo44x44.png">
|
||||
<uap:SplashScreen Image="SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
339
examples/signaling-server-nodejs/LICENSE
Normal file
@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
285
examples/signaling-server-nodejs/package-lock.json
generated
Normal file
@ -0,0 +1,285 @@
|
||||
{
|
||||
"name": "libdatachannel-signaling-server",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "libdatachannel-signaling-server",
|
||||
"version": "0.1.0",
|
||||
"license": "GPL-2.0",
|
||||
"dependencies": {
|
||||
"websocket": "^1.0.33"
|
||||
}
|
||||
},
|
||||
"node_modules/bufferutil": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.2.tgz",
|
||||
"integrity": "sha512-AtnG3W6M8B2n4xDQ5R+70EXvOpnXsFYg/AK2yTZd+HQ/oxAdz+GI+DvjmhBw3L0ole+LJ0ngqY4JMbDzkfNzhA==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"node-gyp-build": "^4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/d": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz",
|
||||
"integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==",
|
||||
"dependencies": {
|
||||
"es5-ext": "^0.10.50",
|
||||
"type": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"dependencies": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/es5-ext": {
|
||||
"version": "0.10.53",
|
||||
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.53.tgz",
|
||||
"integrity": "sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==",
|
||||
"dependencies": {
|
||||
"es6-iterator": "~2.0.3",
|
||||
"es6-symbol": "~3.1.3",
|
||||
"next-tick": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/es6-iterator": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
|
||||
"integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=",
|
||||
"dependencies": {
|
||||
"d": "1",
|
||||
"es5-ext": "^0.10.35",
|
||||
"es6-symbol": "^3.1.1"
|
||||
}
|
||||
},
|
||||
"node_modules/es6-symbol": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz",
|
||||
"integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==",
|
||||
"dependencies": {
|
||||
"d": "^1.0.1",
|
||||
"ext": "^1.1.2"
|
||||
}
|
||||
},
|
||||
"node_modules/ext": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz",
|
||||
"integrity": "sha512-Key5NIsUxdqKg3vIsdw9dSuXpPCQ297y6wBjL30edxwPgt2E44WcWBZey/ZvUc6sERLTxKdyCu4gZFmUbk1Q7A==",
|
||||
"dependencies": {
|
||||
"type": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ext/node_modules/type": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/type/-/type-2.1.0.tgz",
|
||||
"integrity": "sha512-G9absDWvhAWCV2gmF1zKud3OyC61nZDwWvBL2DApaVFogI07CprggiQAOOjvp2NRjYWFzPyu7vwtDrQFq8jeSA=="
|
||||
},
|
||||
"node_modules/is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"node_modules/next-tick": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
|
||||
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
|
||||
},
|
||||
"node_modules/node-gyp-build": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz",
|
||||
"integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==",
|
||||
"bin": {
|
||||
"node-gyp-build": "bin.js",
|
||||
"node-gyp-build-optional": "optional.js",
|
||||
"node-gyp-build-test": "build-test.js"
|
||||
}
|
||||
},
|
||||
"node_modules/type": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz",
|
||||
"integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg=="
|
||||
},
|
||||
"node_modules/typedarray-to-buffer": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
|
||||
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
|
||||
"dependencies": {
|
||||
"is-typedarray": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/utf-8-validate": {
|
||||
"version": "5.0.3",
|
||||
"resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.3.tgz",
|
||||
"integrity": "sha512-jtJM6fpGv8C1SoH4PtG22pGto6x+Y8uPprW0tw3//gGFhDDTiuksgradgFN6yRayDP4SyZZa6ZMGHLIa17+M8A==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"node-gyp-build": "^4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/websocket": {
|
||||
"version": "1.0.33",
|
||||
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.33.tgz",
|
||||
"integrity": "sha512-XwNqM2rN5eh3G2CUQE3OHZj+0xfdH42+OFK6LdC2yqiC0YU8e5UK0nYre220T0IyyN031V/XOvtHvXozvJYFWA==",
|
||||
"dependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"debug": "^2.2.0",
|
||||
"es5-ext": "^0.10.50",
|
||||
"typedarray-to-buffer": "^3.1.5",
|
||||
"utf-8-validate": "^5.0.2",
|
||||
"yaeti": "^0.0.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/yaeti": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
|
||||
"integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc=",
|
||||
"engines": {
|
||||
"node": ">=0.10.32"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"bufferutil": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.2.tgz",
|
||||
"integrity": "sha512-AtnG3W6M8B2n4xDQ5R+70EXvOpnXsFYg/AK2yTZd+HQ/oxAdz+GI+DvjmhBw3L0ole+LJ0ngqY4JMbDzkfNzhA==",
|
||||
"requires": {
|
||||
"node-gyp-build": "^4.2.0"
|
||||
}
|
||||
},
|
||||
"d": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz",
|
||||
"integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==",
|
||||
"requires": {
|
||||
"es5-ext": "^0.10.50",
|
||||
"type": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"es5-ext": {
|
||||
"version": "0.10.53",
|
||||
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.53.tgz",
|
||||
"integrity": "sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==",
|
||||
"requires": {
|
||||
"es6-iterator": "~2.0.3",
|
||||
"es6-symbol": "~3.1.3",
|
||||
"next-tick": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"es6-iterator": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
|
||||
"integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=",
|
||||
"requires": {
|
||||
"d": "1",
|
||||
"es5-ext": "^0.10.35",
|
||||
"es6-symbol": "^3.1.1"
|
||||
}
|
||||
},
|
||||
"es6-symbol": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz",
|
||||
"integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==",
|
||||
"requires": {
|
||||
"d": "^1.0.1",
|
||||
"ext": "^1.1.2"
|
||||
}
|
||||
},
|
||||
"ext": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz",
|
||||
"integrity": "sha512-Key5NIsUxdqKg3vIsdw9dSuXpPCQ297y6wBjL30edxwPgt2E44WcWBZey/ZvUc6sERLTxKdyCu4gZFmUbk1Q7A==",
|
||||
"requires": {
|
||||
"type": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"type": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/type/-/type-2.1.0.tgz",
|
||||
"integrity": "sha512-G9absDWvhAWCV2gmF1zKud3OyC61nZDwWvBL2DApaVFogI07CprggiQAOOjvp2NRjYWFzPyu7vwtDrQFq8jeSA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"next-tick": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
|
||||
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
|
||||
},
|
||||
"node-gyp-build": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz",
|
||||
"integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg=="
|
||||
},
|
||||
"type": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz",
|
||||
"integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg=="
|
||||
},
|
||||
"typedarray-to-buffer": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
|
||||
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
|
||||
"requires": {
|
||||
"is-typedarray": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"version": "5.0.3",
|
||||
"resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.3.tgz",
|
||||
"integrity": "sha512-jtJM6fpGv8C1SoH4PtG22pGto6x+Y8uPprW0tw3//gGFhDDTiuksgradgFN6yRayDP4SyZZa6ZMGHLIa17+M8A==",
|
||||
"requires": {
|
||||
"node-gyp-build": "^4.2.0"
|
||||
}
|
||||
},
|
||||
"websocket": {
|
||||
"version": "1.0.33",
|
||||
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.33.tgz",
|
||||
"integrity": "sha512-XwNqM2rN5eh3G2CUQE3OHZj+0xfdH42+OFK6LdC2yqiC0YU8e5UK0nYre220T0IyyN031V/XOvtHvXozvJYFWA==",
|
||||
"requires": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"debug": "^2.2.0",
|
||||
"es5-ext": "^0.10.50",
|
||||
"typedarray-to-buffer": "^3.1.5",
|
||||
"utf-8-validate": "^5.0.2",
|
||||
"yaeti": "^0.0.6"
|
||||
}
|
||||
},
|
||||
"yaeti": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
|
||||
"integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc="
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "libdatachannel-example-web",
|
||||
"version": "0.0.1",
|
||||
"description": "Example for libdatachannel",
|
||||
"name": "libdatachannel-signaling-server",
|
||||
"version": "0.1.0",
|
||||
"description": "Signaling server example for libdatachannel",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"start": "node signaling-server.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
@ -18,6 +18,6 @@
|
||||
},
|
||||
"homepage": "https://github.com/paullouisageneau/libdatachannel#readme",
|
||||
"dependencies": {
|
||||
"websocket": "^1.0.31"
|
||||
"websocket": "^1.0.33"
|
||||
}
|
||||
}
|
@ -21,12 +21,6 @@ const fs = require('fs');
|
||||
const http = require('http');
|
||||
const websocket = require('websocket');
|
||||
|
||||
const staticFiles = {
|
||||
'/index.html': 'text/html',
|
||||
'/style.css': 'text/css',
|
||||
'/script.js': 'text/javascript',
|
||||
};
|
||||
|
||||
const clients = {};
|
||||
|
||||
const httpServer = http.createServer((req, res) => {
|
||||
@ -34,58 +28,38 @@ const httpServer = http.createServer((req, res) => {
|
||||
|
||||
const respond = (code, data, contentType = 'text/plain') => {
|
||||
res.writeHead(code, {
|
||||
'Content-Type': contentType,
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Type' : contentType,
|
||||
'Access-Control-Allow-Origin' : '*',
|
||||
});
|
||||
res.end(data);
|
||||
};
|
||||
|
||||
if(req.method != 'GET') {
|
||||
respond(405, 'Method not allowed');
|
||||
return;
|
||||
}
|
||||
|
||||
const url = req.url == '/' ? '/index.html' : req.url;
|
||||
const contentType = staticFiles[url];
|
||||
if(!contentType) {
|
||||
respond(404, 'Not found');
|
||||
return;
|
||||
}
|
||||
|
||||
fs.readFile(__dirname + url, (err, data) => {
|
||||
if(err) {
|
||||
respond(500, 'Missing file');
|
||||
return;
|
||||
}
|
||||
|
||||
respond(200, data, contentType);
|
||||
});
|
||||
respond(404, 'Not Found');
|
||||
});
|
||||
|
||||
const wsServer = new websocket.server({ httpServer });
|
||||
const wsServer = new websocket.server({httpServer});
|
||||
wsServer.on('request', (req) => {
|
||||
console.log(`WS ${req.resource}`);
|
||||
|
||||
const { path } = req.resourceURL;
|
||||
const {path} = req.resourceURL;
|
||||
const splitted = path.split('/');
|
||||
splitted.shift();
|
||||
const id = splitted[0];
|
||||
|
||||
const conn = req.accept(null, req.origin);
|
||||
conn.on('message', (data) => {
|
||||
if(data.type === 'utf8') {
|
||||
if (data.type === 'utf8') {
|
||||
console.log(`Client ${id} << ${data.utf8Data}`);
|
||||
|
||||
const message = JSON.parse(data.utf8Data);
|
||||
const destId = message.id;
|
||||
const dest = clients[destId];
|
||||
if(dest) {
|
||||
if (dest) {
|
||||
message.id = id;
|
||||
const data = JSON.stringify(message);
|
||||
console.log(`Client ${destId} >> ${data}`);
|
||||
dest.send(data);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.error(`Client ${destId} not found`);
|
||||
}
|
||||
}
|
||||
@ -98,5 +72,10 @@ wsServer.on('request', (req) => {
|
||||
clients[id] = conn;
|
||||
});
|
||||
|
||||
httpServer.listen(8000);
|
||||
const endpoint = process.env.PORT || '8000';
|
||||
const splitted = endpoint.split(':');
|
||||
const port = splitted.pop();
|
||||
const hostname = splitted.join(':') || '127.0.0.1';
|
||||
|
||||
httpServer.listen(port, hostname,
|
||||
() => { console.log(`Server listening on ${hostname}:${port}`); });
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Signaling server example for libdatachannel
|
||||
# Python signaling server example for libdatachannel
|
||||
# Copyright (c) 2020 Paul-Louis Ageneau
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
@ -63,16 +63,20 @@ async def handle_websocket(websocket, path):
|
||||
print('Client {} disconnected'.format(client_id))
|
||||
|
||||
if __name__ == '__main__':
|
||||
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
|
||||
# Usage: ./server.py [[host:]port] [SSL certificate file]
|
||||
endpoint_or_port = sys.argv[1] if len(sys.argv) > 1 else "8000"
|
||||
ssl_cert = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
|
||||
endpoint = endpoint_or_port if ':' in endpoint_or_port else "127.0.0.1:" + endpoint_or_port
|
||||
|
||||
if ssl_cert:
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||
ssl_context.load_cert_chain(ssl_cert)
|
||||
else:
|
||||
ssl_context = None
|
||||
|
||||
print('Listening on port {}'.format(port))
|
||||
start_server = websockets.serve(handle_websocket, '127.0.0.1', port, ssl=ssl_context)
|
||||
print('Listening on {}'.format(endpoint))
|
||||
host, port = endpoint.rsplit(':', 1)
|
||||
start_server = websockets.serve(handle_websocket, host, int(port), ssl=ssl_context)
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
asyncio.get_event_loop().run_forever()
|
||||
|