Initial commit
This commit is contained in:
214
dist/Unity/CameraRunner.js
vendored
Normal file
214
dist/Unity/CameraRunner.js
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
||||
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CameraRunner = void 0;
|
||||
var socket_io_client_1 = require("socket.io-client");
|
||||
var Utils_1 = require("../Utils");
|
||||
var PREFIX = "[CameraRunner]";
|
||||
var CameraRunner = /** @class */ (function () {
|
||||
function CameraRunner(Main) {
|
||||
this.state = 'DISCONNECTED';
|
||||
this.processStatus = {
|
||||
state: 'STOPPED',
|
||||
startTime: -1,
|
||||
output: { current: [], last: [] },
|
||||
};
|
||||
this._Main = Main;
|
||||
}
|
||||
CameraRunner.prototype.handle = function (command) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
switch (command) {
|
||||
case 'restart':
|
||||
case 'reboot':
|
||||
var callback = args[0];
|
||||
if (typeof callback !== 'function')
|
||||
return;
|
||||
this.sendCommand(command, callback);
|
||||
break;
|
||||
}
|
||||
};
|
||||
CameraRunner.prototype.sendCommand = function (command, callback) {
|
||||
if (this.socket == null || !this.socket.connected)
|
||||
return callback({
|
||||
succeed: false,
|
||||
message: 'Not connected to CameraRunner',
|
||||
});
|
||||
this.socket.emit(command, function (response) {
|
||||
callback(response);
|
||||
});
|
||||
};
|
||||
CameraRunner.prototype.broadcastState = function () {
|
||||
this._Main.WebServer.socket.emit('cameraRunnerState', this.getState());
|
||||
};
|
||||
CameraRunner.prototype.getState = function () {
|
||||
return {
|
||||
state: this.state,
|
||||
message: this.message,
|
||||
error: this.error,
|
||||
processStatus: this.processStatus,
|
||||
};
|
||||
};
|
||||
CameraRunner.prototype.setInfo = function (message, error, state) {
|
||||
if (state === void 0) { state = 'FAILED'; }
|
||||
this.message = message;
|
||||
this.error = error;
|
||||
this.state = state;
|
||||
this.broadcastState();
|
||||
if (state == 'FAILED' || state == 'DISCONNECTED')
|
||||
console.warn(PREFIX, message !== null && message !== void 0 ? message : error);
|
||||
else
|
||||
console.log(PREFIX, message !== null && message !== void 0 ? message : error);
|
||||
};
|
||||
CameraRunner.prototype.startPollClock = function () {
|
||||
var _this = this;
|
||||
var poll = function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var data;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, new Promise(function (resolve) {
|
||||
_this.socket.emit('getStatus', function (response) {
|
||||
return resolve(response);
|
||||
});
|
||||
})];
|
||||
case 1:
|
||||
data = _a.sent();
|
||||
this.processStatus = data;
|
||||
this.broadcastState();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
this.socket.on('simpleStatus', function (simpleStatus) {
|
||||
_this.processStatus.state = simpleStatus.state;
|
||||
_this.processStatus.message = simpleStatus.message;
|
||||
_this.processStatus.error = simpleStatus.error;
|
||||
_this.broadcastState();
|
||||
});
|
||||
clearInterval(this.pollClock);
|
||||
this.pollClock = setInterval(function () { return poll(); }, this._Main.Config.cameraRunner.pollInterval);
|
||||
poll();
|
||||
};
|
||||
CameraRunner.prototype.reconnect = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
clearInterval(this.pollClock);
|
||||
if (this.socket != null) {
|
||||
this.socket.disconnect();
|
||||
this.socket.close();
|
||||
this.socket = null;
|
||||
}
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(500)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.setInfo("Reconnecting to CameraRunner in 5 seconds...", null, 'CONNECTING');
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(5000)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, this.connect()];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
CameraRunner.prototype.connect = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var ip, port;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
this.setInfo('Connecting to CameraRunner', null, 'CONNECTING');
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(1000)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
ip = this._Main.Config.cameraRunner.webSocket.ip;
|
||||
port = this._Main.Config.cameraRunner.webSocket.port;
|
||||
if (ip == null || port == null) {
|
||||
return [2 /*return*/, this.setInfo('Connection problem', 'Camera Runner WebSocket IP or port is not configured.')];
|
||||
}
|
||||
this.socket = (0, socket_io_client_1.io)("ws://".concat(ip, ":").concat(port), {
|
||||
reconnectionAttempts: 0,
|
||||
reconnectionDelay: 2000,
|
||||
});
|
||||
this.socket.on('connect', function () {
|
||||
_this.setInfo('Connected', null, 'CONNECTED');
|
||||
_this.startPollClock();
|
||||
});
|
||||
this.socket.on('disconnect', function () {
|
||||
_this.setInfo('Disconnected', null, 'DISCONNECTED');
|
||||
_this.reconnect();
|
||||
});
|
||||
this.socket.on('reconnect', function () {
|
||||
_this.setInfo('Connected (reconnection)', null, 'CONNECTED');
|
||||
});
|
||||
this.socket.on('connect_error', function (err) {
|
||||
_this.setInfo('Connection problem', "Connection error: ".concat(err));
|
||||
_this.reconnect();
|
||||
});
|
||||
this.socket.on('error', function (err) {
|
||||
_this.setInfo('Connection problem', "Socket error: ".concat(err));
|
||||
_this.reconnect();
|
||||
});
|
||||
this.socket.on('reconnect_attempt', function () {
|
||||
_this.setInfo('Reconnecting', null, 'CONNECTING');
|
||||
});
|
||||
this.socket.on('reconnect_failed', function () {
|
||||
_this.setInfo('Connection problem', 'Reconnection failed');
|
||||
_this.reconnect();
|
||||
});
|
||||
this.socket.on('close', function () {
|
||||
_this.setInfo('Disconnected', null, 'DISCONNECTED');
|
||||
_this.reconnect();
|
||||
});
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
return CameraRunner;
|
||||
}());
|
||||
exports.CameraRunner = CameraRunner;
|
||||
//# sourceMappingURL=CameraRunner.js.map
|
||||
1
dist/Unity/CameraRunner.js.map
vendored
Normal file
1
dist/Unity/CameraRunner.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"CameraRunner.js","sourceRoot":"","sources":["../../src/Unity/CameraRunner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA8C;AAE9C,kCAA+C;AAE/C,IAAM,MAAM,GAAG,gBAAgB,CAAC;AAChC;IAgBC,sBAAY,IAAU;QAXtB,UAAK,GAAiB,cAAc,CAAC;QAIrC,kBAAa,GAAkB;YAC9B,KAAK,EAAE,SAAS;YAEhB,SAAS,EAAE,CAAC,CAAC;YACb,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;SACjC,CAAC;QAGD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,6BAAM,GAAN,UAAO,OAAe;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QACrC,QAAQ,OAAO,EAAE,CAAC;YACjB,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ;gBACZ,IAAM,QAAQ,GAGD,IAAI,CAAC,CAAC,CAAC,CAAC;gBACrB,IAAI,OAAO,QAAQ,KAAK,UAAU;oBAAE,OAAO;gBAE3C,IAAI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,EAAE,cAAc,CAAC,CAAC;4BACnD,KAAI,CAAC,SAAS,EAAE,CAAC;wBAClB,CAAC,CAAC,CAAC;;;;;KACH;IACF,mBAAC;AAAD,CAAC,AAxLD,IAwLC;AAxLY,oCAAY"}
|
||||
117
dist/Unity/Unity.js
vendored
Normal file
117
dist/Unity/Unity.js
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
||||
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Unity = void 0;
|
||||
var ws_1 = require("ws");
|
||||
var Utils_1 = require("../Utils");
|
||||
var PREFIX = '[Unity]';
|
||||
var Unity = /** @class */ (function () {
|
||||
function Unity(Main) {
|
||||
this.state = 'DISCONNECTED';
|
||||
this.restartRequested = false;
|
||||
this._Main = Main;
|
||||
}
|
||||
Unity.prototype.broadcastState = function () {
|
||||
this._Main.WebServer.socket.emit('unityState', this.getState());
|
||||
};
|
||||
Unity.prototype.setInfo = function (message, error, state) {
|
||||
if (state === void 0) { state = 'FAILED'; }
|
||||
this.message = message;
|
||||
this.error = error;
|
||||
this.state = state;
|
||||
this.broadcastState();
|
||||
if (state == 'FAILED' || state == 'DISCONNECTED')
|
||||
console.warn(PREFIX, message !== null && message !== void 0 ? message : error);
|
||||
else
|
||||
console.log(PREFIX, message !== null && message !== void 0 ? message : error);
|
||||
};
|
||||
Unity.prototype.reconnect = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (this.restartRequested)
|
||||
return [2 /*return*/];
|
||||
this.restartRequested = true;
|
||||
if (this.socket != null) {
|
||||
this.socket.close();
|
||||
this.socket = null;
|
||||
}
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(500)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.setInfo("Reconnecting to Unity in 5 seconds...", null, 'CONNECTING');
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(5000)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, this.connect()];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Unity.prototype.connect = function () {
|
||||
var _this = this;
|
||||
var ws = new ws_1.WebSocket("ws://".concat(this._Main.Config.unity.webSocket.ip, ":").concat(this._Main.Config.unity.webSocket.port));
|
||||
ws.on('error', function (error) {
|
||||
_this.setInfo('Connection error', "Could not connect: ".concat(error.message), 'FAILED');
|
||||
_this.reconnect();
|
||||
});
|
||||
ws.on('open', function () {
|
||||
_this.setInfo('Connected', null, 'CONNECTED');
|
||||
});
|
||||
ws.on('close', function () {
|
||||
if (_this.restartRequested)
|
||||
return;
|
||||
_this.setInfo('Disconnected', 'Unity was disconnected unexpectedly', 'DISCONNECTED');
|
||||
_this.reconnect();
|
||||
});
|
||||
};
|
||||
Unity.prototype.getState = function () {
|
||||
return {
|
||||
state: this.state,
|
||||
message: this.message,
|
||||
error: this.error,
|
||||
};
|
||||
};
|
||||
return Unity;
|
||||
}());
|
||||
exports.Unity = Unity;
|
||||
//# sourceMappingURL=Unity.js.map
|
||||
1
dist/Unity/Unity.js.map
vendored
Normal file
1
dist/Unity/Unity.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Unity.js","sourceRoot":"","sources":["../../src/Unity/Unity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAA+B;AAE/B,kCAA+C;AAE/C,IAAM,MAAM,GAAG,SAAS,CAAC;AACzB;IASC,eAA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Normal file
@@ -0,0 +1,278 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
||||
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UnityRunner = void 0;
|
||||
var fs_extra_1 = require("fs-extra");
|
||||
var child_process_1 = require("child_process");
|
||||
var Utils_1 = require("../Utils");
|
||||
var PREFIX = '[UnityRunner]';
|
||||
var LOG_OUTPUT = !process.argv.includes('--no-output-log');
|
||||
var UnityRunner = /** @class */ (function () {
|
||||
function UnityRunner(Main) {
|
||||
this.message = 'Awaiting startup delay...';
|
||||
this.startTime = null;
|
||||
this.output = { current: [], last: [] };
|
||||
this.restartTriggered = false;
|
||||
this._Main = Main;
|
||||
}
|
||||
UnityRunner.prototype.handle = function (command) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
switch (command) {
|
||||
case 'restart':
|
||||
var callback = args[0];
|
||||
if (typeof callback !== 'function')
|
||||
return;
|
||||
callback(this.requestRestart());
|
||||
break;
|
||||
}
|
||||
};
|
||||
UnityRunner.prototype.startStatusClock = function () {
|
||||
var _this = this;
|
||||
clearInterval(this.statusClock);
|
||||
this.statusClock = setInterval(function () {
|
||||
_this.broadcastState();
|
||||
}, 3000);
|
||||
};
|
||||
UnityRunner.prototype.requestRestart = function () {
|
||||
if (this.state !== 'RUNNING')
|
||||
return {
|
||||
succeed: false,
|
||||
message: 'Cannot restart when process is not running. It is probably restarting already.',
|
||||
};
|
||||
this.restart(true);
|
||||
return { succeed: true };
|
||||
};
|
||||
UnityRunner.prototype.broadcastState = function () {
|
||||
this._Main.WebServer.socket.emit('unityRunnerState', this.getStatus());
|
||||
};
|
||||
UnityRunner.prototype.setInfo = function (message, error, state) {
|
||||
if (state === void 0) { state = 'PROBLEM'; }
|
||||
this.message = message;
|
||||
this.error = error;
|
||||
this.state = state;
|
||||
this.broadcastState();
|
||||
this.output.current.push("[".concat(new Date().toLocaleTimeString('nl-NL'), "] [System] [").concat(state, "] ").concat(message !== null && message !== void 0 ? message : error));
|
||||
if (state == 'PROBLEM' || state == 'STOPPED')
|
||||
console.warn(PREFIX, message !== null && message !== void 0 ? message : error);
|
||||
else
|
||||
console.log(PREFIX, message !== null && message !== void 0 ? message : error);
|
||||
};
|
||||
UnityRunner.prototype.restart = function () {
|
||||
return __awaiter(this, arguments, void 0, function (instant) {
|
||||
if (instant === void 0) { instant = false; }
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (this.restartTriggered)
|
||||
return [2 /*return*/];
|
||||
clearInterval(this.statusClock);
|
||||
this._Main.WebServer.Calibration.hasCalibrationImage = false;
|
||||
this._Main.UnityWebSocket.disconnect();
|
||||
this.restartTriggered = true;
|
||||
this.startTime = -1;
|
||||
this.broadcastState();
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(2000)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
if (this.output.current.length > 0) {
|
||||
this.output.last = __spreadArray([], this.output.current, true);
|
||||
this.output.current = [];
|
||||
}
|
||||
if (instant)
|
||||
this.setInfo('Process will restart shortly...', null, 'STOPPED');
|
||||
if (!(this.process != null)) return [3 /*break*/, 3];
|
||||
this.process.kill('SIGTERM');
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(3000)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
if (!this.process.killed && this.process.exitCode === null) {
|
||||
this.process.kill('SIGKILL');
|
||||
console.log(PREFIX, 'Sent SIGKILL to process.');
|
||||
}
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
this.startTime = -1;
|
||||
if (!!instant) return [3 /*break*/, 5];
|
||||
this.message = 'Reconnecting in 10 seconds...';
|
||||
this.broadcastState();
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(10000)];
|
||||
case 4:
|
||||
_a.sent();
|
||||
_a.label = 5;
|
||||
case 5: return [4 /*yield*/, this.start()];
|
||||
case 6:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
UnityRunner.prototype.start = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var path, fileName;
|
||||
var _this = this;
|
||||
var _a, _b, _c;
|
||||
return __generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
case 0:
|
||||
if (this.output.current.length > 0) {
|
||||
this.output.last = __spreadArray([], this.output.current, true);
|
||||
this.output.current = [];
|
||||
}
|
||||
this.startTime = Date.now();
|
||||
this.restartTriggered = false;
|
||||
this.broadcastState();
|
||||
this._Main.WebServer.Calibration.hasCalibrationImage = false;
|
||||
clearInterval(this.statusClock);
|
||||
path = this._Main.Config.unity.executable.path;
|
||||
if (path == null || !(0, fs_extra_1.pathExistsSync)(path)) {
|
||||
this.setInfo('Executable problem', "Executable path is not set or does not exist: ".concat(path));
|
||||
return [2 /*return*/];
|
||||
}
|
||||
if (!(this._Main.CameraRunner.state !== 'CONNECTED')) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, new Promise(function (resolve) {
|
||||
_this.setInfo('Waiting for CameraRunner to connect...', null, 'STARTING');
|
||||
var c = setInterval(function () {
|
||||
if (_this._Main.CameraRunner.state !== 'CONNECTED')
|
||||
return;
|
||||
clearInterval(c);
|
||||
resolve();
|
||||
}, 1000);
|
||||
})];
|
||||
case 1:
|
||||
_d.sent();
|
||||
_d.label = 2;
|
||||
case 2:
|
||||
if (!(((_a = this._Main.CameraRunner.processStatus) === null || _a === void 0 ? void 0 : _a.state) !== 'RUNNING')) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, new Promise(function (resolve) {
|
||||
_this.setInfo('Waiting for CameraRunner process to start...', null, 'STARTING');
|
||||
var c = setInterval(function () {
|
||||
var _a;
|
||||
if (((_a = _this._Main.CameraRunner.processStatus) === null || _a === void 0 ? void 0 : _a.state) !==
|
||||
'RUNNING')
|
||||
return;
|
||||
clearInterval(c);
|
||||
resolve();
|
||||
}, 1000);
|
||||
})];
|
||||
case 3:
|
||||
_d.sent();
|
||||
_d.label = 4;
|
||||
case 4:
|
||||
fileName = path.split(/(\/|\\)/).pop();
|
||||
this.setInfo("Starting executable: ".concat(fileName), null, 'STARTING');
|
||||
this.process = (0, child_process_1.spawn)(path, this._Main.Config.unity.executable.arguments, {
|
||||
stdio: 'pipe',
|
||||
});
|
||||
this.process.on('exit', function (code, signal) {
|
||||
if (_this.restartTriggered)
|
||||
return;
|
||||
_this.setInfo('Process exited', "Process exited with code ".concat(code, " and signal ").concat(signal), 'STOPPED');
|
||||
_this.restart();
|
||||
});
|
||||
this.process.on('error', function (err) {
|
||||
_this.setInfo('Process error', err.message);
|
||||
_this.restart();
|
||||
});
|
||||
(_b = this.process.stdout) === null || _b === void 0 ? void 0 : _b.on('data', function (data) {
|
||||
var lines = data
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter(function (line) { return line.length > 0; });
|
||||
lines.forEach(function (line) {
|
||||
var formattedLine = "[".concat(new Date().toLocaleTimeString('nl-NL'), "] [").concat(fileName, "] ").concat(line);
|
||||
if (LOG_OUTPUT)
|
||||
console.log(PREFIX, formattedLine);
|
||||
_this.output.current.push(formattedLine);
|
||||
});
|
||||
});
|
||||
(_c = this.process.stderr) === null || _c === void 0 ? void 0 : _c.on('data', function (data) {
|
||||
var lines = data
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter(function (line) { return line.length > 0; });
|
||||
lines.forEach(function (line) {
|
||||
var formattedLine = "[".concat(new Date().toLocaleTimeString('nl-NL'), "] [").concat(fileName, "] [ERROR] ").concat(line);
|
||||
if (LOG_OUTPUT)
|
||||
console.error(PREFIX, formattedLine);
|
||||
_this.output.current.push(formattedLine);
|
||||
});
|
||||
});
|
||||
this.startStatusClock();
|
||||
setTimeout(function () {
|
||||
var _a, _b;
|
||||
if (_this.process == null ||
|
||||
((_a = _this.process) === null || _a === void 0 ? void 0 : _a.killed) ||
|
||||
((_b = _this.process) === null || _b === void 0 ? void 0 : _b.exitCode) != null ||
|
||||
_this.restartTriggered)
|
||||
return;
|
||||
_this.setInfo('Running', '', 'RUNNING');
|
||||
_this._Main.UnityWebSocket.connect();
|
||||
}, 5000);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
UnityRunner.prototype.getStatus = function () {
|
||||
return {
|
||||
state: this.state,
|
||||
message: this.message,
|
||||
error: this.error,
|
||||
startTime: this.startTime,
|
||||
output: this.output,
|
||||
};
|
||||
};
|
||||
return UnityRunner;
|
||||
}());
|
||||
exports.UnityRunner = UnityRunner;
|
||||
//# sourceMappingURL=UnityRunner.js.map
|
||||
1
dist/Unity/UnityRunner.js.map
vendored
Normal file
1
dist/Unity/UnityRunner.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
244
dist/Unity/UnityWebSocket.js
vendored
Normal file
244
dist/Unity/UnityWebSocket.js
vendored
Normal file
@@ -0,0 +1,244 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
||||
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UnityWebSocket = void 0;
|
||||
var ws_1 = require("ws");
|
||||
var Utils_1 = require("../Utils");
|
||||
var PREFIX = '[Unity]';
|
||||
var UnityWebSocket = /** @class */ (function () {
|
||||
function UnityWebSocket(Main) {
|
||||
this.state = 'DISCONNECTED';
|
||||
this.message = 'Waiting for process...';
|
||||
this.parameters = {
|
||||
timelineWatching: false,
|
||||
timelineStanding: false,
|
||||
timelineProgress: 0,
|
||||
zedPath: '',
|
||||
zedReady: false,
|
||||
zedFPS: '-',
|
||||
parameters: [],
|
||||
};
|
||||
this.disconnected = false;
|
||||
this.restartRequested = false;
|
||||
this._Main = Main;
|
||||
}
|
||||
UnityWebSocket.prototype.handle = function (command) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
switch (command) {
|
||||
case 'parameterValue':
|
||||
var sliderIndex = args[0];
|
||||
var percentage = args[1];
|
||||
if (this.parameters.parameters[sliderIndex] == undefined)
|
||||
return;
|
||||
this.parameters.parameters[sliderIndex].outputValue =
|
||||
percentage;
|
||||
if (this.socket == null ||
|
||||
this.socket.readyState !== ws_1.WebSocket.OPEN)
|
||||
return;
|
||||
this.socket.send(JSON.stringify({
|
||||
type: 'set_slider_value',
|
||||
sliderIndex: sliderIndex,
|
||||
sliderValue: percentage,
|
||||
}));
|
||||
this.broadcastState();
|
||||
break;
|
||||
}
|
||||
};
|
||||
UnityWebSocket.prototype.broadcastState = function () {
|
||||
this._Main.WebServer.socket.emit('unityWebSocketState', this.getState());
|
||||
};
|
||||
UnityWebSocket.prototype.setInfo = function (message, error, state) {
|
||||
if (state === void 0) { state = 'FAILED'; }
|
||||
this.message = message;
|
||||
this.error = error;
|
||||
this.state = state;
|
||||
this.broadcastState();
|
||||
if (state == 'FAILED' || state == 'DISCONNECTED')
|
||||
console.warn(PREFIX, message !== null && message !== void 0 ? message : error);
|
||||
else
|
||||
console.log(PREFIX, message !== null && message !== void 0 ? message : error);
|
||||
};
|
||||
UnityWebSocket.prototype.stopFetchClocks = function () {
|
||||
clearInterval(this.heartbeatClock);
|
||||
clearInterval(this.calibrationImageClock);
|
||||
};
|
||||
UnityWebSocket.prototype.handleSocketMessage = function (data) {
|
||||
var message;
|
||||
try {
|
||||
message = JSON.parse(data.toString());
|
||||
}
|
||||
catch (error) {
|
||||
return;
|
||||
}
|
||||
switch (message.type) {
|
||||
case 'heartbeat_data':
|
||||
this.parameters.timelineWatching =
|
||||
message.heartbeat.dataTimeline.isWatching;
|
||||
this.parameters.timelineStanding =
|
||||
message.heartbeat.dataTimeline.isStanding;
|
||||
this.parameters.timelineProgress =
|
||||
message.heartbeat.dataTimeline.timelineProgress;
|
||||
this.parameters.zedPath = "".concat(message.heartbeat.zedCamera.streamInputIP, ":").concat(message.heartbeat.zedCamera.streamInputPort);
|
||||
this.parameters.zedReady =
|
||||
message.heartbeat.zedCamera.isZedReady;
|
||||
this.parameters.zedFPS = message.heartbeat.zedCamera.cameraFPS;
|
||||
this.parameters.parameters = message.heartbeat.dataSliders;
|
||||
this.broadcastState();
|
||||
break;
|
||||
case 'response_camera_frame':
|
||||
this._Main.WebServer.Calibration.writeCalibrationImage(message.imageBase64);
|
||||
break;
|
||||
}
|
||||
};
|
||||
UnityWebSocket.prototype.disconnect = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
this.restartRequested = true;
|
||||
this.disconnected = true;
|
||||
if (this.socket != null) {
|
||||
this.socket.close();
|
||||
this.socket = null;
|
||||
}
|
||||
this.stopFetchClocks();
|
||||
this.setInfo('Waiting for process...', null, 'DISCONNECTED');
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
UnityWebSocket.prototype.reconnect = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (this.restartRequested)
|
||||
return [2 /*return*/];
|
||||
if (this.disconnected)
|
||||
return [2 /*return*/];
|
||||
this.restartRequested = true;
|
||||
this.stopFetchClocks();
|
||||
if (this.socket != null) {
|
||||
this.socket.close();
|
||||
this.socket = null;
|
||||
}
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(2000)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
if (this.disconnected)
|
||||
return [2 /*return*/];
|
||||
this.message = "Reconnecting in 10 seconds...";
|
||||
this.broadcastState();
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(10000)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
if (this.disconnected)
|
||||
return [2 /*return*/];
|
||||
return [4 /*yield*/, this.connect()];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
UnityWebSocket.prototype.connect = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
this.restartRequested = false;
|
||||
this.disconnected = false;
|
||||
this.stopFetchClocks();
|
||||
this.setInfo('Connecting...', null, 'CONNECTING');
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(1000)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.socket = new ws_1.WebSocket("ws://".concat(this._Main.Config.unity.webSocket.ip, ":").concat(this._Main.Config.unity.webSocket.port));
|
||||
this.socket.on('error', function (error) {
|
||||
if (_this.restartRequested)
|
||||
return;
|
||||
_this.setInfo('Connection error', "Could not connect: ".concat(error.message), 'FAILED');
|
||||
_this.reconnect();
|
||||
});
|
||||
this.socket.on('open', function () {
|
||||
_this.startFetchClocks();
|
||||
_this.setInfo('Connected', null, 'CONNECTED');
|
||||
});
|
||||
this.socket.on('close', function () {
|
||||
if (_this.restartRequested)
|
||||
return;
|
||||
_this.setInfo('Disconnected', 'Unity was disconnected unexpectedly', 'FAILED');
|
||||
_this.reconnect();
|
||||
});
|
||||
this.socket.on('message', function (data) { return _this.handleSocketMessage(data); });
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
UnityWebSocket.prototype.startFetchClocks = function () {
|
||||
var _this = this;
|
||||
this.socket.send(JSON.stringify({ type: 'set_heartbeat_auto_send', autoSend: false }));
|
||||
this.heartbeatClock = setInterval(function () {
|
||||
if (_this.socket == null ||
|
||||
_this.socket.readyState !== ws_1.WebSocket.OPEN)
|
||||
return;
|
||||
_this.socket.send(JSON.stringify({ type: 'request_heartbeat' }));
|
||||
}, this._Main.Config.unity.heartbeatInterval);
|
||||
this.calibrationImageClock = setInterval(function () {
|
||||
if (_this.socket == null ||
|
||||
_this.socket.readyState !== ws_1.WebSocket.OPEN)
|
||||
return;
|
||||
_this.socket.send(JSON.stringify({ type: 'request_camera_frame' }));
|
||||
}, this._Main.Config.unity.calibrationImageInterval);
|
||||
};
|
||||
UnityWebSocket.prototype.getState = function () {
|
||||
return {
|
||||
state: this.state,
|
||||
message: this.message,
|
||||
error: this.error,
|
||||
parameters: this.parameters,
|
||||
};
|
||||
};
|
||||
return UnityWebSocket;
|
||||
}());
|
||||
exports.UnityWebSocket = UnityWebSocket;
|
||||
//# sourceMappingURL=UnityWebSocket.js.map
|
||||
1
dist/Unity/UnityWebSocket.js.map
vendored
Normal file
1
dist/Unity/UnityWebSocket.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user