Some updates
This commit is contained in:
parent
7c7e4a3d26
commit
814f529d99
2
github
2
github
@ -1 +1 @@
|
||||
Subproject commit b3e3903e67e8b0dff7d847a5a3690d49123ccf95
|
||||
Subproject commit e5b65f461c44e440473dde270213a0153021f6b0
|
@ -836,7 +836,7 @@ async function check_update(channel: string) {
|
||||
console.error(error);
|
||||
return;
|
||||
}
|
||||
if(version) {
|
||||
if(version && !update_question_open) {
|
||||
update_question_open = true;
|
||||
dialog.showMessageBox({
|
||||
buttons: ["update now", "remind me later"],
|
||||
|
@ -1,4 +1,3 @@
|
||||
import * as electron from "electron";
|
||||
import * as main_window from "./main_window";
|
||||
|
||||
export function handle_second_instance_call(argv: string[], work_dir: string) {
|
||||
@ -10,12 +9,13 @@ export function handle_second_instance_call(argv: string[], work_dir: string) {
|
||||
return;
|
||||
}
|
||||
main_window.main_window.focus();
|
||||
execute_connect_urls(original_args);
|
||||
}
|
||||
|
||||
{
|
||||
const connect_url = argv.find(e => e.startsWith("teaclient://"));
|
||||
if(connect_url) {
|
||||
console.log("Received connect url: %s", connect_url);
|
||||
main_window.main_window.webContents.send('connect', connect_url);
|
||||
}
|
||||
export function execute_connect_urls(argv: string[]) {
|
||||
const connect_urls = argv.filter(e => e.startsWith("teaclient://"));
|
||||
for(const url of connect_urls) {
|
||||
console.log("Received connect url: %s", url);
|
||||
main_window.main_window.webContents.send('connect', url);
|
||||
}
|
||||
}
|
@ -9,33 +9,8 @@ import MessageBoxOptions = electron.MessageBoxOptions;
|
||||
import {process_args, parse_arguments, Arguments} from "../shared/process-arguments";
|
||||
import {open as open_changelog} from "./app-updater/changelog";
|
||||
import * as crash_handler from "../crash_handler";
|
||||
import {open_preview} from "./url-preview";
|
||||
|
||||
async function execute_app() {
|
||||
/* legacy, will be removed soon */
|
||||
if(process_args.has_value("update-failed")) {
|
||||
const result = await electron.dialog.showMessageBox({
|
||||
type: "error",
|
||||
message: "Failed to execute update:\n" + process_args.value("update-failed"),
|
||||
title: "Update failed!",
|
||||
buttons: ["retry", "ignore"]
|
||||
} as MessageBoxOptions);
|
||||
if(result.response == 0)
|
||||
if(await app_updater.execute_graphical(await app_updater.selected_channel(), false))
|
||||
return;
|
||||
} else if(process_args.has_value("update-succeed")) {
|
||||
const result = await electron.dialog.showMessageBox({
|
||||
type: "info",
|
||||
message: "Update successfully installed!\nShould we launch TeaClient?",
|
||||
title: "Update succeeded!",
|
||||
buttons: ["yes", "no"]
|
||||
} as MessageBoxOptions);
|
||||
if(result.response != 0) {
|
||||
electron.app.exit(0);
|
||||
return; //Not really required here!
|
||||
}
|
||||
}
|
||||
|
||||
if(process_args.has_value("update-execute")) {
|
||||
console.log("Executing update " + process_args.value("update-execute"));
|
||||
await app_updater.execute_update(process_args.value("update-execute"), callback => {
|
||||
@ -65,8 +40,8 @@ async function execute_app() {
|
||||
}
|
||||
}
|
||||
data.parse_success = true;
|
||||
} catch($) {
|
||||
console.error($);
|
||||
} catch(error) {
|
||||
console.warn("Failed to parse update response data: %o", error);
|
||||
}
|
||||
console.log("Update success: %o. Update data: %o", success, data);
|
||||
|
||||
@ -140,7 +115,7 @@ async function execute_app() {
|
||||
callback: async () => true
|
||||
});
|
||||
|
||||
const result = await electron.dialog.showMessageBox({
|
||||
const result = await electron.dialog.showMessageBox(null, {
|
||||
type: type,
|
||||
message: message,
|
||||
title: title,
|
||||
|
@ -6,11 +6,15 @@ import BrowserWindow = electron.BrowserWindow;
|
||||
|
||||
import {open as open_changelog} from "../app-updater/changelog";
|
||||
import * as updater from "../app-updater";
|
||||
import {execute_connect_urls} from "../instance_handler";
|
||||
import {process_args} from "../../shared/process-arguments";
|
||||
|
||||
ipcMain.on('basic-action', (event, action, ...args: any[]) => {
|
||||
const window = BrowserWindow.fromWebContents(event.sender);
|
||||
|
||||
if(action === "open-changelog") {
|
||||
if(action == "parse-connect-arguments") {
|
||||
execute_connect_urls(process_args["_"] || []);
|
||||
} else if(action === "open-changelog") {
|
||||
open_changelog();
|
||||
} else if(action === "check-native-update") {
|
||||
updater.selected_channel().then(channel => updater.execute_graphical(channel, true));
|
||||
|
@ -1,9 +1,37 @@
|
||||
window["require_setup"](module);
|
||||
|
||||
import * as electron from "electron";
|
||||
const remote = electron.remote;
|
||||
|
||||
electron.ipcRenderer.on('connect', (event, url) => {
|
||||
console.log(tr("Received connect event to %s"), url);
|
||||
console.error(tr("Dropping connect event (Currently not supported)"));
|
||||
});
|
||||
electron.ipcRenderer.on('connect', (event, url) => handle_native_connect_request(url));
|
||||
|
||||
function handle_native_connect_request(url_string: string) {
|
||||
console.log(tr("Received connect event to %s"), url_string);
|
||||
|
||||
|
||||
if(!url_string.toLowerCase().startsWith("teaclient://")) {
|
||||
createErrorModal(tr("Failed to parse connect URL"), tra("Failed to parse connect URL (Unknown protocol).{:br:}URL: {}", url_string)).open();
|
||||
return;
|
||||
}
|
||||
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL("https://" + url_string.substring(10));
|
||||
} catch(error) {
|
||||
createErrorModal(tr("Failed to parse connect URL"), tra("Failed to parse connect URL.{:br:}URL: {}", url_string)).open();
|
||||
return;
|
||||
}
|
||||
|
||||
let connection = server_connections.active_connection_handler();
|
||||
if(connection.connected)
|
||||
connection = server_connections.spawn_server_connection_handler();
|
||||
|
||||
handle_connect_request({
|
||||
address: url.host,
|
||||
password: {
|
||||
value: url.password,
|
||||
hashed: (url.searchParams.get("password_raw") || "0") == "0"
|
||||
},
|
||||
profile: url.searchParams.get("profile"),
|
||||
username: url.searchParams.get("username")
|
||||
}, connection)
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
/// <reference path="imports/imports_shared.d.ts" />
|
||||
|
||||
import {Arguments, process_args, parse_arguments} from "../shared/process-arguments";
|
||||
import {Arguments, parse_arguments, process_args} from "../shared/process-arguments";
|
||||
import * as electron from "electron";
|
||||
import {remote} from "electron";
|
||||
import * as crash_handler from "../crash_handler";
|
||||
import * as electron from "electron";
|
||||
import * as path from "path";
|
||||
import * as os from "os";
|
||||
import ipcRenderer = electron.ipcRenderer;
|
||||
|
||||
/* first of all setup crash handler */
|
||||
{
|
||||
@ -112,6 +113,14 @@ export const initialize = async () => {
|
||||
},
|
||||
priority: 100
|
||||
});
|
||||
|
||||
loader.register_task(loader.Stage.LOADED, {
|
||||
name: "argv connect",
|
||||
function: async () => {
|
||||
ipcRenderer.send('basic-action', "parse-connect-arguments");
|
||||
},
|
||||
priority: 0
|
||||
})
|
||||
};
|
||||
|
||||
const jquery_initialize = async () => {
|
||||
|
@ -20,11 +20,10 @@ namespace _ppt {
|
||||
key_alt: nevent.key_alt,
|
||||
key_windows: nevent.key_windows
|
||||
} as any;
|
||||
|
||||
//console.debug("Trigger key event %o", key_event);
|
||||
//console.debug("Trigger key event %o", type);
|
||||
|
||||
for (const listener of key_listener)
|
||||
listener(event);
|
||||
listener && listener(event);
|
||||
}
|
||||
|
||||
function native_keyhook(event: NKeyEvent) {
|
||||
@ -36,6 +35,8 @@ namespace _ppt {
|
||||
listener_key(ppt.EventType.KEY_RELEASE, event);
|
||||
else if(event.type == 2)
|
||||
listener_key(ppt.EventType.KEY_TYPED, event);
|
||||
else
|
||||
console.warn(tr("Received unknown native event: %o"), event);
|
||||
}
|
||||
|
||||
export async function initialize() : Promise<void> {
|
||||
@ -70,20 +71,6 @@ namespace _ppt {
|
||||
|
||||
let key_hooks_active: ppt.KeyHook[] = [];
|
||||
|
||||
function listener_blur() {
|
||||
current_state.special[ppt.SpecialKey.ALT] = false;
|
||||
current_state.special[ppt.SpecialKey.CTRL] = false;
|
||||
current_state.special[ppt.SpecialKey.SHIFT] = false;
|
||||
current_state.special[ppt.SpecialKey.WINDOWS] = false;
|
||||
|
||||
for(const code of Object.keys(current_state.keys))
|
||||
delete current_state[code];
|
||||
|
||||
for(const hook of key_hooks_active)
|
||||
hook.callback_release();
|
||||
key_hooks_active = [];
|
||||
}
|
||||
|
||||
function listener_hook(event: ppt.KeyEvent) {
|
||||
if(event.type == ppt.EventType.KEY_TYPED)
|
||||
return;
|
||||
@ -142,7 +129,7 @@ namespace _ppt {
|
||||
|
||||
export function key_pressed(code: string | ppt.SpecialKey) : boolean {
|
||||
if(typeof(code) === 'string')
|
||||
return current_state.code == code;
|
||||
return typeof(current_state[code]) === "object";
|
||||
return current_state.special[code];
|
||||
}
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ else()
|
||||
endif()
|
||||
include_directories(${NODEJS_INCLUDE_DIRS})
|
||||
|
||||
add_subdirectory(dist/ext_nan/)
|
||||
function(build_update_installer)
|
||||
add_subdirectory(updater)
|
||||
endfunction()
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include <memory>
|
||||
#include "CeltCodec.h"
|
||||
#include "NativeCodec.h"
|
||||
#include "NanException.h"
|
||||
#include "NanEventCallback.h"
|
||||
#include "include/NanException.h"
|
||||
#include "include/NanEventCallback.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "OpusCodec.h"
|
||||
#include "SpeexCodec.h"
|
||||
#include "CeltCodec.h"
|
||||
#include "NanException.h"
|
||||
#include "include/NanException.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include <memory>
|
||||
#include "OpusCodec.h"
|
||||
#include "NativeCodec.h"
|
||||
#include "NanException.h"
|
||||
#include "NanEventCallback.h"
|
||||
#include "include/NanException.h"
|
||||
#include "include/NanEventCallback.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include <memory>
|
||||
#include "SpeexCodec.h"
|
||||
#include "NativeCodec.h"
|
||||
#include "NanException.h"
|
||||
#include "NanEventCallback.h"
|
||||
#include "include/NanException.h"
|
||||
#include "include/NanEventCallback.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "NanException.h"
|
||||
#include "NanEventCallback.h"
|
||||
#include "include/NanException.h"
|
||||
#include "include/NanEventCallback.h"
|
||||
#include "src/crash_handler.h"
|
||||
|
||||
#include <thread>
|
||||
|
39
native/dist/ext_nan/include/NanGet.h
vendored
Normal file
39
native/dist/ext_nan/include/NanGet.h
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "./NanStrings.h"
|
||||
#include <v8.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Nan {
|
||||
inline v8::MaybeLocal<v8::Object> GetObject(v8::Local<v8::Object> object, v8::Local<v8::Value> key) {
|
||||
auto result = Nan::Get(object, key);
|
||||
if(result.IsEmpty())
|
||||
return v8::Local<v8::Object>{};
|
||||
|
||||
return result.ToLocalChecked()->ToObject(v8::Isolate::GetCurrent()->GetCurrentContext());
|
||||
}
|
||||
|
||||
inline v8::MaybeLocal<v8::Value> Get(v8::Local<v8::Object> object, const std::string_view& key) {
|
||||
return Nan::Get(object, Nan::LocalString(key));
|
||||
}
|
||||
|
||||
template <class T, typename K, typename std::enable_if<!std::is_same<v8::Value, T>::value, int>::type * = nullptr>
|
||||
inline v8::MaybeLocal<T> Get(v8::Local<v8::Object> object, K key) {
|
||||
MaybeLocal<v8::Value> result{Nan::Get(object, key)};
|
||||
if(result.IsEmpty())
|
||||
return v8::Local<T>{};
|
||||
|
||||
return result.ToLocalChecked().As<T>();
|
||||
}
|
||||
|
||||
template <class T, typename K>
|
||||
inline v8::Local<T> GetLocal(v8::Local<v8::Object> object, K key) {
|
||||
return Nan::Get<T, K>(object, key).FromMaybe(v8::Local<T>{});
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline v8::MaybeLocal<v8::String> GetString(v8::Local<v8::Object> object, T key) { return Get<v8::String>(object, key); }
|
||||
|
||||
template <typename T>
|
||||
inline v8::Local<v8::String> GetStringLocal(v8::Local<v8::Object> object, T key) { return GetLocal<v8::String>(object, key); }
|
||||
}
|
69
native/dist/ext_nan/include/NanStrings.h
vendored
69
native/dist/ext_nan/include/NanStrings.h
vendored
@ -1,13 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <nan.h>
|
||||
#include <string_view>
|
||||
#include <v8.h>
|
||||
|
||||
namespace Nan {
|
||||
/* UTF-8 Helpers */
|
||||
inline v8::Local<v8::String> StringUTF8(std::string_view buffer) {
|
||||
Nan::EscapableHandleScope scope{};
|
||||
auto data = v8::String::NewFromUtf8(Nan::GetCurrentContext()->GetIsolate(), buffer.data(), v8::NewStringType::kNormal, buffer.length());
|
||||
inline v8::Local<v8::String> LocalStringUTF8(std::string_view buffer) {
|
||||
auto isolate = Nan::GetCurrentContext()->GetIsolate();
|
||||
v8::EscapableHandleScope scope{isolate};
|
||||
auto data = v8::String::NewFromUtf8(isolate, buffer.data(), v8::NewStringType::kNormal, buffer.length());
|
||||
|
||||
v8::Local<v8::String> response{};
|
||||
if(!data.ToLocal(&response))
|
||||
@ -15,39 +17,50 @@ namespace Nan {
|
||||
return scope.Escape(response);
|
||||
}
|
||||
|
||||
template <size_t S>
|
||||
inline v8::Local<v8::String> StringUTF8(const char (&buffer)[S]) {
|
||||
return Nan::StringUTF8(buffer, S);
|
||||
inline v8::Local<v8::String> LocalStringUTF8(const std::string& buffer) {
|
||||
return LocalStringUTF8(std::string_view{buffer});
|
||||
}
|
||||
|
||||
inline v8::Local<v8::String> StringUTF8(const char* buffer, size_t length) {
|
||||
return Nan::StringUTF8(std::string_view{buffer, length});
|
||||
inline v8::Local<v8::String> LocalStringUTF8(const char* buffer, size_t length) {
|
||||
return Nan::LocalStringUTF8(std::string_view{buffer, length});
|
||||
}
|
||||
|
||||
template <size_t S>
|
||||
inline v8::Local<v8::String> LocalStringUTF8(const char (&buffer)[S]) {
|
||||
return Nan::LocalStringUTF8((const char*) buffer, S - 1);
|
||||
}
|
||||
|
||||
/* Latin1 Helpers */
|
||||
inline v8::Local<v8::String> String(std::string_view buffer) {
|
||||
Nan::EscapableHandleScope scope{};
|
||||
auto data = v8::String::NewFromOneByte(Nan::GetCurrentContext()->GetIsolate(), (uint8_t*) buffer.data(), v8::NewStringType::kNormal, buffer.length());
|
||||
inline v8::Local<v8::String> LocalString(std::string_view buffer) {
|
||||
auto isolate = Nan::GetCurrentContext()->GetIsolate();
|
||||
//v8::EscapableHandleScope scope{isolate};
|
||||
auto data = v8::String::NewFromOneByte(isolate, (uint8_t*) buffer.data(), v8::NewStringType::kNormal, buffer.length());
|
||||
|
||||
v8::Local<v8::String> response{};
|
||||
if(!data.ToLocal(&response))
|
||||
throw std::bad_alloc{};
|
||||
return scope.Escape(response);
|
||||
return response;
|
||||
//eturn scope.Escape(response);
|
||||
}
|
||||
|
||||
inline v8::Local<v8::String> LocalString(const std::string& buffer) {
|
||||
return LocalString(std::string_view{buffer});
|
||||
}
|
||||
|
||||
inline v8::Local<v8::String> LocalString(const char* buffer, size_t length) {
|
||||
return Nan::LocalString(std::string_view{buffer, length});
|
||||
}
|
||||
|
||||
template <size_t S>
|
||||
inline v8::Local<v8::String> String(const char (&buffer)[S]) {
|
||||
return Nan::StringUTF8(buffer, S);
|
||||
}
|
||||
|
||||
inline v8::Local<v8::String> String(const char* buffer, size_t length) {
|
||||
return Nan::StringUTF8(std::string_view{buffer, length});
|
||||
inline v8::Local<v8::String> LocalString(const char (&buffer)[S]) {
|
||||
return Nan::LocalString((const char*) buffer, S - 1);
|
||||
}
|
||||
|
||||
/* Wide char helpers */
|
||||
inline v8::Local<v8::String> String(std::wstring_view buffer) {
|
||||
Nan::EscapableHandleScope scope{};
|
||||
auto data = v8::String::NewFromTwoByte(Nan::GetCurrentContext()->GetIsolate(), (uint16_t*) buffer.data(), v8::NewStringType::kNormal, buffer.length());
|
||||
inline v8::Local<v8::String> LocalString(std::wstring_view buffer) {
|
||||
auto isolate = Nan::GetCurrentContext()->GetIsolate();
|
||||
v8::EscapableHandleScope scope{isolate};
|
||||
auto data = v8::String::NewFromTwoByte(isolate, (uint16_t*) buffer.data(), v8::NewStringType::kNormal, buffer.length());
|
||||
|
||||
v8::Local<v8::String> response{};
|
||||
if(!data.ToLocal(&response))
|
||||
@ -55,12 +68,16 @@ namespace Nan {
|
||||
return scope.Escape(response);
|
||||
}
|
||||
|
||||
template <size_t S>
|
||||
inline v8::Local<v8::String> String(const wchar_t (&buffer)[S]) {
|
||||
return Nan::String(buffer, S);
|
||||
inline v8::Local<v8::String> LocalString(const std::wstring& buffer) {
|
||||
return LocalString(std::wstring_view{buffer});
|
||||
}
|
||||
|
||||
inline v8::Local<v8::String> String(const wchar_t* buffer, size_t length) {
|
||||
return Nan::String(std::wstring_view{buffer, length});
|
||||
template <size_t S>
|
||||
inline v8::Local<v8::String> LocalString(const wchar_t (&buffer)[S]) {
|
||||
return Nan::LocalString(buffer, S - 1);
|
||||
}
|
||||
|
||||
inline v8::Local<v8::String> LocalString(const wchar_t* buffer, size_t length) {
|
||||
return Nan::LocalString(std::wstring_view{buffer, length});
|
||||
}
|
||||
}
|
1
native/dist/ext_nan/test/main.cpp
vendored
1
native/dist/ext_nan/test/main.cpp
vendored
@ -1,6 +1,7 @@
|
||||
#include "include/NanEventCallback.h"
|
||||
#include "include/NanException.h"
|
||||
#include "include/NanStrings.h"
|
||||
#include "include/NanGet.h"
|
||||
|
||||
int main() {
|
||||
auto str = Nan::StringUTF8("Hello World");
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "NanException.h"
|
||||
#include "NanEventCallback.h"
|
||||
#include "include/NanException.h"
|
||||
#include "include/NanEventCallback.h"
|
||||
|
||||
std::unique_ptr<tc::dns::Resolver> resolver{nullptr};
|
||||
|
||||
|
@ -3,11 +3,12 @@
|
||||
#include <node.h>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <include/NanStrings.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "NanException.h"
|
||||
#include "NanEventCallback.h"
|
||||
#include "include/NanException.h"
|
||||
#include "include/NanEventCallback.h"
|
||||
#include "src/KeyboardHook.h"
|
||||
|
||||
|
||||
@ -22,19 +23,19 @@ inline v8::Local<v8::Object> event_to_object(const std::shared_ptr<KeyboardHook:
|
||||
Nan::EscapableHandleScope scope;
|
||||
|
||||
auto object = Nan::New<v8::Object>();
|
||||
object->Set(Nan::New<v8::String>("type").ToLocalChecked(), Nan::New<v8::Number>(event->type));
|
||||
object->Set(Nan::New<v8::String>("key_code").ToLocalChecked(), Nan::New<v8::String>(event->code).ToLocalChecked());
|
||||
Nan::Set(object, Nan::LocalString("type"), Nan::New<v8::Number>(event->type));
|
||||
Nan::Set(object, Nan::LocalString("key_code"), Nan::New<v8::String>(event->code).ToLocalChecked());
|
||||
|
||||
object->Set(Nan::New<v8::String>("key_shift").ToLocalChecked(), Nan::New<v8::Boolean>(event->key_shift));
|
||||
object->Set(Nan::New<v8::String>("key_alt").ToLocalChecked(), Nan::New<v8::Boolean>(event->key_alt));
|
||||
object->Set(Nan::New<v8::String>("key_windows").ToLocalChecked(), Nan::New<v8::Boolean>(event->key_windows));
|
||||
object->Set(Nan::New<v8::String>("key_ctrl").ToLocalChecked(), Nan::New<v8::Boolean>(event->key_ctrl));
|
||||
Nan::Set(object, Nan::LocalString("key_shift"), Nan::New<v8::Boolean>(event->key_shift));
|
||||
Nan::Set(object, Nan::LocalString("key_alt"), Nan::New<v8::Boolean>(event->key_alt));
|
||||
Nan::Set(object, Nan::LocalString("key_windows"), Nan::New<v8::Boolean>(event->key_windows));
|
||||
Nan::Set(object, Nan::LocalString("key_ctrl"), Nan::New<v8::Boolean>(event->key_ctrl));
|
||||
|
||||
return scope.Escape(object);
|
||||
}
|
||||
|
||||
NAN_METHOD(RegisterCallback) {
|
||||
if(!info[0]->IsFunction()) {
|
||||
if(info.Length() < 1 || !info[0]->IsFunction()) {
|
||||
NAN_THROW_EXCEPTION(Error, "argument must be a function!");
|
||||
return;
|
||||
}
|
||||
@ -47,7 +48,7 @@ NAN_METHOD(RegisterCallback) {
|
||||
}
|
||||
|
||||
NAN_METHOD(UnregisterCallback) {
|
||||
if(!info[0]->IsFunction()) {
|
||||
if(info.Length() < 1 || !info[0]->IsFunction()) {
|
||||
NAN_THROW_EXCEPTION(Error, "argument must be a function!");
|
||||
return;
|
||||
}
|
||||
@ -94,7 +95,8 @@ NAN_MODULE_INIT(init) {
|
||||
v8::Local<v8::Value> args[] = {
|
||||
object
|
||||
};
|
||||
callback->Call(1, args);
|
||||
|
||||
Nan::Call(*callback, Nan::Undefined().As<v8::Object>(), 1, args);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -125,6 +125,7 @@ set(REQUIRED_LIBRARIES
|
||||
${ed25519_LIBRARIES_STATIC}
|
||||
|
||||
spdlog::spdlog
|
||||
Nan::Helpers
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
@ -68,7 +68,7 @@ void AudioConsumerWrapper::do_wrap(const v8::Local<v8::Object> &obj) {
|
||||
Nan::HandleScope scope;
|
||||
|
||||
auto handle = this->handle();
|
||||
v8::Local<v8::Value> callback_function = handle->Get(Nan::New<v8::String>("callback_data").ToLocalChecked());
|
||||
v8::Local<v8::Value> callback_function = Nan::Get(handle, Nan::New<v8::String>("callback_data").ToLocalChecked()).FromMaybe(v8::Local<v8::Value>{});
|
||||
if(callback_function.IsEmpty() || callback_function->IsNullOrUndefined() || !callback_function->IsFunction()) {
|
||||
lock_guard lock(this->_data_lock);
|
||||
this->_data_entries.clear();
|
||||
@ -100,7 +100,7 @@ void AudioConsumerWrapper::do_wrap(const v8::Local<v8::Object> &obj) {
|
||||
Nan::HandleScope scope;
|
||||
|
||||
auto handle = this->handle();
|
||||
v8::Local<v8::Value> callback_function = handle->Get(Nan::New<v8::String>("callback_ended").ToLocalChecked());
|
||||
v8::Local<v8::Value> callback_function = Nan::Get(handle, Nan::New<v8::String>("callback_ended").ToLocalChecked()).FromMaybe(v8::Local<v8::Value>{});
|
||||
if(callback_function.IsEmpty() || callback_function->IsNullOrUndefined() || !callback_function->IsFunction())
|
||||
return;
|
||||
callback_function.As<v8::Function>()->Call(Nan::GetCurrentContext(), Nan::Undefined(), 0, nullptr);
|
||||
@ -110,7 +110,7 @@ void AudioConsumerWrapper::do_wrap(const v8::Local<v8::Object> &obj) {
|
||||
Nan::HandleScope scope;
|
||||
|
||||
auto handle = this->handle();
|
||||
v8::Local<v8::Value> callback_function = handle->Get(Nan::New<v8::String>("callback_started").ToLocalChecked());
|
||||
v8::Local<v8::Value> callback_function = Nan::Get(handle, Nan::New<v8::String>("callback_started").ToLocalChecked()).FromMaybe(v8::Local<v8::Value>{});
|
||||
if(callback_function.IsEmpty() || callback_function->IsNullOrUndefined() || !callback_function->IsFunction())
|
||||
return;
|
||||
callback_function.As<v8::Function>()->Call(Nan::GetCurrentContext(), Nan::Undefined(), 0, nullptr);
|
||||
@ -240,7 +240,7 @@ NAN_METHOD(AudioConsumerWrapper::_get_filters) {
|
||||
auto result = Nan::New<v8::Array>(filters.size());
|
||||
|
||||
for(size_t index = 0; index < filters.size(); index++)
|
||||
result->Set(index, filters[index]->handle());
|
||||
Nan::Set(result, index, filters[index]->handle());
|
||||
|
||||
info.GetReturnValue().Set(result);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <nan.h>
|
||||
#include <mutex>
|
||||
#include <deque>
|
||||
#include <NanEventCallback.h>
|
||||
#include <include/NanEventCallback.h>
|
||||
|
||||
namespace tc {
|
||||
namespace audio {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <nan.h>
|
||||
#include <NanEventCallback.h>
|
||||
#include <include/NanEventCallback.h>
|
||||
|
||||
namespace tc {
|
||||
namespace audio {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <nan.h>
|
||||
#include <NanEventCallback.h>
|
||||
#include <include/NanEventCallback.h>
|
||||
|
||||
namespace tc {
|
||||
namespace audio {
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <misc/base64.h>
|
||||
#include <misc/digest.h>
|
||||
#include <include/NanStrings.h>
|
||||
#include "AudioPlayer.h"
|
||||
#include "../AudioOutput.h"
|
||||
#include "../AudioDevice.h"
|
||||
@ -28,7 +29,7 @@ NAN_METHOD(audio::available_devices) {
|
||||
auto device_info = Nan::New<v8::Object>();
|
||||
auto device = devices[index];
|
||||
|
||||
Nan::Set(device_info, Nan::New<v8::String>("name").ToLocalChecked(), Nan::New<v8::String>(device->name).ToLocalChecked());
|
||||
Nan::Set(device_info, Nan::LocalString("name"), Nan::LocalString(device->name));
|
||||
Nan::Set(device_info, Nan::New<v8::String>("driver").ToLocalChecked(), Nan::New<v8::String>(device->driver).ToLocalChecked());
|
||||
Nan::Set(device_info, Nan::New<v8::String>("device_id").ToLocalChecked(), Nan::New<v8::String>(base64::encode(digest::sha1(device->name + device->driver))).ToLocalChecked());
|
||||
|
||||
@ -40,7 +41,7 @@ NAN_METHOD(audio::available_devices) {
|
||||
|
||||
Nan::Set(device_info, Nan::New<v8::String>("device_index").ToLocalChecked(), Nan::New<v8::Number>(device->device_id));
|
||||
|
||||
result->Set(index, device_info);
|
||||
Nan::Set(result, index, device_info);
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(result);
|
||||
|
@ -227,7 +227,7 @@ NAN_METHOD(AudioRecorderWrapper::_get_consumers) {
|
||||
auto result = Nan::New<v8::Array>(consumers.size());
|
||||
|
||||
for(size_t index = 0; index < consumers.size(); index++)
|
||||
result->Set(index, consumers[index]->handle());
|
||||
Nan::Set(result, index, consumers[index]->handle());
|
||||
|
||||
info.GetReturnValue().Set(result);
|
||||
}
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <misc/digest.h>
|
||||
|
||||
#include "logger.h"
|
||||
#include "NanException.h"
|
||||
#include "NanEventCallback.h"
|
||||
#include "include/NanException.h"
|
||||
#include "include/NanEventCallback.h"
|
||||
#include "connection/ServerConnection.h"
|
||||
#include "connection/audio/VoiceConnection.h"
|
||||
#include "connection/audio/VoiceClient.h"
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <misc/endianness.h>
|
||||
#include <misc/strobf.h>
|
||||
#include <iomanip>
|
||||
#include <include/NanGet.h>
|
||||
|
||||
//#define FUZZ_VOICE
|
||||
//#define SHUFFLE_VOICE
|
||||
@ -404,15 +405,15 @@ NAN_METHOD(ServerConnection::send_command) {
|
||||
|
||||
ts::Command cmd(*Nan::Utf8String(command));
|
||||
for(size_t index = 0; index < arguments->Length(); index++) {
|
||||
auto object = arguments->Get((uint32_t) index);
|
||||
if(!object->IsObject()) {
|
||||
auto object = Nan::GetLocal<v8::Object>(arguments, (uint32_t) index);
|
||||
if(object.IsEmpty() || !object->IsObject()) {
|
||||
Nan::ThrowError(Nan::New<v8::String>("invalid parameter (" + to_string(index) + ")").ToLocalChecked());
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Array> properties = object->ToObject(Nan::GetCurrentContext()).ToLocalChecked()->GetOwnPropertyNames(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
for(uint32_t i = 0; i < properties->Length(); i++) {
|
||||
auto key = properties->Get(i)->ToString(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
auto key = Nan::GetStringLocal(properties, i);
|
||||
auto value = object->ToObject(Nan::GetCurrentContext()).ToLocalChecked()->Get(Nan::GetCurrentContext(), key).ToLocalChecked();
|
||||
|
||||
string key_string = *Nan::Utf8String(key);
|
||||
@ -435,8 +436,8 @@ NAN_METHOD(ServerConnection::send_command) {
|
||||
|
||||
|
||||
for(size_t index = 0; index < switches->Length(); index++) {
|
||||
auto object = switches->Get((uint32_t) index);
|
||||
if(!object->IsString()) {
|
||||
auto object = Nan::GetStringLocal(switches, (uint32_t) index);
|
||||
if(object.IsEmpty()) {
|
||||
Nan::ThrowError(Nan::New<v8::String>("invalid switch (" + to_string(index) + ")").ToLocalChecked());
|
||||
return;
|
||||
}
|
||||
@ -646,7 +647,7 @@ void ServerConnection::_execute_callback_commands() {
|
||||
for(const auto& key : bulk.keys())
|
||||
Nan::Set(object, Nan::New<v8::String>(key).ToLocalChecked(), Nan::New<v8::String>(bulk[key].string()).ToLocalChecked());
|
||||
|
||||
parameters->Set((uint32_t) index, object);
|
||||
Nan::Set(parameters, (uint32_t) index, object);
|
||||
}
|
||||
arguments[1] = parameters;
|
||||
|
||||
@ -654,7 +655,7 @@ void ServerConnection::_execute_callback_commands() {
|
||||
auto switched = Nan::New<v8::Array>((int) next_command->parms().size());
|
||||
for(size_t index = 0; index < next_command->parms().size(); index++) {
|
||||
auto& key = next_command->parms()[index];
|
||||
parameters->Set((uint32_t) index, Nan::New<v8::String>(key).ToLocalChecked());
|
||||
Nan::Set(parameters, (uint32_t) index, Nan::New<v8::String>(key).ToLocalChecked());
|
||||
}
|
||||
arguments[2] = switched;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <nan.h>
|
||||
#include <NanEventCallback.h>
|
||||
#include <include/NanEventCallback.h>
|
||||
#include <condition_variable>
|
||||
#include <pipes/buffer.h>
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <nan.h>
|
||||
#include <NanEventCallback.h>
|
||||
#include <include/NanEventCallback.h>
|
||||
#include <functional>
|
||||
#include <pipes/buffer.h>
|
||||
#include "../../audio/AudioResampler.h"
|
||||
|
@ -8,6 +8,8 @@
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#include <misc/net.h>
|
||||
#include <include/NanGet.h>
|
||||
|
||||
#ifndef IPPROTO_TCP
|
||||
#define IPPROTO_TCP (0)
|
||||
#endif
|
||||
@ -616,11 +618,11 @@ NAN_METHOD(JSTransfer::NewInstance) {
|
||||
* object: HandledTransferObject;
|
||||
*/
|
||||
auto options = info[0]->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
v8::Local<v8::String> key = options->Get(Nan::New<v8::String>("transfer_key").ToLocalChecked()).As<v8::String>();
|
||||
v8::Local<v8::Number> client_transfer_id = options->Get(Nan::New<v8::String>("client_transfer_id").ToLocalChecked()).As<v8::Number>();
|
||||
v8::Local<v8::Number> server_transfer_id = options->Get(Nan::New<v8::String>("server_transfer_id").ToLocalChecked()).As<v8::Number>();
|
||||
v8::Local<v8::String> remote_address = options->Get(Nan::New<v8::String>("remote_address").ToLocalChecked()).As<v8::String>();
|
||||
v8::Local<v8::Number> remote_port = options->Get(Nan::New<v8::String>("remote_port").ToLocalChecked()).As<v8::Number>();
|
||||
auto key = Nan::GetStringLocal(options, "transfer_key");
|
||||
v8::Local<v8::Number> client_transfer_id = Nan::GetLocal<v8::Number>(options, "client_transfer_id");
|
||||
v8::Local<v8::Number> server_transfer_id = Nan::GetLocal<v8::Number>(options, "server_transfer_id");
|
||||
v8::Local<v8::String> remote_address = Nan::GetStringLocal(options, "remote_address");
|
||||
v8::Local<v8::Number> remote_port = Nan::GetLocal<v8::Number>(options, "remote_port");
|
||||
|
||||
if(
|
||||
key.IsEmpty() || !key->IsString() ||
|
||||
@ -633,7 +635,7 @@ NAN_METHOD(JSTransfer::NewInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto wrapped_options = options->Get(Nan::New<v8::String>("object").ToLocalChecked()).As<v8::Object>();
|
||||
auto wrapped_options = Nan::GetLocal<v8::Object>(options, "object");
|
||||
if(!TransferObjectWrap::is_wrap(wrapped_options)) {
|
||||
Nan::ThrowError("invalid handle");
|
||||
return;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#if NODEJS_API
|
||||
#include <nan.h>
|
||||
#include <NanEventCallback.h>
|
||||
#include <include/NanEventCallback.h>
|
||||
#endif
|
||||
|
||||
namespace tc {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <NanGet.h>
|
||||
#include "logger.h"
|
||||
|
||||
/* Basic */
|
||||
@ -8,7 +9,8 @@ void force_log_raw(logger::category::value, spdlog::level::level_enum level, con
|
||||
void force_log_node(logger::category::value, spdlog::level::level_enum, const std::string_view &);
|
||||
|
||||
#ifdef NODEJS_API
|
||||
#include <NanEventCallback.h>
|
||||
#include <include/NanEventCallback.h>
|
||||
#include <include/NanStrings.h>
|
||||
|
||||
/* NODE JS */
|
||||
struct LogMessage {
|
||||
@ -41,16 +43,19 @@ struct StdExternalStringResourceBase : public v8::String::ExternalOneByteStringR
|
||||
std::string message;
|
||||
};
|
||||
|
||||
inline v8::Local<v8::Value> get_logger_method() {
|
||||
inline v8::MaybeLocal<v8::Function> get_logger_method() {
|
||||
v8::Local<v8::Object> global_context = Nan::GetCurrentContext()->Global();
|
||||
|
||||
v8::Local<v8::Object> logger_context = global_context->Get(Nan::New<v8::String>("logger").ToLocalChecked()).As<v8::Object>();
|
||||
v8::Local<v8::Value> logger_method = logger_context->Get(Nan::New<v8::String>("log").ToLocalChecked());
|
||||
if(!logger_method.IsEmpty() && !logger_method->IsNullOrUndefined())
|
||||
return logger_method;
|
||||
auto logger = Nan::GetLocal<v8::Object>(global_context, "logger");
|
||||
if(!logger.IsEmpty()) {
|
||||
auto log_function = Nan::Get<v8::Function>(logger, "log");
|
||||
if(!log_function.IsEmpty()) return log_function;
|
||||
}
|
||||
|
||||
logger_context = global_context->Get(Nan::New<v8::String>("console").ToLocalChecked()).As<v8::Object>();
|
||||
return logger_context->Get(Nan::New<v8::String>("log").ToLocalChecked());
|
||||
auto console = Nan::GetLocal<v8::Object>(global_context, "console");
|
||||
assert(!console.IsEmpty());
|
||||
|
||||
return Nan::Get<v8::Function>(console, "log");
|
||||
}
|
||||
|
||||
void logger::initialize_node() {
|
||||
@ -58,7 +63,7 @@ void logger::initialize_node() {
|
||||
Nan::HandleScope scope;
|
||||
|
||||
auto isolate = Nan::GetCurrentContext()->GetIsolate();
|
||||
v8::Local<v8::Value> logger_method = get_logger_method();
|
||||
auto logger_method = get_logger_method();
|
||||
|
||||
v8::Local<v8::Value> arguments[3];
|
||||
while(true) {
|
||||
@ -72,12 +77,13 @@ void logger::initialize_node() {
|
||||
log_messages_tail = &log_messages_head;
|
||||
messages_lock.unlock();
|
||||
|
||||
if(!logger_method.IsEmpty() && !logger_method->IsNullOrUndefined()) {
|
||||
if(!logger_method.IsEmpty()) {
|
||||
auto logger = logger_method.ToLocalChecked();
|
||||
arguments[0] = Nan::New<v8::Number>(entry->category);
|
||||
arguments[1] = Nan::New<v8::Number>(entry->level);
|
||||
arguments[2] = v8::String::NewExternalOneByte(isolate, new StdExternalStringResourceBase(entry->message)).ToLocalChecked();
|
||||
|
||||
logger_method.As<v8::Function>()->Call(Nan::GetCurrentContext(), Nan::Undefined(), 3, arguments);
|
||||
logger.As<v8::Function>()->Call(Nan::GetCurrentContext(), Nan::Undefined(), 3, arguments);
|
||||
} else {
|
||||
std::cout << "Failed to log message! Invalid method!" << std::endl;
|
||||
}
|
||||
|
@ -39,10 +39,8 @@ namespace logger {
|
||||
template<typename... Args>
|
||||
inline void force_log(category::value category, level::level_enum lvl, const char *fmt, const Args &... args) {
|
||||
try {
|
||||
fmt::MemoryWriter fmt_writer;
|
||||
fmt_writer.write(fmt, args...);
|
||||
|
||||
_force_log(category, lvl, std::string_view{fmt_writer.data(), fmt_writer.size()});
|
||||
const auto msg = fmt::format(fmt, args...);
|
||||
_force_log(category, lvl, msg);
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user