-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
66 lines (55 loc) · 2.2 KB
/
server.js
File metadata and controls
66 lines (55 loc) · 2.2 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
const express = require('express');
const fs = require('fs');
const app = express();
const path = require('path');
const ioServer = require('socket.io');
const RTCMultiConnection = require('rtcmulticonnection');
const RTCMultiConnectionServer = require('rtcmulticonnection-server');
const robot = require('robotjs');
var options = {
key: fs.readFileSync('privateKey.key'),
cert: fs.readFileSync('certificate.crt')
};
app.use(express.static(path.join(__dirname, 'public')));
var PORT = 2002;
var config = require('./config.json');
//******************************************************************** */
var httpsApp = require('https').createServer(options, app);
//var connection = new RTCMultiConnectionServer();
RTCMultiConnectionServer.beforeHttpListen(httpsApp, config);
httpsApp = httpsApp.listen(process.env.PORT || PORT, process.env.IP || "0.0.0.0", function() {
RTCMultiConnectionServer.afterHttpListen(httpsApp, config);
});
ioServer(httpsApp).on('connection', function(socket) {
RTCMultiConnectionServer.addSocket(socket, config);
//*************************************************************** */
// ----------------------
// below code is optional
const params = socket.handshake.query;
if (!params.socketCustomEvent) {
params.socketCustomEvent = 'custom-message';
}
socket.on(params.socketCustomEvent, function(message) {
var x = message.mouse.mouse_position.x;
var y = message.mouse.mouse_position.y;
var mousedownLeft = message.mouse.mouse_click.mousedownLeft;
var mousedownRight = message.mouse.mouse_click.mousedownRight;
let key = message.keyboard.key;
if(key !== null){
if(key === 'Backspace')
robot.keyTap("backspace")
else
robot.keyTap(key)
console.log(message.keyboard.key)
}
if(mousedownLeft){
robot.mouseClick("left")
}
else if(mousedownRight){
robot.mouseClick("right")
}
robot.moveMouse(x, y);
//console.log(message.keyboard);
socket.broadcast.emit(params.socketCustomEvent, message);
});
});