-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoPlayerStresser.js
122 lines (101 loc) · 2.36 KB
/
videoPlayerStresser.js
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
var config = {
ip:'192.168.1.109',
port:'1337',
files:['1.mp4','2.mp4','3.mp4','4.mp4','5.mp4','6.mp4','7.mp4','8.mp4','giphy.mp4','giphy_1.mp4','giphy_2.mp4','giphy_3.mp4','giphy_4.mp4','giphy_5.mp4','giphy_6.mp4']
}
var connected = false;
var connecting = false;
var fileIndex = 0;
var i = null;
var net = require('net');
var client = new net.Socket();
client.on("error", function(error)
{
console.log("Error connecting to vidplayer");
console.log(error);
connected = false;
connecting = false;
});
sendPlay = function(client,fileToPlay)
{
client.write(JSON.stringify(
{
command: "play",
fileName: fileToPlay
})+"\n");
}
sendPause = function(client)
{
client.write(JSON.stringify(
{
command: "pause"
})+"\n");
}
doSomething = function()
{
if(connected && Math.random() < 0.02)
{
var fileToPlay = config.files[Math.floor((Math.random() * (config.files.length-1)))];
console.log('play '+fileToPlay);
sendPlay(client,fileToPlay);
if(Math.random() > 0.8)
{
console.log('pause');
sendPause(client);
}
}
else if(connected == false)
{
client.connect(config.port, config.ip, function()
{
console.log('Connected to vidplayer');
connected = true;
});
}
}
var stdin = process.stdin;
// without this, we would only get streams once enter is pressed
stdin.setRawMode( true );
// resume stdin in the parent process (node app won't quit all by itself
// unless an error or process.exit() happens)
stdin.resume();
// i don't want binary, do you?
stdin.setEncoding( 'utf8' );
// on any data into stdin
stdin.on( 'data', function( key ){
if(connected == false && connecting == false)
{
connecting = true;
client.connect(config.port, config.ip, function()
{
console.log('Connected to vidplayer');
connected = true;
connecting = false;
});
}
// ctrl-c ( end of text )
switch(key)
{
case '\u0003':
process.exit();
break;
case 'n':
fileIndex = (fileIndex+1)%config.files.length;
sendPlay(client,config.files[fileIndex]);
break
case 'p':
sendPause(client);
break;
case 'i':
if(i===null)
i = setInterval(doSomething,100);
else
{
clearInterval(i);
i=null;
}
break;
}
// write the key to stdout all normal like
process.stdout.write( key );
});