mirror of https://github.com/lhie1/Rules.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.7 KiB
JavaScript
50 lines
1.7 KiB
JavaScript
module.exports = {
|
|
init: (address, port, clearFirst = true, debug = true) => {
|
|
var oldLog = console.log;
|
|
var oldInfo = console.info;
|
|
var oldWarn = console.warn;
|
|
var oldError = console.error;
|
|
let start = clearFirst
|
|
var socket = $socket.new(`ws://${address}:${port}`);
|
|
socket.open()
|
|
console.log = function (obj) {
|
|
if (debug) {
|
|
let msg = JSON.stringify({ type: 'log', args: Array.prototype.slice.call(arguments) });
|
|
start = sendMessage(start, socket, msg);
|
|
}
|
|
oldLog.apply(console, arguments);
|
|
}
|
|
console.info = function (obj) {
|
|
if (debug) {
|
|
let msg = JSON.stringify({ type: 'info', args: Array.prototype.slice.call(arguments) });
|
|
start = sendMessage(start, socket, msg);
|
|
}
|
|
oldInfo.apply(console, arguments);
|
|
}
|
|
console.warn = function (obj) {
|
|
if (debug) {
|
|
let msg = JSON.stringify({ type: 'warn', args: Array.prototype.slice.call(arguments) });
|
|
start = sendMessage(start, socket, msg);
|
|
}
|
|
oldWarn.apply(console, arguments);
|
|
}
|
|
console.error = function (obj) {
|
|
if (debug) {
|
|
let msg = JSON.stringify({ type: 'error', args: Array.prototype.slice.call(arguments) });
|
|
start = sendMessage(start, socket, msg);
|
|
}
|
|
oldError.apply(console, arguments);
|
|
}
|
|
}
|
|
}
|
|
|
|
function sendMessage(start, socket, msg) {
|
|
if (start) {
|
|
socket.send(JSON.stringify({ type: "_open" }));
|
|
start = false;
|
|
}
|
|
socket.send(msg);
|
|
return start;
|
|
}
|
|
|