This repository was archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
183 lines (151 loc) · 5.34 KB
/
Copy pathindex.js
File metadata and controls
183 lines (151 loc) · 5.34 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Caleb, KO4UYJ
discord: _php_
email: ko4uyj@gmail.com
*/
import io from "socket.io-client";
import logger from "./logger.js";
import readline from "readline";
import fs from "fs";
import yaml from "js-yaml";
console.log(`
WhackerLink Client Emulator
Caleb, KO4UYJ
Commands:
ctrL + c : quit
k : key
u : unkey
Params:
-c config.example.yml
`);
const configFilePathIndex = process.argv.indexOf('-c');
if (configFilePathIndex === -1 || process.argv.length <= configFilePathIndex + 1) {
logger.error("Please provide the path to the configuration file using -c arg");
process.exit(1);
}
const configFilePath = process.argv[configFilePathIndex + 1];
const configFile = fs.readFileSync(configFilePath, 'utf8');
const config = yaml.load(configFile);
const peerSocket = io(config.networkUrl, {
query: { token: config.networkJWT }
});
if (!config.bgMode){
readline.emitKeypressEvents(process.stdin);
process.stdin.on('keypress', (ch, key) => {
//console.log('got keypress', ch, key);
if (key && key.ctrl && key.name == 'c') {
process.exit();
} else if(key && key.name == 'k') {
request_voice_channel();
} else if(key && key.name == 'u') {
release_voice_channel();
}
});
process.stdin.setRawMode(true);
}
const userStatus = {
microphone: true,
mute: false,
srcId: config.srcId,
online: true,
dstId: config.dstId,
controlChannel: config.controlChannel,
voiceChannel: "000.0000"
};
let denied = false;
let connected = false;
let occasionalKey = true;
peerSocket.on('connect', function(d){
logger.info("Connected to network");
emulatePowerOn();
connected = true;
});
peerSocket.on("CONTROL_CHANNEL_ERROR", function(data) {
logger.error(data.message);
});
function emulatePowerOn(){
peerSocket.emit("JOIN_CONTROL_CHANNEL", {channel: userStatus.controlChannel});
updateStatus(userStatus);
peerSocket.emit("REG_REQUEST", userStatus.srcId);
logger.info("Reg Request");
peerSocket.once("REG_GRANTED", (data)=>{
logger.info("Reg Granted")
startAffiliation();
});
peerSocket.once("REG_REFUSE", (data)=>{
logger.warn("Sys reg refuse");
});
}
function startAffiliation(srcId, dstId){
logger.info("Affiliation Request")
peerSocket.emit('CHANNEL_AFFILIATION_REQUEST', {"srcId": userStatus.srcId, "dstId": userStatus.dstId});
peerSocket.on("CHANNEL_AFFILIATION_GRANTED", function (data){
if (data.srcId === userStatus.srcId){
logger.info("Affiliation granted");
peerSocket.off("CHANNEL_AFFILIATION_GRANTED");
}
});
peerSocket.on("VOICE_CHANNEL_GRANT", function (data) {
if (data.srcId === userStatus.srcId && data.dstId === userStatus.dstId) {
userStatus.microphone = !userStatus.microphone;
logger.info("Switching to voice channel: " + data.newChannel);
userStatus.voiceChannel = data.newChannel;
updateStatus();
peerSocket.emit("VOICE_CHANNEL_CONFIRMED", {"srcId": userStatus.srcId, "dstId": userStatus.dstId});
logger.info(userStatus.voiceChannel);
denied = false;
} else if(data.dstId === userStatus.dstId) {
logger.info("Switching to voice channel: " + data.newChannel);
userStatus.voiceChannel = data.newChannel;
updateStatus(userStatus);
peerSocket.emit("VOICE_CHANNEL_CONFIRMED", {"srcId": userStatus.srcId, "dstId": userStatus.dstId});
}
});
peerSocket.on("VOICE_CHANNEL_RELEASE", function (data){
if (data.srcId === userStatus.srcId && data.dstId === userStatus.dstId) {
logger.info("Released Voice Channel");
userStatus.microphone = !userStatus.microphone;
userStatus.voiceChannel = "000.0000";
updateStatus(userStatus);
denied = false;
} else if(data.dstId === userStatus.dstId){
logger.info("Got voice release");
userStatus.voiceChannel = "000.0000";
updateStatus(userStatus);
}
});
peerSocket.on("VOICE_CHANNEL_DENY", function (data){
denied = true
if (data.srcId === userStatus.srcId && data.dstId === userStatus.dstId) {
logger.info("Voice Channel Deny");
denied = false;
}
});
}
function request_voice_channel() {
peerSocket.emit("VOICE_CHANNEL_REQUEST", {"srcId": userStatus.srcId, "dstId": userStatus.dstId});
}
function release_voice_channel() {
if (!denied) {
logger.info("Send voice channel release");
peerSocket.emit("RELEASE_VOICE_CHANNEL", {"srcId": userStatus.srcId, "dstId": userStatus.dstId});
} else {
denied = false
}
}
function updateStatus(status){
peerSocket.emit("userInformation", userStatus);
}
if (config.occasionalVoiceTransmission){
setInterval(()=>{
if (connected){
request_voice_channel();
setTimeout(()=>{
release_voice_channel();
}, config.occasionalTransmissionsLength);
}
}, config.occasionalTransmissionsOccurance);
}
peerSocket.on("updateChannels", (data)=>{
//
});