Add Windows build support (#2)

This commit adds Windows build support by utilizing vcpkg to build
dependencies, and CMake for the build system.

These changes rely on vcpkg to be built and located in the VCPKG_ROOT
environment variable, along with having Visual Studio 2019 installed.
This commit is contained in:
Dillon Pentz 2020-06-24 18:44:52 +12:00 • committed by GitHub
parent 937c1a2322
commit 5b3fc5cdc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 112 additions and 28 deletions

View file

@ -1,5 +1,10 @@
#if defined(_WIN32)
#include <srt.h>
#pragma comment(lib, "ws2_32.lib")
#elif !defined(_WIN32)
#include <srt/srt.h>
#include <sys/syslog.h>
#endif
#include "node-srt.h"
Napi::FunctionReference NodeSRT::constructor;
@ -170,15 +175,19 @@ Napi::Value NodeSRT::Read(const Napi::CallbackInfo& info) {
Napi::Number chunkSize = info[1].As<Napi::Number>();
size_t bufferSize = uint32_t(chunkSize);
uint8_t buffer[bufferSize];
memset(&buffer, 0, bufferSize);
uint8_t *buffer = (uint8_t *)malloc(bufferSize);
memset(buffer, 0, bufferSize);
int nb = srt_recvmsg(socketValue, (char *)buffer, (int)bufferSize);
if (nb == SRT_ERROR) {
Napi::Error::New(env, srt_getlasterror_str()).ThrowAsJavaScriptException();
return Napi::Number::New(env, SRT_ERROR);
}
return Napi::Buffer<uint8_t>::Copy(env, buffer, nb);
Napi::Value nbuff = Napi::Buffer<uint8_t>::Copy(env, buffer, nb);
free(buffer);
return nbuff;
}
Napi::Value NodeSRT::Write(const Napi::CallbackInfo& info) {