-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsession.js
More file actions
129 lines (102 loc) · 3.17 KB
/
session.js
File metadata and controls
129 lines (102 loc) · 3.17 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var rdp = require('./build/Release/node-freerdp2');
var EventEmitter = require('events');
// This is from include/freerdp/input.h to simplify addon code
const PTR_FLAGS_MOVE = 0x0800
const PTR_FLAGS_DOWN = 0x8000
const PTR_FLAGS_BUTTON1 = 0x1000 /* left */
const PTR_FLAGS_BUTTON2 = 0x2000 /* right */
const PTR_FLAGS_BUTTON3 = 0x4000 /* middle */
const PTR_FLAGS_HWHEEL = 0x0400
const PTR_FLAGS_WHEEL = 0x0200
const PTR_FLAGS_WHEEL_NEGATIVE = 0x0100
class Session extends EventEmitter {
constructor(options) {
super();
this.host = options.host;
this.username = options.username;
this.password = options.password;
this.s_domain = options.domain;// EventEmitter 本身有个domain
this.port = options.port || 3389;
this.width = options.width || 1366;
this.height = options.height || 768;
this.bitsPerPixel = 24;
this.certIgnore = options.certIgnore;
this.app = options.app;
this.drive = options.drive;
}
requestKeyframe() {
rdp.requestKeyframe(this._sessionIndex);
}
sendClipboard(data) {
rdp.sendClipboard(this._sessionIndex,data);
}
sendKeyEventScancode(code, pressed) {
rdp.sendKeyEventScancode(this._sessionIndex, code, pressed);
}
sendWheelEvent(x, y, step, isNegative, isHorizontal){
var flags = 0;
if (isHorizontal)
flags |= PTR_FLAGS_HWHEEL;
else
flags |= PTR_FLAGS_WHEEL;
if (isNegative)
{
flags |= PTR_FLAGS_WHEEL_NEGATIVE;
}
flags += step;
rdp.sendPointerEvent(this._sessionIndex, flags, x, y);
}
sendPointerEvent(x, y,button,isPressed) {
var flags = 0;
x = x || 0;
y = y || 0;
if (button == 1 && isPressed) flags |= PTR_FLAGS_BUTTON1 | PTR_FLAGS_DOWN;
if (button == 2 && isPressed) flags |= PTR_FLAGS_BUTTON2 | PTR_FLAGS_DOWN;
if (button == 1 && !isPressed) flags |= PTR_FLAGS_BUTTON1;
if (button == 2 && !isPressed) flags |= PTR_FLAGS_BUTTON2;
if (x !== null && y !== null && flags == 0) {
flags |= PTR_FLAGS_MOVE;
}
rdp.sendPointerEvent(this._sessionIndex, flags, x, y);
}
setClipboard(val) {
rdp.setClipboard(this._sessionIndex, val);
}
close() {
rdp.close(this._sessionIndex);
}
_eventHandler(event, args) {
args.unshift(event);
this.emit.apply(this, args);
}
connect() {
var params = [];
params.push(`/v:${this.host}`);
params.push(`/u:${this.username}`);
params.push(`/p:${this.password}`);
params.push(`/w:${this.width}`);
params.push(`/h:${this.height}`);
params.push(`/bpp:${this.bitsPerPixel}`);
params.push('+clipboard');
//params.push('/log-level:debug')
if (this.app) {
params.push(`/app:||${this.app}`);
}
if (this.drive) {
params.push(`/drive:RemoteApp,${this.drive}`);
}
if (this.certIgnore) {
params.push('/cert-ignore');
}
if (this.s_domain) {
params.push(`/d:${this.s_domain}`);
}
if (this.port) {
params.push(`/port:${this.port}`);
}
this._sessionIndex = rdp.connect(params, this._eventHandler.bind(this));
console.log(this._sessionIndex);
return this;
}
}
module.exports = Session;