Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
cmake-build-debug
|
||||
.idea/*
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "protocol"]
|
||||
path = protocol
|
||||
url = https://github.com/livekit/protocol
|
||||
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
project(livekit-native)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
find_package(Boost COMPONENTS system REQUIRED)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
find_package(Protobuf REQUIRED)
|
||||
include_directories(${Protobuf_INCLUDE_DIR})
|
||||
|
||||
file(GLOB_RECURSE SRC src/*)
|
||||
add_executable(livekit-native ${SRC} main.cpp)
|
||||
target_link_libraries(livekit-native ${Boost_LIBRARIES} ${Protobuf_LIBRARIES})
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
protoc -I=protocol --cpp_out=src/proto protocol/livekit_models.proto protocol/livekit_rtc.proto
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <iostream>
|
||||
#include <boost/regex.hpp>
|
||||
#include "src/signal_client.h"
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
|
||||
livekit::SignalClient client;
|
||||
client.Connect("ws://localhost:7880/rtc", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTMzMTY2MjYsImlzcyI6IkFQSUNrSG04M01oZ2hQeCIsIm5iZiI6MTY1MDcyNDYyNiwic3ViIjoidGVzdCIsInZpZGVvIjp7InJvb20iOiJ0ZXN0cm9vbSIsInJvb21Kb2luIjp0cnVlfX0.I3Q5W4pk1kUNguGEJ4m95nE8hl8cPCliXBtF9hCt-Wg");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Submodule
+1
Submodule protocol added at fa9efaff8c
@@ -0,0 +1 @@
|
||||
* linguist-generated
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by Théo Monnom on 27/04/2022.
|
||||
//
|
||||
|
||||
#include "signal_client.h"
|
||||
#include "proto/livekit_rtc.pb.h"
|
||||
#include <boost/regex.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace livekit {
|
||||
void SignalClient::Connect(const std::string& url, const std::string& token) {
|
||||
boost::regex reg("(ws|wss)://([^:]+):?([^/]*)(.*)");
|
||||
boost::match_results<std::string::const_iterator> regMatches;
|
||||
if (boost::regex_match(url, regMatches, reg))
|
||||
{
|
||||
const std::string protocol = regMatches[1]; // TODO Check if secure or not
|
||||
const std::string domain = regMatches[2];
|
||||
const std::string port = regMatches[3];
|
||||
|
||||
m_WebSocket = std::make_unique<websocket::stream<tcp::socket>>(m_IOContext);
|
||||
|
||||
tcp::resolver resolver{m_IOContext};
|
||||
auto const results = resolver.resolve(domain, port);
|
||||
net::connect(m_WebSocket->next_layer(), results.begin(), results.end());
|
||||
|
||||
m_WebSocket->handshake(domain, "/rtc?access_token=" + token);
|
||||
|
||||
while(true){
|
||||
beast::flat_buffer buffer;
|
||||
m_WebSocket->read(buffer);
|
||||
}
|
||||
|
||||
}else{
|
||||
throw std::runtime_error{"Failed to parse url"};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by Théo Monnom on 27/04/2022.
|
||||
//
|
||||
|
||||
#ifndef LIVEKIT_NATIVE_SIGNAL_CLIENT_H
|
||||
#define LIVEKIT_NATIVE_SIGNAL_CLIENT_H
|
||||
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
namespace livekit {
|
||||
class SignalClient {
|
||||
|
||||
public:
|
||||
void Connect(const std::string& url, const std::string& token);
|
||||
|
||||
private:
|
||||
net::io_context m_IOContext;
|
||||
std::unique_ptr<websocket::stream<tcp::socket>> m_WebSocket;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //LIVEKIT_NATIVE_SIGNAL_CLIENT_H
|
||||
Reference in New Issue
Block a user