remoterigs-raspberrypi 0.1.8 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "remoterigs-raspberrypi",
3
3
  "type": "module",
4
- "version": "0.1.8",
4
+ "version": "0.1.9",
5
5
  "main": "./index.js",
6
6
  "files": [
7
7
  "index.js",
@@ -76,6 +76,7 @@ export default class SignalR {
76
76
  }
77
77
  static ScheduleReconnect() {
78
78
  if (SignalR.intentionalStop) {
79
+ 1;
79
80
  return;
80
81
  }
81
82
  if (SignalR.reconnectTimer != null) {
@@ -100,10 +101,10 @@ export default class SignalR {
100
101
  if (SignalR.hubConnection) {
101
102
  SignalR.hubConnection.stop()
102
103
  .then(() => {
103
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), 'hub connection stopped');
104
+ Debug.LogAlways(SignalR.GetName(), 'hub connection stopped', false);
104
105
  })
105
106
  .catch((err) => {
106
- Debug.Error(SignalR.GetName(), err);
107
+ Debug.LogAlways(SignalR.GetName(), "StopConnection err: '" + err + "'", false);
107
108
  });
108
109
  }
109
110
  }
@@ -132,7 +133,7 @@ export default class SignalR {
132
133
  });
133
134
  }
134
135
  else {
135
- Debug.Error(SignalR.GetName(), "sign in canceled: no hub connection");
136
+ Debug.LogAlways(SignalR.GetName(), "sign in canceled: no hub connection", false);
136
137
  }
137
138
  }
138
139
  static UpdateStatus(pStatusModel) {
@@ -151,7 +152,7 @@ export default class SignalR {
151
152
  });
152
153
  }
153
154
  else {
154
- Debug.Error(SignalR.GetName(), "outgoing UpdateStatus: no hub connection");
155
+ Debug.LogAlways(SignalR.GetName(), "outgoing UpdateStatus: no hub connection", false);
155
156
  }
156
157
  }
157
158
  static SendWebRTCMessage(message) {
@@ -166,7 +167,7 @@ export default class SignalR {
166
167
  });
167
168
  }
168
169
  else {
169
- Debug.Error(SignalR.GetName(), "SendWebRTCMessage: no hub connection");
170
+ Debug.LogAlways(SignalR.GetName(), "SendWebRTCMessage: no hub connection", false);
170
171
  }
171
172
  }
172
173
  static AddHighScorePoints(message) {
@@ -181,7 +182,7 @@ export default class SignalR {
181
182
  });
182
183
  }
183
184
  else {
184
- Debug.Error(SignalR.GetName(), "outgoing AddHighScorePoints: no hub connection");
185
+ Debug.LogAlways(SignalR.GetName(), "outgoing AddHighScorePoints: no hub connection", false);
185
186
  }
186
187
  }
187
188
  }
