remoterigs-raspberrypi 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/common/debug.js +4 -6
- package/src/common/signalr.js +1 -1
- package/src/server.js +1 -0
- package/src/src/common/code.js +0 -62
- package/src/src/common/debug.js +0 -77
- package/src/src/common/signalr.js +0 -188
- package/src/src/common/webrtc-streamer-wrapper.js +0 -483
- package/src/src/component/component.js +0 -358
- package/src/src/component/input/input.js +0 -26
- package/src/src/component/pin/pin.js +0 -92
- package/src/src/component/property/property.js +0 -32
- package/src/src/component/status/status-number.js +0 -7
- package/src/src/component/status/status-state.js +0 -27
- package/src/src/component/status/status.js +0 -41
- package/src/src/models/models.js +0 -1045
- package/src/src/rig.js +0 -68
- package/src/src/server.js +0 -73
package/package.json
CHANGED
package/src/common/debug.js
CHANGED
|
@@ -40,12 +40,10 @@ export default class Debug {
|
|
|
40
40
|
Debug.error_callback();
|
|
41
41
|
}
|
|
42
42
|
static SendLogModel(logModel) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
SignalR.UpdateStatus(tStatusModel);
|
|
48
|
-
}
|
|
43
|
+
var tStatusModel = new StatusModel();
|
|
44
|
+
tStatusModel.type = StatusType.RigLog;
|
|
45
|
+
tStatusModel.value = logModel;
|
|
46
|
+
SignalR.UpdateStatus(tStatusModel);
|
|
49
47
|
}
|
|
50
48
|
static GetLogSetting(pLogSettingType, id) {
|
|
51
49
|
if (Server.rig != null) {
|
package/src/common/signalr.js
CHANGED
|
@@ -70,7 +70,7 @@ export default class SignalR {
|
|
|
70
70
|
SignalR.SignIn(uniquecode);
|
|
71
71
|
})
|
|
72
72
|
.catch((err) => {
|
|
73
|
-
Debug.
|
|
73
|
+
Debug.LogAlways(SignalR.GetName(), "failed to establish hub connection: " + err, false);
|
|
74
74
|
SignalR.ScheduleReconnect();
|
|
75
75
|
});
|
|
76
76
|
}
|
package/src/server.js
CHANGED
package/src/src/common/code.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import vm from "vm";
|
|
2
|
-
import SignalR from "./signalr.js";
|
|
3
|
-
export default class Code {
|
|
4
|
-
static GetComponentContext(component) {
|
|
5
|
-
return {
|
|
6
|
-
SetCallback: component.SetCallback,
|
|
7
|
-
SetStatus: component.SetStatus,
|
|
8
|
-
SetStatusState: component.SetStatusState,
|
|
9
|
-
GetStatus: component.GetStatus,
|
|
10
|
-
GetStatusState: component.GetStatusState,
|
|
11
|
-
GetName: component.GetName,
|
|
12
|
-
GetStorageName: component.GetStorageName,
|
|
13
|
-
GetChild: component.GetChild,
|
|
14
|
-
Log: component.Log,
|
|
15
|
-
LogAlways: component.LogAlways,
|
|
16
|
-
Error: component.Error,
|
|
17
|
-
GetProperty: component.GetProperty,
|
|
18
|
-
GetPropertyNumber: component.GetPropertyNumber,
|
|
19
|
-
SetTimeOut: component.SetTimeOut,
|
|
20
|
-
ResetTimeOut: component.ResetTimeOut,
|
|
21
|
-
IsEventInput: component.IsEventInput,
|
|
22
|
-
child: component.child,
|
|
23
|
-
property: component.property,
|
|
24
|
-
input: component.input,
|
|
25
|
-
component: component.component,
|
|
26
|
-
pin: component.pin,
|
|
27
|
-
status: component.status,
|
|
28
|
-
boolean: component.boolean,
|
|
29
|
-
number: component.number,
|
|
30
|
-
string: component.string,
|
|
31
|
-
timeout: component.timeout,
|
|
32
|
-
streamer: component.streamer,
|
|
33
|
-
callback: component.callback
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/* (code: string, sandboxVars: SandboxVars): any {*/
|
|
37
|
-
/**
|
|
38
|
-
* Voert dynamische code uit in een veilige VM-sandbox.
|
|
39
|
-
* Geeft nette foutmeldingen met regelnummers.
|
|
40
|
-
*
|
|
41
|
-
* @param code - De code die moet worden uitgevoerd.
|
|
42
|
-
* @param contextVars - Variabelen die zichtbaar moeten zijn in de sandbox.
|
|
43
|
-
*/
|
|
44
|
-
static runSandboxed(code, contextVars = {}) {
|
|
45
|
-
const sandbox = {
|
|
46
|
-
SignalR: SignalR,
|
|
47
|
-
console,
|
|
48
|
-
...contextVars,
|
|
49
|
-
};
|
|
50
|
-
const context = vm.createContext(sandbox);
|
|
51
|
-
try {
|
|
52
|
-
return vm.runInContext(code, context, {
|
|
53
|
-
filename: "dynamic.js",
|
|
54
|
-
displayErrors: true,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
throw err; // laat native stacktrace intact
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=code.js.map
|
package/src/src/common/debug.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { LogModel, LogSettingType, StatusModel, StatusType } from '../models/models.js';
|
|
2
|
-
import Server from "../server.js";
|
|
3
|
-
import SignalR from "./signalr.js";
|
|
4
|
-
export default class Debug {
|
|
5
|
-
// Timings
|
|
6
|
-
static { this.watchdogtimer = 1000; }
|
|
7
|
-
static { this.pwmdelay = 100; }
|
|
8
|
-
static { this.pwmstart = 120; }
|
|
9
|
-
static { this.pwm_frequency = 800; }
|
|
10
|
-
static { this.pwm_dutycycle_max = 1000000; }
|
|
11
|
-
static { this.time_to_full_speed_ms = 10000; }
|
|
12
|
-
static { this.commandtimer = 500; }
|
|
13
|
-
static SetErrorCallback(callback_param) {
|
|
14
|
-
Debug.error_callback = callback_param;
|
|
15
|
-
}
|
|
16
|
-
static Log(pVehicleSettingType, id, name, message) {
|
|
17
|
-
if (Debug.GetLogSetting(pVehicleSettingType, id)) {
|
|
18
|
-
Debug.LogAlways(name, message, true);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
static LogAlways(name, message, signalr) {
|
|
22
|
-
var date = new Date();
|
|
23
|
-
if (signalr) {
|
|
24
|
-
var logModel = new LogModel();
|
|
25
|
-
logModel.dateTime = date;
|
|
26
|
-
logModel.name = name;
|
|
27
|
-
logModel.message = message;
|
|
28
|
-
Debug.SendLogModel(logModel);
|
|
29
|
-
}
|
|
30
|
-
console.log(date.toLocaleTimeString() + " / " + name + " / " + message);
|
|
31
|
-
}
|
|
32
|
-
static Error(name, message) {
|
|
33
|
-
var date = new Date();
|
|
34
|
-
var logModel = new LogModel();
|
|
35
|
-
logModel.dateTime = date;
|
|
36
|
-
logModel.name = name;
|
|
37
|
-
logModel.message = message;
|
|
38
|
-
Debug.SendLogModel(logModel);
|
|
39
|
-
console.error(date.toLocaleTimeString() + " / " + name + " / " + message);
|
|
40
|
-
Debug.error_callback();
|
|
41
|
-
}
|
|
42
|
-
static SendLogModel(logModel) {
|
|
43
|
-
if (Server.rig != null) {
|
|
44
|
-
var tStatusModel = new StatusModel();
|
|
45
|
-
tStatusModel.type = StatusType.RigLog;
|
|
46
|
-
tStatusModel.value = logModel;
|
|
47
|
-
SignalR.UpdateStatus(tStatusModel);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
static GetLogSetting(pLogSettingType, id) {
|
|
51
|
-
if (Server.rig != null) {
|
|
52
|
-
for (var i = 0; i < Server.rig.rig.logSettings.length; i++) {
|
|
53
|
-
if (Server.rig.rig.logSettings[i].logSettingType == pLogSettingType &&
|
|
54
|
-
Server.rig.rig.logSettings[i].parameter1 == id) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
static GetStringValue(logSettingType) {
|
|
62
|
-
switch (logSettingType) {
|
|
63
|
-
case LogSettingType.BLESensor:
|
|
64
|
-
return "BLESensor";
|
|
65
|
-
case LogSettingType.Commands:
|
|
66
|
-
return "Commands";
|
|
67
|
-
case LogSettingType.KeyEvents:
|
|
68
|
-
return "KeyEvents";
|
|
69
|
-
case LogSettingType.SignalR:
|
|
70
|
-
return "SignalR";
|
|
71
|
-
case LogSettingType.Component:
|
|
72
|
-
return "Component";
|
|
73
|
-
}
|
|
74
|
-
return "";
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=debug.js.map
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import * as signalR from '@microsoft/signalr';
|
|
2
|
-
import Server from './../server.js';
|
|
3
|
-
import Debug from './debug.js';
|
|
4
|
-
import Rig from '../rig.js';
|
|
5
|
-
import { exec } from "child_process";
|
|
6
|
-
import { LogSettingType, CommandType, StatusType } from '../models/models.js';
|
|
7
|
-
export default class SignalR {
|
|
8
|
-
static { this.hubConnection = null; }
|
|
9
|
-
static { this.reconnectTimer = null; }
|
|
10
|
-
static { this.lastUniqueCode = null; }
|
|
11
|
-
static { this.intentionalStop = false; }
|
|
12
|
-
static GetName() {
|
|
13
|
-
return "SignalR";
|
|
14
|
-
}
|
|
15
|
-
static StartConnection(uniquecode) {
|
|
16
|
-
SignalR.lastUniqueCode = uniquecode;
|
|
17
|
-
SignalR.intentionalStop = false;
|
|
18
|
-
Debug.LogAlways(SignalR.GetName(), "initiating hub connection... url: '" + Server.signalr + "'", false);
|
|
19
|
-
SignalR.hubConnection = new signalR.HubConnectionBuilder()
|
|
20
|
-
.withUrl(Server.signalr)
|
|
21
|
-
.withAutomaticReconnect()
|
|
22
|
-
.build();
|
|
23
|
-
SignalR.hubConnection.on('keyevent', (keyEventClientModel) => {
|
|
24
|
-
if (Server.rig != null) {
|
|
25
|
-
Server.rig.ProcessKeyEvent(keyEventClientModel);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
Debug.LogAlways(SignalR.GetName(), "no rig to process keyevent", true);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
SignalR.hubConnection.on("web-rtc-message", async (webRTCMessage) => {
|
|
32
|
-
if (Server.rig != null) {
|
|
33
|
-
if (Server.rig.rig.id !== webRTCMessage.rigId) {
|
|
34
|
-
Debug.Error(SignalR.GetName(), "incoming web-rtc-message error Server.rig.rig.id (" + Server.rig.rig.id + ") !== message.rigId (" + webRTCMessage.rigId + ")");
|
|
35
|
-
}
|
|
36
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "incoming web-rtc-message rigId:" + webRTCMessage.rigId + " componentId:" + webRTCMessage.componentId + " userName: " + webRTCMessage.userName + " rigOwnerUsername: " + webRTCMessage.rigOwnerUsername);
|
|
37
|
-
Server.rig.PutWebRTCMessage(webRTCMessage);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
Debug.LogAlways(SignalR.GetName(), "no rig to process webrtc message", true);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
SignalR.hubConnection.on("send-command", async (commandMessage) => {
|
|
44
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "incoming message: " + JSON.stringify(commandMessage));
|
|
45
|
-
switch (commandMessage.type) {
|
|
46
|
-
case CommandType.RigReloadRigModel:
|
|
47
|
-
SignalR.SignIn(uniquecode);
|
|
48
|
-
break;
|
|
49
|
-
case CommandType.RigShutdown:
|
|
50
|
-
Debug.LogAlways("Raspberry Pi", "SHUTTING DOWN! (received command)", true);
|
|
51
|
-
exec("shutdown now");
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
SignalR.hubConnection.onreconnecting((error) => {
|
|
56
|
-
Debug.LogAlways(SignalR.GetName(), "hub connection lost, attempting to reconnect..." + (error ? (" reason: " + error) : ""), true);
|
|
57
|
-
});
|
|
58
|
-
SignalR.hubConnection.onreconnected(() => {
|
|
59
|
-
Debug.LogAlways(SignalR.GetName(), "hub connection reconnected, re-signing in...", true);
|
|
60
|
-
SignalR.SignIn(uniquecode);
|
|
61
|
-
});
|
|
62
|
-
SignalR.hubConnection.onclose((error) => {
|
|
63
|
-
Debug.LogAlways(SignalR.GetName(), "hub connection closed" + (error ? (": " + error) : ""), true);
|
|
64
|
-
SignalR.ScheduleReconnect();
|
|
65
|
-
});
|
|
66
|
-
SignalR.hubConnection
|
|
67
|
-
.start()
|
|
68
|
-
.then(() => {
|
|
69
|
-
Debug.LogAlways(SignalR.GetName(), 'hub connection established', false);
|
|
70
|
-
SignalR.SignIn(uniquecode);
|
|
71
|
-
})
|
|
72
|
-
.catch((err) => {
|
|
73
|
-
Debug.Error(SignalR.GetName(), err);
|
|
74
|
-
SignalR.ScheduleReconnect();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
static ScheduleReconnect() {
|
|
78
|
-
if (SignalR.intentionalStop) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (SignalR.reconnectTimer != null) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
Debug.LogAlways(SignalR.GetName(), "scheduling reconnect attempt in 30s...", true);
|
|
85
|
-
SignalR.reconnectTimer = setTimeout(() => {
|
|
86
|
-
SignalR.reconnectTimer = null;
|
|
87
|
-
if (SignalR.lastUniqueCode != null && !SignalR.intentionalStop) {
|
|
88
|
-
Debug.LogAlways(SignalR.GetName(), "attempting reconnect now...", true);
|
|
89
|
-
SignalR.StartConnection(SignalR.lastUniqueCode);
|
|
90
|
-
}
|
|
91
|
-
}, 30000);
|
|
92
|
-
}
|
|
93
|
-
static StopConnection() {
|
|
94
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "stopping hub connection...");
|
|
95
|
-
SignalR.intentionalStop = true;
|
|
96
|
-
if (SignalR.reconnectTimer != null) {
|
|
97
|
-
clearTimeout(SignalR.reconnectTimer);
|
|
98
|
-
SignalR.reconnectTimer = null;
|
|
99
|
-
}
|
|
100
|
-
if (SignalR.hubConnection) {
|
|
101
|
-
SignalR.hubConnection.stop()
|
|
102
|
-
.then(() => {
|
|
103
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), 'hub connection stopped');
|
|
104
|
-
})
|
|
105
|
-
.catch((err) => {
|
|
106
|
-
Debug.Error(SignalR.GetName(), err);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
static IsConnected() {
|
|
111
|
-
return SignalR.hubConnection != null && SignalR.hubConnection.state === signalR.HubConnectionState.Connected;
|
|
112
|
-
}
|
|
113
|
-
static SignIn(uniquecode) {
|
|
114
|
-
if (SignalR.hubConnection != null && SignalR.IsConnected()) {
|
|
115
|
-
SignalR.hubConnection.invoke('SignIn', uniquecode)
|
|
116
|
-
.then((rigClientViewModel) => {
|
|
117
|
-
if (rigClientViewModel.rigModelViewModel == undefined) {
|
|
118
|
-
Debug.LogAlways(SignalR.GetName(), "sign in to server failed! GUID: " + uniquecode, true);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
Debug.LogAlways(SignalR.GetName(), "sign in to server successful", true);
|
|
122
|
-
Debug.LogAlways(SignalR.GetName(), "rig #" + rigClientViewModel.id + " '" + rigClientViewModel.name + "'", true);
|
|
123
|
-
Debug.LogAlways(SignalR.GetName(), "rig model #" + rigClientViewModel.rigModelViewModel.id + " '" + rigClientViewModel.rigModelViewModel.name + "'", true);
|
|
124
|
-
Server.rig = new Rig(rigClientViewModel);
|
|
125
|
-
Server.rig.CreateComponents();
|
|
126
|
-
Server.rig.Init();
|
|
127
|
-
Server.rig.SendCurrent();
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
.catch((err) => {
|
|
131
|
-
Debug.Error(SignalR.GetName(), err);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
Debug.Error(SignalR.GetName(), "sign in canceled: no hub connection");
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
static UpdateStatus(pStatusModel) {
|
|
139
|
-
if (SignalR.hubConnection != null && SignalR.IsConnected()) {
|
|
140
|
-
if (pStatusModel.type != StatusType.RigLog) {
|
|
141
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing UpdateStatus type: " + pStatusModel.type);
|
|
142
|
-
}
|
|
143
|
-
SignalR.hubConnection.invoke('UpdateStatus', pStatusModel)
|
|
144
|
-
.then(() => {
|
|
145
|
-
if (pStatusModel.type != StatusType.RigLog) {
|
|
146
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing UpdateStatus type: " + pStatusModel.type);
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
.catch((err) => {
|
|
150
|
-
Debug.Error(SignalR.GetName(), "outgoing UpdateStatus error: " + err);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
Debug.Error(SignalR.GetName(), "outgoing UpdateStatus: no hub connection");
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
static SendWebRTCMessage(message) {
|
|
158
|
-
if (SignalR.hubConnection != null && SignalR.IsConnected()) {
|
|
159
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing SendWebRTCMessage rigId: " + message.rigId + " componentId:" + message.componentId + " userName: " + message.userName + " rigOwnerUsername: " + message.rigOwnerUsername);
|
|
160
|
-
SignalR.hubConnection.invoke("SendWebRTCMessage", message)
|
|
161
|
-
.then(() => {
|
|
162
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing SendWebRTCMessage success rigId: " + message.rigId + " componentId:" + message.componentId + " userName: " + message.userName + " rigOwnerUsername: " + message.rigOwnerUsername);
|
|
163
|
-
})
|
|
164
|
-
.catch((err) => {
|
|
165
|
-
Debug.Error(SignalR.GetName(), "outgoing SendWebRTCMessage error: " + err);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
Debug.Error(SignalR.GetName(), "SendWebRTCMessage: no hub connection");
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
static AddHighScorePoints(message) {
|
|
173
|
-
if (SignalR.hubConnection != null && SignalR.IsConnected()) {
|
|
174
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing AddHighScorePoints: " + JSON.stringify(message));
|
|
175
|
-
SignalR.hubConnection.invoke("AddHighScorePoints", message)
|
|
176
|
-
.then(() => {
|
|
177
|
-
Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing AddHighScorePoints success: " + JSON.stringify(message));
|
|
178
|
-
})
|
|
179
|
-
.catch((err) => {
|
|
180
|
-
Debug.Error(SignalR.GetName(), "outgoing AddHighScorePoints error: " + err);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
Debug.Error(SignalR.GetName(), "outgoing AddHighScorePoints: no hub connection");
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
//# sourceMappingURL=signalr.js.map
|