Static Webview - RTC - UDP - TCP - WSS
This commit is contained in:
136
Sources/main.cpp
136
Sources/main.cpp
@ -38,6 +38,10 @@
|
||||
#include "websocket.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_RTC
|
||||
#include "rtc_v8_bindings.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_BENCHMARK
|
||||
#include "BENCHMARK/websocket_benchmark.h"
|
||||
extern "C" void websocket_run_benchmark();
|
||||
@ -1325,9 +1329,7 @@ namespace {
|
||||
}
|
||||
|
||||
int runt_get_samples_per_second_fast(Local<Object> receiver) {
|
||||
int rate = kinc_a2_samples_per_second();
|
||||
kinc_log(KINC_LOG_LEVEL_INFO, "Samples per second: %d Hz.", rate);
|
||||
return rate;
|
||||
return kinc_a2_samples_per_second();
|
||||
}
|
||||
|
||||
void runt_get_samples_per_second(const FunctionCallbackInfo<Value> &args) {
|
||||
@ -2296,11 +2298,14 @@ namespace {
|
||||
HandleScope scope(args.GetIsolate());
|
||||
String::Utf8Value utf8_path(isolate, args[0]);
|
||||
|
||||
if (args.Length() < 2 || !args[1]->IsArrayBuffer()) return;
|
||||
|
||||
Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(args[1]);
|
||||
std::shared_ptr<BackingStore> content = buffer->GetBackingStore();
|
||||
|
||||
bool hasLengthArg = args.Length() > 2 && !args[2]->IsNullOrUndefined();
|
||||
int byteLength = hasLengthArg ? args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value() : (int)content->ByteLength();
|
||||
if (byteLength < 0) byteLength = 0;
|
||||
if (byteLength > (int)content->ByteLength()) byteLength = (int)content->ByteLength();
|
||||
|
||||
#ifdef KINC_WINDOWS
|
||||
@ -2314,6 +2319,112 @@ namespace {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void runt_file_write_bytes(const FunctionCallbackInfo<Value> &args) {
|
||||
HandleScope scope(args.GetIsolate());
|
||||
String::Utf8Value utf8_path(isolate, args[0]);
|
||||
|
||||
if (args.Length() < 2 || !args[1]->IsArrayBuffer()) return;
|
||||
|
||||
Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(args[1]);
|
||||
std::shared_ptr<BackingStore> content = buffer->GetBackingStore();
|
||||
|
||||
int64_t offset = 0;
|
||||
if (args.Length() > 2 && !args[2]->IsNullOrUndefined()) {
|
||||
offset = (int64_t)args[2]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value();
|
||||
}
|
||||
|
||||
bool hasLengthArg = args.Length() > 3 && !args[3]->IsNullOrUndefined();
|
||||
int byteLength = hasLengthArg ? args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value() : (int)content->ByteLength();
|
||||
if (byteLength < 0) byteLength = 0;
|
||||
if (byteLength > (int)content->ByteLength()) byteLength = (int)content->ByteLength();
|
||||
|
||||
#ifdef KINC_WINDOWS
|
||||
MultiByteToWideChar(CP_UTF8, 0, *utf8_path, -1, temp_wstring, 1024);
|
||||
FILE *file = _wfopen(temp_wstring, L"r+b");
|
||||
if (file == nullptr) file = _wfopen(temp_wstring, L"w+b");
|
||||
#else
|
||||
FILE *file = fopen(*utf8_path, "r+b");
|
||||
if (file == nullptr) file = fopen(*utf8_path, "w+b");
|
||||
#endif
|
||||
if (file == nullptr) {
|
||||
args.GetReturnValue().Set(Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
#ifdef KINC_WINDOWS
|
||||
_fseeki64(file, offset, SEEK_SET);
|
||||
#else
|
||||
fseeko(file, offset, SEEK_SET);
|
||||
#endif
|
||||
size_t written = fwrite(content->Data(), 1, byteLength, file);
|
||||
fclose(file);
|
||||
args.GetReturnValue().Set(Boolean::New(isolate, written == (size_t)byteLength));
|
||||
}
|
||||
|
||||
void runt_file_read_bytes(const FunctionCallbackInfo<Value> &args) {
|
||||
HandleScope scope(args.GetIsolate());
|
||||
String::Utf8Value utf8_path(isolate, args[0]);
|
||||
|
||||
int64_t offset = 0;
|
||||
if (args.Length() > 1 && !args[1]->IsNullOrUndefined()) {
|
||||
offset = (int64_t)args[1]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value();
|
||||
}
|
||||
int length = 0;
|
||||
if (args.Length() > 2 && !args[2]->IsNullOrUndefined()) {
|
||||
length = args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value();
|
||||
}
|
||||
if (offset < 0 || length <= 0) {
|
||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
Local<ArrayBuffer> buffer = ArrayBuffer::New(isolate, length);
|
||||
std::shared_ptr<BackingStore> content = buffer->GetBackingStore();
|
||||
memset(content->Data(), 0, length);
|
||||
|
||||
#ifdef KINC_WINDOWS
|
||||
MultiByteToWideChar(CP_UTF8, 0, *utf8_path, -1, temp_wstring, 1024);
|
||||
FILE *file = _wfopen(temp_wstring, L"rb");
|
||||
#else
|
||||
FILE *file = fopen(*utf8_path, "rb");
|
||||
#endif
|
||||
if (file != nullptr) {
|
||||
#ifdef KINC_WINDOWS
|
||||
_fseeki64(file, offset, SEEK_SET);
|
||||
#else
|
||||
fseeko(file, offset, SEEK_SET);
|
||||
#endif
|
||||
fread(content->Data(), 1, length, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
args.GetReturnValue().Set(buffer);
|
||||
}
|
||||
|
||||
void runt_file_size(const FunctionCallbackInfo<Value> &args) {
|
||||
HandleScope scope(args.GetIsolate());
|
||||
String::Utf8Value utf8_path(isolate, args[0]);
|
||||
int64_t size = -1;
|
||||
|
||||
#ifdef KINC_WINDOWS
|
||||
MultiByteToWideChar(CP_UTF8, 0, *utf8_path, -1, temp_wstring, 1024);
|
||||
FILE *file = _wfopen(temp_wstring, L"rb");
|
||||
#else
|
||||
FILE *file = fopen(*utf8_path, "rb");
|
||||
#endif
|
||||
if (file != nullptr) {
|
||||
#ifdef KINC_WINDOWS
|
||||
_fseeki64(file, 0, SEEK_END);
|
||||
size = _ftelli64(file);
|
||||
#else
|
||||
fseeko(file, 0, SEEK_END);
|
||||
size = (int64_t)ftello(file);
|
||||
#endif
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
args.GetReturnValue().Set(Number::New(isolate, (double)size));
|
||||
}
|
||||
|
||||
int sys_command(const char *cmd) {
|
||||
#ifdef KINC_WINDOWS
|
||||
int wlen = MultiByteToWideChar(CP_UTF8, 0, cmd, -1, NULL, 0);
|
||||
@ -2913,6 +3024,9 @@ namespace {
|
||||
SET_FUNCTION(runt, "beginFace", runt_begin_face);
|
||||
SET_FUNCTION(runt, "end", runt_end);
|
||||
SET_FUNCTION(runt, "fileSaveBytes", runt_file_save_bytes);
|
||||
SET_FUNCTION(runt, "fileWriteBytes", runt_file_write_bytes);
|
||||
SET_FUNCTION(runt, "fileReadBytes", runt_file_read_bytes);
|
||||
SET_FUNCTION(runt, "fileSize", runt_file_size);
|
||||
SET_FUNCTION(runt, "sysCommand", runt_sys_command);
|
||||
SET_FUNCTION(runt, "savePath", runt_save_path);
|
||||
SET_FUNCTION(runt, "getArgCount", runt_get_arg_count);
|
||||
@ -2934,6 +3048,10 @@ namespace {
|
||||
SET_FUNCTION(runt, "socketSetBlocking", v8_runt_socket_set_blocking);
|
||||
SET_FUNCTION(runt, "socketSelect", v8_runt_socket_select);
|
||||
SET_FUNCTION(runt, "socketIsConnected", v8_runt_socket_is_connected);
|
||||
SET_FUNCTION(runt, "udpCreate", v8_runt_udp_create);
|
||||
SET_FUNCTION(runt, "udpBind", v8_runt_udp_bind);
|
||||
SET_FUNCTION(runt, "udpSendTo", v8_runt_udp_sendto);
|
||||
SET_FUNCTION(runt, "udpRecvFrom", v8_runt_udp_recvfrom);
|
||||
#ifdef WITH_SSL
|
||||
SET_FUNCTION(runt, "socketEnableSsl", v8_runt_socket_enable_ssl);
|
||||
#endif
|
||||
@ -3214,6 +3332,9 @@ namespace {
|
||||
WebSocketWrapper::processEvents();
|
||||
HttpRequestWrapper::processEvents();
|
||||
#endif
|
||||
#ifdef WITH_RTC
|
||||
runt_rtc_process_events_native();
|
||||
#endif
|
||||
|
||||
execute_timers();
|
||||
EngineManager::AsyncEngine::instance().process_events();
|
||||
@ -3454,10 +3575,14 @@ namespace {
|
||||
if (!func->Call(context, context->Global(), 0, NULL).ToLocal(&result)) {
|
||||
handle_exception(&try_catch);
|
||||
}
|
||||
|
||||
|
||||
#ifdef WITH_RTC
|
||||
v8_runt_rtc_shutdown_all();
|
||||
#endif
|
||||
#ifdef WITH_NETWORKING
|
||||
WebSocketWrapper::cleanup();
|
||||
HttpRequestWrapper::cleanup();
|
||||
GlobalThreadPool::shutdown();
|
||||
#endif
|
||||
#ifdef WITH_VIEWPORT
|
||||
if (viewport_server_mode) {
|
||||
@ -4115,6 +4240,9 @@ int kickstart(int argc, char **argv) {
|
||||
bind_httprequest_class(isolate, global_context);
|
||||
WEBSOCKET_BIND_V8(isolate, global_context);
|
||||
#endif
|
||||
#ifdef WITH_RTC
|
||||
bind_rtc_bridge(isolate, global_context);
|
||||
#endif
|
||||
|
||||
start_runt(snapshot_found ? NULL : code);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user