@@ -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
@@ -1,75 +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
- var tStatusModel = new StatusModel();
44
- tStatusModel.type = StatusType.RigLog;
45
- tStatusModel.value = logModel;
46
- SignalR.UpdateStatus(tStatusModel);
47
- }
48
- static GetLogSetting(pLogSettingType, id) {
49
- if (Server.rig != null) {
50
- for (var i = 0; i < Server.rig.rig.logSettings.length; i++) {
51
- if (Server.rig.rig.logSettings[i].logSettingType == pLogSettingType &&
52
- Server.rig.rig.logSettings[i].parameter1 == id) {
53
- return true;
54
- }
55
- }
56
- }
57
- return false;
58
- }
59
- static GetStringValue(logSettingType) {
60
- switch (logSettingType) {
61
- case LogSettingType.BLESensor:
62
- return "BLESensor";
63
- case LogSettingType.Commands:
64
- return "Commands";
65
- case LogSettingType.KeyEvents:
66
- return "KeyEvents";
67
- case LogSettingType.SignalR:
68
- return "SignalR";
69
- case LogSettingType.Component:
70
- return "Component";
71
- }
72
- return "";
73
- }
74
- }
75
- //# sourceMappingURL=debug.js.map
@@ -1,189 +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.LogAlways(SignalR.GetName(), "failed to establish hub connection: " + err, false);
74
- SignalR.ScheduleReconnect();
75
- });
76
- }
77
- static ScheduleReconnect() {
78
- if (SignalR.intentionalStop) {
79
- 1;
80
- return;
81
- }
82
- if (SignalR.reconnectTimer != null) {
83
- return;
84
- }
85
- Debug.LogAlways(SignalR.GetName(), "scheduling reconnect attempt in 30s...", true);
86
- SignalR.reconnectTimer = setTimeout(() => {
87
- SignalR.reconnectTimer = null;
88
- if (SignalR.lastUniqueCode != null && !SignalR.intentionalStop) {
89
- Debug.LogAlways(SignalR.GetName(), "attempting reconnect now...", true);
90
- SignalR.StartConnection(SignalR.lastUniqueCode);
91
- }
92
- }, 30000);
93
- }
94
- static StopConnection() {
95
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "stopping hub connection...");
96
- SignalR.intentionalStop = true;
97
- if (SignalR.reconnectTimer != null) {
98
- clearTimeout(SignalR.reconnectTimer);
99
- SignalR.reconnectTimer = null;
100
- }
101
- if (SignalR.hubConnection) {
102
- SignalR.hubConnection.stop()
103
- .then(() => {
104
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), 'hub connection stopped');
105
- })
106
- .catch((err) => {
107
- Debug.Error(SignalR.GetName(), err);
108
- });
109
- }
110
- }
111
- static IsConnected() {
112
- return SignalR.hubConnection != null && SignalR.hubConnection.state === signalR.HubConnectionState.Connected;
113
- }
114
- static SignIn(uniquecode) {
115
- if (SignalR.hubConnection != null && SignalR.IsConnected()) {
116
- SignalR.hubConnection.invoke('SignIn', uniquecode)
117
- .then((rigClientViewModel) => {
118
- if (rigClientViewModel.rigModelViewModel == undefined) {
119
- Debug.LogAlways(SignalR.GetName(), "sign in to server failed! GUID: " + uniquecode, true);
120
- }
121
- else {
122
- Debug.LogAlways(SignalR.GetName(), "sign in to server successful", true);
123
- Debug.LogAlways(SignalR.GetName(), "rig #" + rigClientViewModel.id + " '" + rigClientViewModel.name + "'", true);
124
- Debug.LogAlways(SignalR.GetName(), "rig model #" + rigClientViewModel.rigModelViewModel.id + " '" + rigClientViewModel.rigModelViewModel.name + "'", true);
125
- Server.rig = new Rig(rigClientViewModel);
126
- Server.rig.CreateComponents();
127
- Server.rig.Init();
128
- Server.rig.SendCurrent();
129
- }
130
- })
131
- .catch((err) => {
132
- Debug.Error(SignalR.GetName(), err);
133
- });
134
- }
135
- else {
136
- Debug.Error(SignalR.GetName(), "sign in canceled: no hub connection");
137
- }
138
- }
139
- static UpdateStatus(pStatusModel) {
140
- if (SignalR.hubConnection != null && SignalR.IsConnected()) {
141
- if (pStatusModel.type != StatusType.RigLog) {
142
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing UpdateStatus type: " + pStatusModel.type);
143
- }
144
- SignalR.hubConnection.invoke('UpdateStatus', pStatusModel)
145
- .then(() => {
146
- if (pStatusModel.type != StatusType.RigLog) {
147
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing UpdateStatus type: " + pStatusModel.type);
148
- }
149
- })
150
- .catch((err) => {
151
- Debug.Error(SignalR.GetName(), "outgoing UpdateStatus error: " + err);
152
- });
153
- }
154
- else {
155
- Debug.Error(SignalR.GetName(), "outgoing UpdateStatus: no hub connection");
156
- }
157
- }
158
- static SendWebRTCMessage(message) {
159
- if (SignalR.hubConnection != null && SignalR.IsConnected()) {
160
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing SendWebRTCMessage rigId: " + message.rigId + " componentId:" + message.componentId + " userName: " + message.userName + " rigOwnerUsername: " + message.rigOwnerUsername);
161
- SignalR.hubConnection.invoke("SendWebRTCMessage", message)
162
- .then(() => {
163
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing SendWebRTCMessage success rigId: " + message.rigId + " componentId:" + message.componentId + " userName: " + message.userName + " rigOwnerUsername: " + message.rigOwnerUsername);
164
- })
165
- .catch((err) => {
166
- Debug.Error(SignalR.GetName(), "outgoing SendWebRTCMessage error: " + err);
167
- });
168
- }
169
- else {
170
- Debug.Error(SignalR.GetName(), "SendWebRTCMessage: no hub connection");
171
- }
172
- }
173
- static AddHighScorePoints(message) {
174
- if (SignalR.hubConnection != null && SignalR.IsConnected()) {
175
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing AddHighScorePoints: " + JSON.stringify(message));
176
- SignalR.hubConnection.invoke("AddHighScorePoints", message)
177
- .then(() => {
178
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing AddHighScorePoints success: " + JSON.stringify(message));
179
- })
180
- .catch((err) => {
181
- Debug.Error(SignalR.GetName(), "outgoing AddHighScorePoints error: " + err);
182
- });
183
- }
184
- else {
185
- Debug.Error(SignalR.GetName(), "outgoing AddHighScorePoints: no hub connection");
186
- }
187
- }
188
- }
189
- //# sourceMappingURL=signalr.js.map