This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathbridge.cc
81 lines (60 loc) · 1.93 KB
/
bridge.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <nan.h>
#include "bridge.h"
#include "rdp.h"
using v8::Function;
using v8::Local;
using v8::Number;
using v8::Value;
using v8::String;
using v8::Handle;
using v8::Array;
using Nan::Callback;
using Nan::HandleScope;
using Nan::New;
using Nan::MaybeLocal;
using Nan::Null;
using Nan::To;
NAN_METHOD(Connect) {
Nan::HandleScope scope;
Handle<Value> val;
Handle<Array> jsArray = Handle<Array>::Cast(info[0]);
char** cstrings = new char*[jsArray->Length() + 1];
std::string tmp = "node-freerdp";
cstrings[0] = new char[tmp.size() + 1];
std::strcpy(cstrings[0], tmp.c_str());
for (unsigned int i = 0; i < jsArray->Length(); i++) {
val = jsArray->Get(i);
std::string current = std::string(*String::Utf8Value(val));
cstrings[i + 1] = new char[current.size() + 1];
std::strcpy(cstrings[i + 1], current.c_str());
}
Callback *callback = new Callback(info[1].As<Function>());
int session_index = node_freerdp_connect(jsArray->Length() + 1, cstrings, callback);
info.GetReturnValue().Set(session_index);
}
NAN_METHOD(SendKeyEventScancode) {
Nan::HandleScope scope;
int session_index = info[0]->Uint32Value();
int scanCode = info[1]->Uint32Value();
int pressed = info[2]->Uint32Value();
node_freerdp_send_key_event_scancode(session_index, scanCode, pressed);
}
NAN_METHOD(SendPointerEvent) {
Nan::HandleScope scope;
int session_index = info[0]->Uint32Value();
int flags = info[1]->Uint32Value();
int x = info[2]->Uint32Value();
int y = info[3]->Uint32Value();
node_freerdp_send_pointer_event(session_index, flags, x, y);
}
NAN_METHOD(SetClipboard) {
Nan::HandleScope scope;
int session_index = info[0]->Uint32Value();
std::string str = std::string(*String::Utf8Value(info[1]));
node_freerdp_set_clipboard(session_index, (void*)str.c_str(), str.size());
}
NAN_METHOD(Close) {
Nan::HandleScope scope;
int session_index = info[0]->Uint32Value();
node_freerdp_close(session_index);
}