# callany_cpp **Repository Path**: sevcat/callany_cpp ## Basic Information - **Project Name**: callany_cpp - **Description**: No description available - **Primary Language**: Unknown - **License**: MPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-10-16 - **Last Updated**: 2023-10-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # callany - C/C++ API network library ## 依赖 - [GnuTLS](https://www.gnutls.org/), [Mbed TLS](https://www.trustedfirmware.org/projects/mbed-tls/), or [OpenSSL](https://www.openssl.org/) - [usrsctp](https://github.com/sctplab/usrsctp) (as submodule by default) - [Plog](https://github.com/SergiusTheBest/plog) (as submodule by default) - [libjuice](https://github.com/paullouisageneau/libjuice) (as submodule by default) or [libnice](https://nice.freedesktop.org/) as an ICE backend. - [libsrtp](https://github.com/cisco/libsrtp) (as submodule by default) required if compiled with media support. - [nlohmann JSON](https://github.com/nlohmann/json) (as submodule by default) required to build examples. ## 编译 见 BUILDING.md ## 例子 See examples for complete usage examples with signaling server (under MPL 2.0). Additionally, you might want to have a look at the C API documentation DOC.md. ### 创建连接 ```cpp #include "rtc/rtc.hpp" ``` ```cpp rtc::Configuration config; config.iceServers.emplace_back("mystunserver.org:3478"); rtc::PeerConnection pc(config); pc.onLocalDescription([](rtc::Description sdp) { // Send the SDP to the remote peer MY_SEND_DESCRIPTION_TO_REMOTE(std::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](std::string sdp) { pc.setRemoteDescription(rtc::Description(sdp)); }); MY_ON_RECV_CANDIDATE_FROM_REMOTE([&pc](std::string candidate, std::string mid) { pc.addRemoteCandidate(rtc::Candidate(candidate, mid)); }); ``` ### 检测连接状态 ```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; }); ``` ### 字幕通道 ```cpp auto dc = pc.createDataChannel("test"); dc->onOpen([]() { std::cout << "Open" << std::endl; }); dc->onMessage([](std::variant message) { if (std::holds_alternative(message)) { std::cout << "Received: " << get(message) << std::endl; } }); ``` ### 接收字幕 ```cpp std::shared_ptr dc; pc.onDataChannel([&dc](std::shared_ptr incoming) { dc = incoming; dc->send("Hello world!"); }); ``` ### 其他方式 WebSocket ```cpp rtc::WebSocket ws; ws.onOpen([]() { std::cout << "WebSocket open" << std::endl; }); ws.onMessage([](std::variant message) { if (std::holds_alternative(message)) { std::cout << "WebSocket received: " << std::get(message) << endl; } }); ws.open("wss://my.websocket/service"); ``` ## 致谢 Thanks to [Streamr](https://streamr.network/), [Vagon](https://vagon.io/), [Shiguredo](https://github.com/shiguredo), [Deon Botha](https://github.com/dbotha), and [Michael Cho](https://github.com/micoolcho) for sponsoring this work!