mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-13 14:12:41 +01:00
Merge pull request #19 from ItsNewe/master
Set up the initial project structure
This commit is contained in:
commit
9c9c948ae9
127
.gitignore
vendored
127
.gitignore
vendored
@ -1,105 +1,38 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
# Executables
|
||||
*.o
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
# Protobuffer builds
|
||||
*.pb.cc
|
||||
*.pb.h
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
.DS_Store
|
||||
# Directories
|
||||
build/
|
||||
.vscode/
|
||||
|
32
CMakeLists.txt
Normal file
32
CMakeLists.txt
Normal file
@ -0,0 +1,32 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
14
README.md
14
README.md
@ -1,2 +1,16 @@
|
||||
# Fosscord-media
|
||||
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
|
||||
|
||||
### Building
|
||||
|
||||
```bash
|
||||
$ cmake
|
||||
$ cd build
|
||||
$ make
|
||||
```
|
||||
|
1
config.json
Normal file
1
config.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
36
src/main.cpp
Normal file
36
src/main.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
// $$$$$$\ $$\
|
||||
// $$ __$$\ $$ |
|
||||
// $$ / \__|$$$$$$\ $$$$$$$\ $$$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$ |
|
||||
// $$$$\ $$ __$$\ $$ _____|$$ _____|$$ _____|$$ __$$\ $$ __$$\ $$ __$$ |
|
||||
// $$ _| $$ / $$ |\$$$$$$\ \$$$$$$\ $$ / $$ / $$ |$$ | \__|$$ / $$ |
|
||||
// $$ | $$ | $$ | \____$$\ \____$$\ $$ | $$ | $$ |$$ | $$ | $$ |
|
||||
// $$ | \$$$$$$ |$$$$$$$ |$$$$$$$ |\$$$$$$$\ \$$$$$$ |$$ | \$$$$$$$ |
|
||||
// \__| \______/ \_______/ \_______/ \_______| \______/ \__| \_______|
|
||||
//
|
||||
//
|
||||
//
|
||||
// $$\ $$$$$$\
|
||||
// \__| $$ __$$\
|
||||
// $$\ $$\ $$$$$$\ $$\ $$$$$$$\ $$$$$$\ $$ / \__| $$$$$$\ $$$$$$\ $$\ $$\ $$$$$$\ $$$$$$\
|
||||
// \$$\ $$ |$$ __$$\ $$ |$$ _____|$$ __$$\ \$$$$$$\ $$ __$$\ $$ __$$\\$$\ $$ |$$ __$$\ $$ __$$\
|
||||
// \$$\$$ / $$ / $$ |$$ |$$ / $$$$$$$$ | \____$$\ $$$$$$$$ |$$ | \__|\$$\$$ / $$$$$$$$ |$$ | \__|
|
||||
// \$$$ / $$ | $$ |$$ |$$ | $$ ____|$$\ $$ |$$ ____|$$ | \$$$ / $$ ____|$$ |
|
||||
// \$ / \$$$$$$ |$$ |\$$$$$$$\ \$$$$$$$\ \$$$$$$ |\$$$$$$$\ $$ | \$ / \$$$$$$$\ $$ |
|
||||
// \_/ \______/ \__| \_______| \_______| \______/ \_______|\__| \_/ \_______|\__|
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include "rtcPeerHandler.hpp" //Handle peer connection requests
|
||||
#include "rpcStub.hpp" //Handle gRPC communications between the different fosscord elements
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
auto commsHandler = std::make_shared<rtcPeerHandler>();
|
||||
auto rpcHandler = std::unique_ptr<rpcStub>(new rpcStub(commsHandler, 8057));
|
||||
|
||||
std::cout << "Server created" << std::endl;
|
||||
|
||||
//rpcHandler->server->Wait(); //blocking, this will need to be threaded
|
||||
return 0;
|
||||
}
|
24
src/protodefs/protos.proto
Normal file
24
src/protodefs/protos.proto
Normal file
@ -0,0 +1,24 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package fosscordMedia;
|
||||
|
||||
service fosscordInternals{
|
||||
rpc vRequest(voiceRequest) returns (voiceAnswer) {}
|
||||
}
|
||||
|
||||
message voiceRequest{ //OP1 from gw
|
||||
uint64 userid = 1;
|
||||
uint64 guildid = 2;
|
||||
string ip=3;
|
||||
uint32 port=4;
|
||||
string protocol=5;
|
||||
string rtcConnectionId=6;
|
||||
}
|
||||
|
||||
message voiceAnswer{//OP2 and OP4 to gw
|
||||
string ip=1;
|
||||
uint32 port=3;
|
||||
repeated string modes=2;
|
||||
int32 ssrc=4;
|
||||
string audioCodec=5;
|
||||
}
|
32
src/rpcStub.cpp
Normal file
32
src/rpcStub.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#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;
|
||||
}
|
15
src/rpcStub.hpp
Normal file
15
src/rpcStub.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
#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
|
83
src/rtcPeerHandler.cpp
Normal file
83
src/rtcPeerHandler.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
#include "rtcPeerHandler.hpp"
|
||||
|
||||
rtcPeerHandler::rtcPeerHandler() {
|
||||
rtc::InitLogger(rtc::LogLevel::Verbose, NULL);
|
||||
}
|
||||
|
||||
void rtcPeerHandler::initiateConnection(std::string peerIP, int peerPort) {
|
||||
// Socket connection between client and server
|
||||
SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
sockaddr_in addr;
|
||||
addr.sin_addr.s_addr = inet_addr(peerIP.c_str());
|
||||
addr.sin_port = htons(peerPort);
|
||||
addr.sin_family = AF_INET;
|
||||
|
||||
rtc::Configuration conf;
|
||||
conf.enableIceTcp = false;
|
||||
conf.disableAutoNegotiation = false;
|
||||
|
||||
auto pc = std::make_shared<rtc::PeerConnection>(conf);
|
||||
|
||||
rtc::Description::Audio media("audio",
|
||||
rtc::Description::Direction::SendRecv);
|
||||
media.addOpusCodec(96);
|
||||
media.setBitrate(64);
|
||||
|
||||
auto track = pc->addTrack(media);
|
||||
|
||||
// auto session = std::make_shared<rtc::MediaHandler>();
|
||||
|
||||
// track->setMediaHandler(session);
|
||||
|
||||
rtc::Reliability rtcRel;
|
||||
rtcRel.unordered = true;
|
||||
rtcRel.type = rtc::Reliability::Type::Timed;
|
||||
rtcRel.rexmit = 500;
|
||||
|
||||
rtc::DataChannelInit rtcConf;
|
||||
rtcConf.reliability = rtcRel;
|
||||
rtcConf.negotiated = false;
|
||||
|
||||
pc->onStateChange([](rtc::PeerConnection::State state) {
|
||||
std::cout << "State: " << state << std::endl;
|
||||
if (state == rtc::PeerConnection::State::Disconnected ||
|
||||
state == rtc::PeerConnection::State::Failed ||
|
||||
state == rtc::PeerConnection::State::Closed) {
|
||||
// remove disconnected client
|
||||
}
|
||||
});
|
||||
|
||||
pc->onGatheringStateChange([](rtc::PeerConnection::GatheringState state) {
|
||||
std::cout << "Gathering State: " << state << std::endl;
|
||||
});
|
||||
|
||||
/*std::tuple<rtc::Track*, rtc::RtcpSrReporter*> addAudio(
|
||||
|
||||
const std::shared_ptr<rtc::PeerConnection> pc,
|
||||
const uint8_t payloadType, const uint32_t ssrc, const std::string cname,
|
||||
const std::string msid, const std::function<void(void)> onOpen) {
|
||||
auto audio = Description::Audio(cname);
|
||||
audio.addOpusCodec(payloadType);
|
||||
audio.addSSRC(ssrc, cname, msid, cname);
|
||||
auto track = pc->addTrack(audio);
|
||||
// create RTP configuration
|
||||
auto rtpConfig = make_shared<RtpPacketizationConfig>(
|
||||
ssrc, cname, payloadType, OpusRtpPacketizer::defaultClockRate);
|
||||
// create packetizer
|
||||
auto packetizer = make_shared<OpusRtpPacketizer>(rtpConfig);
|
||||
// create opus handler
|
||||
auto opusHandler = make_shared<OpusPacketizationHandler>(packetizer);
|
||||
|
||||
// add RTCP SR handler
|
||||
auto srReporter = make_shared<RtcpSrReporter>(rtpConfig);
|
||||
opusHandler->addToChain(srReporter);
|
||||
|
||||
// set handler
|
||||
track->setMediaHandler(opusHandler);
|
||||
track->onOpen(onOpen);
|
||||
auto trackData = make_shared<ClientTrackData>(track, srReporter);
|
||||
return trackData;
|
||||
}*/
|
||||
|
||||
pc->createDataChannel("Fosscord voice connection", rtcConf);
|
||||
}
|
32
src/rtcPeerHandler.hpp
Normal file
32
src/rtcPeerHandler.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "libdatachannel/rtc.hpp"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <array>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
typedef int SOCKET;
|
||||
#endif
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#ifndef RTCPEERHANDLER
|
||||
#define RTCPEERHANDLER
|
||||
class rtcPeerHandler{
|
||||
public:
|
||||
rtcPeerHandler();
|
||||
void initiateConnection(std::string peerIP, int peerPort);
|
||||
|
||||
struct client
|
||||
{
|
||||
std::shared_ptr<rtc::PeerConnection> pc;
|
||||
std::shared_ptr<rtc::DataChannel> dc;
|
||||
};
|
||||
|
||||
private:
|
||||
std::map<SOCKET, client> clients;
|
||||
};
|
||||
#endif
|
0
src/rtcServer.hpp
Normal file
0
src/rtcServer.hpp
Normal file
Loading…
Reference in New Issue
Block a user