Merge pull request #20 from ItsNewe/master
[edit] Deprecate gRPC in favor of MongoDB
This commit is contained in:
commit
2e1a821601
@ -1,32 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(fosscord-media)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(Protobuf REQUIRED)
|
||||
find_package(gRPC CONFIG REQUIRED)
|
||||
find_package(absl REQUIRED)
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
|
||||
find_package(mongocxx REQUIRED)
|
||||
find_package(Boost REQUIRED)
|
||||
|
||||
|
||||
file(GLOB SourceFiles ${PROJECT_SOURCE_DIR}/src/*.cpp)
|
||||
|
||||
file(GLOB ProtoFiles ${PROJECT_SOURCE_DIR}/src/protodefs/*.proto)
|
||||
set(PROTOBUF_INPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/src/protodefs)
|
||||
set(PROTOBUF_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/src/protodefs/include)
|
||||
|
||||
foreach(file ${ProtoFiles})
|
||||
execute_process(COMMAND "LD_LIBRARY_PATH=/usr/local/lib protoc --proto_path=\"${PROTOBUF_INPUT_DIRECTORY}\"
|
||||
--cpp_out=\"${PROJECT_SOURCE_DIR}/src/protodefs/include\" --grpc_out=\"${PROJECT_SOURCE_DIR}/src/protodefs/include\"
|
||||
--plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin protos.proto"
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
endforeach()
|
||||
|
||||
|
||||
include_directories(${Protobuf_INCLUDE_DIRS})
|
||||
|
||||
#protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ProtoFiles)
|
||||
|
||||
#include_directories("bsoncxx/v_noabi/bsoncxx/")
|
||||
add_executable(${CMAKE_PROJECT_NAME} ${SourceFiles})
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} datachannel gRPC::grpc++ absl::base absl::synchronization absl::strings ${Protobuf_LIBRARIES} nlohmann_json::nlohmann_json)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} datachannel mongo::mongocxx_shared Boost::boost)
|
@ -5,7 +5,7 @@ A Fosscord media (voice and video) server
|
||||
## Installation
|
||||
### Prerequisites
|
||||
- Install the [libdatachannel](https://github.com/paullouisageneau/libdatachannel) library
|
||||
- Install the [gRPC](https://github.com/grpc/grpc) library
|
||||
- Install the [limbongocxx]() driver
|
||||
|
||||
### Building
|
||||
|
||||
|
15
src/main.cpp
15
src/main.cpp
@ -22,15 +22,24 @@
|
||||
//
|
||||
|
||||
#include "rtcPeerHandler.hpp" //Handle peer connection requests
|
||||
#include "rpcStub.hpp" //Handle gRPC communications between the different fosscord elements
|
||||
#include "mongoStub.hpp" //Handle communication with the MongoDB server
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
auto commsHandler = std::make_shared<rtcPeerHandler>();
|
||||
auto rpcHandler = std::unique_ptr<rpcStub>(new rpcStub(commsHandler, 8057));
|
||||
auto mongoHandler = std::make_unique<mongoStub>();
|
||||
|
||||
mongocxx::options::change_stream options;
|
||||
mongocxx::change_stream colCs = mongoHandler->getCol().watch(options);
|
||||
|
||||
//Check for new messages in the collection
|
||||
for (;;){
|
||||
std::vector<std::string> t = mongoHandler->getNewMessages(&colCs);
|
||||
for(auto &i : t){
|
||||
std::cout << i << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "Server created" << std::endl;
|
||||
|
||||
//rpcHandler->server->Wait(); //blocking, this will need to be threaded
|
||||
return 0;
|
||||
}
|
26
src/mongoStub.cpp
Normal file
26
src/mongoStub.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "mongoStub.hpp"
|
||||
|
||||
mongoStub::mongoStub() {
|
||||
if (this->client) {
|
||||
this->db = client["fosscord"];
|
||||
|
||||
if (this->db) {
|
||||
this->col = db["events"];
|
||||
|
||||
} else {
|
||||
std::cout << "db not found";
|
||||
exit(-1);
|
||||
}
|
||||
} else {
|
||||
std::cout << "Client couldn't be initialized";
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string>mongoStub::getNewMessages(mongocxx::change_stream* colCs) {
|
||||
std::vector<std::string> retVec;
|
||||
for (const auto& event : *colCs) {
|
||||
retVec.push_back(bsoncxx::to_json(event));
|
||||
}
|
||||
return retVec;
|
||||
}
|
29
src/mongoStub.hpp
Normal file
29
src/mongoStub.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef MONGOSTUB_HPP
|
||||
#define MONGOSTUB_HPP
|
||||
|
||||
#include <boost/utility.hpp>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <mongocxx/client.hpp>
|
||||
#include <mongocxx/instance.hpp>
|
||||
#include <mongocxx/v_noabi/mongocxx/change_stream.hpp>
|
||||
#include <bsoncxx/json.hpp>
|
||||
|
||||
|
||||
class mongoStub : boost::noncopyable {
|
||||
public:
|
||||
mongoStub();
|
||||
std::vector<std::string> getNewMessages(mongocxx::change_stream* colCs);
|
||||
|
||||
mongocxx::collection getCol() const { return col; }
|
||||
|
||||
private:
|
||||
mongocxx::instance instance;
|
||||
mongocxx::client client{mongocxx::uri{}};
|
||||
mongocxx::database db;
|
||||
mongocxx::collection col;
|
||||
mongocxx::change_stream* colCs = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,32 +0,0 @@
|
||||
#include "rpcStub.hpp"
|
||||
|
||||
class fossCordInternalsImpl final : public fosscordMedia::fosscordInternals::Service {
|
||||
std::shared_ptr<rtcPeerHandler> ph;
|
||||
fossCordInternalsImpl(std::shared_ptr<rtcPeerHandler> handler){
|
||||
this->ph= handler;
|
||||
}
|
||||
grpc::Status vRequest(grpc::ServerContext* ctx,
|
||||
const fosscordMedia::voiceRequest* req,
|
||||
fosscordMedia::voiceAnswer* resp) override {
|
||||
|
||||
this->ph->initiateConnection(req->ip(), req->port());
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
};
|
||||
|
||||
rpcStub::rpcStub(std::shared_ptr<rtcPeerHandler> handler, int port) {
|
||||
if (not port) {
|
||||
port = 8057;
|
||||
}
|
||||
this->ph = handler;
|
||||
|
||||
fossCordInternalsImpl* service;
|
||||
grpc::ServerBuilder builder;
|
||||
builder.AddListeningPort("0.0.0.0:" + std::to_string(port),
|
||||
grpc::InsecureServerCredentials());
|
||||
builder.RegisterService(service);
|
||||
|
||||
this->server = builder.BuildAndStart();
|
||||
|
||||
std::cout << "RPC stub listening on port " << port << std::endl;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#include <grpc++/grpc++.h>
|
||||
#include "protodefs/include/protos.grpc.pb.h"
|
||||
#include "rtcPeerHandler.hpp"
|
||||
|
||||
#ifndef RPCSTUB
|
||||
#define RPCSTUB
|
||||
class rpcStub{
|
||||
public:
|
||||
rpcStub(std::shared_ptr<rtcPeerHandler> peerHandler, int port);
|
||||
std::unique_ptr<grpc::Server> server;
|
||||
|
||||
private:
|
||||
std::shared_ptr<rtcPeerHandler> ph;
|
||||
};
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user