init
This commit is contained in:
commit
a6d5d44ddf
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
71
index.js
Normal file
71
index.js
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
const robot = require('robotjs');
|
||||||
|
const WebSocket = require('ws');
|
||||||
|
|
||||||
|
const mode = 'host'; // 'host' or 'client'
|
||||||
|
const server = 'ws://node.janderedev.xyz:8080';
|
||||||
|
|
||||||
|
if (mode == 'client') {
|
||||||
|
const server = new WebSocket.Server({
|
||||||
|
port: 8080
|
||||||
|
});
|
||||||
|
|
||||||
|
let pos = {}
|
||||||
|
|
||||||
|
let sockets = [];
|
||||||
|
server.on('connection', async (socket) => {
|
||||||
|
console.log('New connection');
|
||||||
|
sockets.push(socket);
|
||||||
|
|
||||||
|
// When you receive a message, send that message to every socket.
|
||||||
|
socket.on('message', function(msg) {
|
||||||
|
console.log(`[SERVER] Received message: ${msg}`);
|
||||||
|
let [x, y] = msg.split(':');
|
||||||
|
x = Number(x);
|
||||||
|
y = Number(y);
|
||||||
|
|
||||||
|
pos[socket] = { x, y }
|
||||||
|
});
|
||||||
|
|
||||||
|
// When a socket closes, or disconnects, remove it from the array.
|
||||||
|
socket.on('close', function() {
|
||||||
|
console.log('Socket closed');
|
||||||
|
sockets = sockets.filter(s => s !== socket);
|
||||||
|
});
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
let x = 0, y = 0;
|
||||||
|
Object.values(pos).forEach(val => {
|
||||||
|
x += val.x;
|
||||||
|
y += val.y;
|
||||||
|
});
|
||||||
|
|
||||||
|
sockets.forEach(s => s.send(`${x / sockets.length}:${y / sockets.length}`));
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let getPos = () => {
|
||||||
|
let { x, y } = robot.getMousePos();
|
||||||
|
let screenSize = robot.getScreenSize();
|
||||||
|
x = x / screenSize.width;
|
||||||
|
y = y / screenSize.height;
|
||||||
|
return { x, y }
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new WebSocket(mode == 'host' ? 'ws://localhost:8080' : server);
|
||||||
|
client.on('open', () => console.log('Connected'));
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
let pos = getPos();
|
||||||
|
client.send(`${pos.x}:${pos.y}`);
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
client.on('message', (msg) => {
|
||||||
|
console.log(`[CLIENT] Received message: ${msg}`);
|
||||||
|
let [x, y] = msg.split(':');
|
||||||
|
x = Number(x);
|
||||||
|
y = Number(y);
|
||||||
|
let screenSize = robot.getScreenSize();
|
||||||
|
|
||||||
|
robot.moveMouse(x * screenSize.width, y * screenSize.height);
|
||||||
|
});
|
1970
package-lock.json
generated
Normal file
1970
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
8
package.json
Normal file
8
package.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"discord-rpc": "^3.1.4",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"robotjs": "^0.6.0",
|
||||||
|
"ws": "^7.4.1"
|
||||||
|
}
|
||||||
|
}
|
36
rpc.js
Normal file
36
rpc.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// ignore this
|
||||||
|
const RPC = require("discord-rpc")
|
||||||
|
|
||||||
|
const client = new RPC.Client({ transport: 'ipc' });
|
||||||
|
const creds = { clientId: '768515662036729887', clientSecret: '[REDACTED]' }
|
||||||
|
|
||||||
|
client.login({
|
||||||
|
clientId: creds.clientId
|
||||||
|
}).then(async () => {
|
||||||
|
console.log(client.user);
|
||||||
|
|
||||||
|
|
||||||
|
// Subscribe to events
|
||||||
|
['ACTIVITY_JOIN', 'ACTIVITY_JOIN_REQUEST'].forEach(evt => client.subscribe(evt, (data) => {
|
||||||
|
console.log(`Received ${evt}`);
|
||||||
|
console.log(data);
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
// Set the user's presence
|
||||||
|
await client.setActivity({
|
||||||
|
state: "state",
|
||||||
|
details: "details",
|
||||||
|
startTimestamp: Date.now(),
|
||||||
|
endTimestamp: Date.now() + (60 * 5 + 23),
|
||||||
|
partyId: 'asdf-ghjk-uztrew-asdfvgbh-trgf4e36r5t',
|
||||||
|
partySize: 1,
|
||||||
|
partyMax: 6,
|
||||||
|
joinSecret: "025ed05c71f639de8bfaa0d679d7c94b2fdce12f",
|
||||||
|
spectateSecret: "e7eb30d2ee025ed05c71ea495f770b76454ee4e0",
|
||||||
|
matchSecret: "4b2fdce12f639de8bfa7e3591b71a0d679d7c93f",
|
||||||
|
instance: true
|
||||||
|
});
|
||||||
|
let lobby = await client.createLobby(2, 6);
|
||||||
|
console.log(lobby);
|
||||||
|
});
|
Loading…
Reference in a new issue