-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
118 lines (93 loc) · 2.64 KB
/
app.js
File metadata and controls
118 lines (93 loc) · 2.64 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
var fs = require("fs");
const readline = require("readline");
var path = require('path')
/* HTTP and Socket*/
var app = require("express")();
var http = require("http").Server(app);
var io = require("socket.io")(http);
var express = require("express");
app.get("/", function(req, res) {
res.sendFile(__dirname + "/index.html");
});
app.use(express.static(path.join(__dirname, '/')));
var clients = [];
var usuarios = [];
io.on("connection", function (socket) {
socket.emit("ClientId", socket.io);
socket.emit("obterInfoMachine", "get");
socket.emit("update", "global");
attUsuarios();
socket.on("entrar", function(recebido) {
console.log(
"Conexão recebida de: " + recebido + " Host" + socket.handshake.address
);
socket.Apelido = recebido;
});
socket.on("infoMachine", function(retorno) {
var json = JSON.parse(retorno);
socket.IP = json.IP;
socket.Usuario = json.Usuario;
socket.NomeRede = json.NomeRede;
socket.Version = json.Version;
socket.NomeUsuario = json.Nome;
clients[socket.id] = socket;
attUsuarios();
//console.table(usuarios);
});
socket.on("enviarNome", function (msg,id) {
try {
clients[id].emit("setarNome", msg);
} catch{ }
});
socket.on("enviarAlert", function (msg,id) {
try {
clients[id].emit("alert", msg);
} catch{ }
});
socket.on("setarProxy", function (status, id) {
try {
clients[id].emit("proxy", status);
}catch { }
});
socket.on("solicitarPrint", function (id) {
try {
clients[id].emit("obterPrint", "get");
} catch{ }
});
socket.on("atividade", function(atv){
io.emit("atividadeUsuario",atv,socket.id);
});
socket.on("print", function(from) {
io.emit("printscreen", from,socket.id);
});
socket.on("disconnect", function() {
console.log(`Desconectado: ${socket.Apelido}`);
delete clients[socket.id];
attUsuarios();
});
});
function attUsuarios() {
usuarios = [];
for (indice in clients) {
let infoJson = {
"ID": clients[indice].id,
"IP": clients[indice].IP,
"Apelido": clients[indice].Apelido,
"Usuario": clients[indice].Usuario,
"NomeUsuario": clients[indice].NomeUsuario,
"NomeRede":clients[indice].NomeRede,
"Version":clients[indice].Version,
};
usuarios.push(infoJson);
}
io.emit("users", usuarios);
}
app.use(express.static(__dirname + "/node_modules"));
app.get("/", function(req, res) {
res.send("<h1>A</h1>");
});
/* */
for (var i = 0; i < 60; i++) console.log(" ");
http.listen(3000, function() {
console.log("Server iniciando na porta: 3000");
});