remoterigs-raspberrypi 0.1.2 → 0.1.4

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/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  import Server from './src/server.js';
2
2
  var server = new Server();
3
- server.Start();
3
+ const configPath = process.argv[2];
4
+
5
+ server.Start(configPath);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "remoterigs-raspberrypi",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "main": "./index.js",
6
6
  "files": [
7
7
  "index.js",
@@ -1,8 +1,8 @@
1
- import { exec } from "child_process";
2
1
  import * as signalR from '@microsoft/signalr';
3
2
  import Server from './../server.js';
4
3
  import Debug from './debug.js';
5
4
  import Rig from '../rig.js';
5
+ import { exec } from "child_process";
6
6
  import { LogSettingType, CommandType, StatusType } from '../models/models.js';
7
7
  export default class SignalR {
8
8
  static { this.hubConnection = null; }
@@ -33,7 +33,7 @@ export default class SignalR {
33
33
  if (Server.rig.rig.id !== webRTCMessage.rigId) {
34
34
  Debug.Error(SignalR.GetName(), "incoming web-rtc-message error Server.rig.rig.id (" + Server.rig.rig.id + ") !== message.rigId (" + webRTCMessage.rigId + ")");
35
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);
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
37
  Server.rig.PutWebRTCMessage(webRTCMessage);
38
38
  }
39
39
  else {
@@ -47,7 +47,7 @@ export default class SignalR {
47
47
  SignalR.SignIn(uniquecode);
48
48
  break;
49
49
  case CommandType.RigShutdown:
50
- Debug.LogAlways("Raspberry Pi", "SHUTTING DOWN!", true);
50
+ Debug.LogAlways("Raspberry Pi", "SHUTTING DOWN! (received command)", true);
51
51
  exec("shutdown now");
52
52
  break;
53
53
  }
@@ -115,17 +115,16 @@ export default class SignalR {
115
115
  SignalR.hubConnection.invoke('SignIn', uniquecode)
116
116
  .then((rigClientViewModel) => {
117
117
  if (rigClientViewModel.rigModelViewModel == undefined) {
118
- Debug.LogAlways(SignalR.GetName(), "SignIn failed!! GUID: " + uniquecode, true);
118
+ Debug.LogAlways(SignalR.GetName(), "sign in to server failed! GUID: " + uniquecode, true);
119
119
  }
120
120
  else {
121
- Debug.LogAlways(SignalR.GetName(), "SignIn successful", true);
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);
122
124
  Server.rig = new Rig(rigClientViewModel);
123
125
  Server.rig.CreateComponents();
124
- Debug.LogAlways(SignalR.GetName(), "Rig components loaded", true);
125
126
  Server.rig.Init();
126
- Debug.LogAlways(SignalR.GetName(), "Rig 'Init' functions executed", true);
127
127
  Server.rig.SendCurrent();
128
- Debug.LogAlways(SignalR.GetName(), "Rig current status send", true);
129
128
  }
130
129
  })
131
130
  .catch((err) => {
@@ -133,7 +132,7 @@ export default class SignalR {
133
132
  });
134
133
  }
135
134
  else {
136
- Debug.Error(SignalR.GetName(), "outgoing SignIn: no hub connection");
135
+ Debug.Error(SignalR.GetName(), "sign in canceled: no hub connection");
137
136
  }
138
137
  }
139
138
  static UpdateStatus(pStatusModel) {
@@ -157,10 +156,10 @@ export default class SignalR {
157
156
  }
158
157
  static SendWebRTCMessage(message) {
159
158
  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);
159
+ Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing SendWebRTCMessage rigId: " + message.rigId + " componentId:" + message.componentId + " userName: " + message.userName + " rigOwnerUsername: " + message.rigOwnerUsername);
161
160
  SignalR.hubConnection.invoke("SendWebRTCMessage", message)
162
161
  .then(() => {
163
- Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing SendWebRTCMessage success rigId: " + message.rigId + " componentId:" + message.componentId + " username: " + message.username + " rigOwnerUsername: " + message.rigOwnerUsername);
162
+ Debug.Log(LogSettingType.SignalR, undefined, SignalR.GetName(), "outgoing SendWebRTCMessage success rigId: " + message.rigId + " componentId:" + message.componentId + " userName: " + message.userName + " rigOwnerUsername: " + message.rigOwnerUsername);
164
163
  })
165
164
  .catch((err) => {
166
165
  Debug.Error(SignalR.GetName(), "outgoing SendWebRTCMessage error: " + err);
@@ -47,7 +47,7 @@ export default class WebRTCStreamerWrapper {
47
47
  }
48
48
  async PutWebRTCMessage(message) {
49
49
  if (this.streamerStarted) {
50
- this.Log("PutWebRTCMessage username: " + message.username + " messageType: " + message.messageType);
50
+ this.Log("PutWebRTCMessage userName: " + message.userName + " messageType: " + message.messageType);
51
51
  if (message.messageType == "getIceServers") {
52
52
  await this.GetIceServers(message);
53
53
  }
@@ -88,7 +88,7 @@ export default class WebRTCStreamerWrapper {
88
88
  }
89
89
  }
90
90
  else {
91
- this.Log("IGNORED! PutWebRTCMessage username: " + message.username + " messageType: " + message.messageType);
91
+ this.Log("IGNORED! PutWebRTCMessage userName: " + message.userName + " messageType: " + message.messageType);
92
92
  }
93
93
  }
94
94
  async StartWebRTCStreamer() {
@@ -189,7 +189,7 @@ export default class WebRTCStreamerWrapper {
189
189
  webrtcMessage.rigId = message.rigId;
190
190
  webrtcMessage.webRTCConnectionType = message.webRTCConnectionType;
191
191
  webrtcMessage.sessionId = message.sessionId;
192
- webrtcMessage.username = message.username;
192
+ webrtcMessage.userName = message.userName;
193
193
  webrtcMessage.rigOwnerUsername = message.rigOwnerUsername;
194
194
  webrtcMessage.messageType = 'getIceServersResponse';
195
195
  webrtcMessage.message = JSON.stringify(response.data);
@@ -249,13 +249,13 @@ export default class WebRTCStreamerWrapper {
249
249
  webrtcMessage.rigId = message.rigId;
250
250
  webrtcMessage.sessionId = message.sessionId;
251
251
  webrtcMessage.webRTCConnectionType = message.webRTCConnectionType;
252
- webrtcMessage.username = message.username;
252
+ webrtcMessage.userName = message.userName;
253
253
  webrtcMessage.rigOwnerUsername = message.rigOwnerUsername;
254
254
  webrtcMessage.messageType = 'onReceiveCall';
255
255
  webrtcMessage.message = JSON.stringify(response.data);
256
256
  SignalR.SendWebRTCMessage(webrtcMessage);
257
257
  // Start polling voor ICE candidates van de server
258
- this.StartIceCandidatePolling(message.sessionId, message.rigId, message.username, message.rigOwnerUsername, message.webRTCConnectionType);
258
+ this.StartIceCandidatePolling(message.sessionId, message.rigId, message.userName, message.rigOwnerUsername, message.webRTCConnectionType);
259
259
  }
260
260
  else {
261
261
  this.Error("devicePath is empty");
@@ -324,7 +324,7 @@ export default class WebRTCStreamerWrapper {
324
324
  webrtcMessage.rigId = message.rigId;
325
325
  webrtcMessage.webRTCConnectionType = message.webRTCConnectionType;
326
326
  webrtcMessage.sessionId = message.sessionId;
327
- webrtcMessage.username = message.username;
327
+ webrtcMessage.userName = message.userName;
328
328
  webrtcMessage.rigOwnerUsername = message.rigOwnerUsername;
329
329
  webrtcMessage.messageType = 'receiveOffer';
330
330
  //webrtcMessage.message = JSON.stringify(response.data);
@@ -355,7 +355,7 @@ export default class WebRTCStreamerWrapper {
355
355
  const response = await this.streamerClient.post(setAnswerUrl, tJSON);
356
356
  this.Log("SetAnswer Response status: " + response.status);
357
357
  this.Log("SetAnswer Response data:\\r\\n" + JSON.stringify(response.data?.sdp));
358
- this.StartIceCandidatePolling(message.sessionId, message.rigId, message.username, message.rigOwnerUsername, message.webRTCConnectionType);
358
+ this.StartIceCandidatePolling(message.sessionId, message.rigId, message.userName, message.rigOwnerUsername, message.webRTCConnectionType);
359
359
  }
360
360
  catch (err) {
361
361
  if (err.response) {
@@ -365,7 +365,7 @@ export default class WebRTCStreamerWrapper {
365
365
  this.Error("SetAnswer Call error: " + err.message);
366
366
  }
367
367
  }
368
- StartIceCandidatePolling(peerId, rigId, username, rigOwnerUsername, webRTCConnectionType) {
368
+ StartIceCandidatePolling(peerId, rigId, userName, rigOwnerUsername, webRTCConnectionType) {
369
369
  // Stop eventuele bestaande polling voor deze peer
370
370
  this.StopIceCandidatePolling(peerId);
371
371
  // Initialiseer candidate tracking voor deze peer
@@ -401,7 +401,7 @@ export default class WebRTCStreamerWrapper {
401
401
  webrtcMessage.rigId = rigId;
402
402
  webrtcMessage.sessionId = peerId;
403
403
  webrtcMessage.webRTCConnectionType = webRTCConnectionType;
404
- webrtcMessage.username = username;
404
+ webrtcMessage.userName = userName;
405
405
  webrtcMessage.rigOwnerUsername = rigOwnerUsername;
406
406
  webrtcMessage.messageType = 'onReceiveCandidate';
407
407
  webrtcMessage.message = JSON.stringify(candidate);
@@ -193,7 +193,7 @@ export default class Component {
193
193
  }
194
194
  PutWebRTCMessage(message) {
195
195
  if (this.component.id == message.componentId) {
196
- this.Log("PutWebRTCMessage username: " + message.username + " rigOwnerUsername: " + message.rigOwnerUsername);
196
+ this.Log("PutWebRTCMessage userName: " + message.userName + " rigOwnerUsername: " + message.rigOwnerUsername);
197
197
  if (this.streamer != null) {
198
198
  this.streamer.PutWebRTCMessage(message);
199
199
  }
@@ -224,7 +224,7 @@ export class WebRTCMessage {
224
224
  this.componentId = _data["componentId"];
225
225
  this.webRTCConnectionType = _data["webRTCConnectionType"];
226
226
  this.sessionId = _data["sessionId"];
227
- this.username = _data["username"];
227
+ this.userName = _data["userName"];
228
228
  this.messageType = _data["messageType"];
229
229
  this.message = _data["message"];
230
230
  }
@@ -242,7 +242,7 @@ export class WebRTCMessage {
242
242
  data["componentId"] = this.componentId;
243
243
  data["webRTCConnectionType"] = this.webRTCConnectionType;
244
244
  data["sessionId"] = this.sessionId;
245
- data["username"] = this.username;
245
+ data["userName"] = this.userName;
246
246
  data["messageType"] = this.messageType;
247
247
  data["message"] = this.message;
248
248
  return data;
package/src/rig.js CHANGED
@@ -13,10 +13,10 @@ export default class Rig {
13
13
  }
14
14
  Debug.LogAlways("#" + this.rig.logSettings[i].id + " log setting", text, true);
15
15
  }
16
- Debug.LogAlways(this.GetName(), "Rig instance '" + this.rig.name + "' created", true);
16
+ Debug.LogAlways(this.GetName(), "rig instance created & log settings loaded", true);
17
17
  }
18
18
  CreateComponents() {
19
- Debug.LogAlways(this.GetName(), "CreateComponents this.rig.rigModelViewModel.components.length: " + this.rig.rigModelViewModel.components.length, true);
19
+ Debug.LogAlways(this.GetName(), "creating components for rig (" + this.rig.rigModelViewModel.components.length + " component(s))", true);
20
20
  for (var i = 0; i < this.rig.rigModelViewModel.components.length; i++) {
21
21
  try {
22
22
  this.components.push(new Component(this, this.rig.rigModelViewModel.components[i], this.rig.clientRTCConfigurationViewModel, null));
@@ -25,11 +25,13 @@ export default class Rig {
25
25
  Debug.Error(this.GetName(), "FAILED TO CREATE CHILD COMPONENT: " + ex);
26
26
  }
27
27
  }
28
+ Debug.LogAlways(this.GetName(), "rig components created", true);
28
29
  }
29
30
  Init() {
30
31
  for (var i = 0; i < this.components.length; i++) {
31
32
  this.components[i].Init();
32
33
  }
34
+ Debug.LogAlways(this.GetName(), "rig 'init' functions executed", true);
33
35
  }
34
36
  Shutdown() {
35
37
  for (var i = 0; i < this.components.length; i++) {
@@ -47,6 +49,7 @@ export default class Rig {
47
49
  for (var i = 0; i < this.components.length; i++) {
48
50
  this.components[i].SendCurrent();
49
51
  }
52
+ Debug.LogAlways(this.GetName(), "rig current status send to server", true);
50
53
  }
51
54
  ProcessKeyEvent(event) {
52
55
  for (var i = 0; i < this.components.length; i++) {
package/src/server.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import fs from 'fs';
3
3
  import Debug from './common/debug.js';
4
4
  import SignalR from './common/signalr.js';
5
+ import { config } from 'process';
5
6
  export default class Server {
6
7
  static { this.signalr = ""; }
7
8
  static { this.rig = null; }
@@ -17,56 +18,41 @@ export default class Server {
17
18
  }
18
19
  });
19
20
  }
20
- Start() {
21
+ Start(configPath) {
21
22
  //this.InitHandlers();
22
- fs.readFile("config.json", 'utf8', (error, data) => {
23
+ if (configPath == undefined || configPath == "" || config == null) {
24
+ Debug.Error(this.GetName(), "config file path is missing");
25
+ return;
26
+ }
27
+ fs.readFile(configPath, 'utf8', (error, data) => {
23
28
  if (error != undefined) {
24
- Debug.Error(this.GetName(), 'Error reading config: ' + error);
29
+ Debug.Error(this.GetName(), 'error reading config: ' + error);
25
30
  return;
26
31
  }
27
32
  try {
28
33
  this.Load(JSON.parse(data));
29
34
  }
30
35
  catch (parseError) {
31
- Debug.Error(this.GetName(), 'Error parsing config: ' + parseError);
36
+ Debug.Error(this.GetName(), 'error parsing config: ' + parseError);
32
37
  }
33
38
  this.SetupVariables();
34
39
  SignalR.StartConnection(Server.rig_uniquecode);
35
40
  });
36
41
  }
37
- //private InitHandlers(): void {
38
- // process.on('exit', this.OnExit);
39
- // process.on('SIGINT', this.OnSigInt);
40
- // process.on('SIGTERM', this.OnSigTerm);
41
- //}
42
- //private OnExit(code: any) {
43
- // Debug.LogAlways(this.GetName(), `exit-code: ${code}`);
44
- // this.Shutdown();
45
- //}
46
- //private OnSigInt() {
47
- // Debug.LogAlways(this.GetName(), "SIGINT received (ctrl + c)");
48
- // this.Shutdown();
49
- // process.exit();
50
- //}
51
- //private OnSigTerm() {
52
- // Debug.LogAlways(this.GetName(), "SIGTERM received");
53
- // this.Shutdown();
54
- // process.exit();
55
- //}
56
42
  Load(config) {
57
43
  // Server
58
44
  if (config.server.url != undefined) {
59
45
  Server.serverurl = config.server.url;
60
46
  }
61
47
  else {
62
- Debug.Error(this.GetName(), "Server IP address is not defined in config.json");
48
+ Debug.Error(this.GetName(), "server ip address is not defined in config.json");
63
49
  }
64
50
  // rig
65
51
  if (config.rig?.uniquecode != undefined) {
66
52
  Server.rig_uniquecode = config.rig.uniquecode;
67
53
  }
68
54
  else {
69
- Debug.Error(this.GetName(), "Rig unique code is not defined in config.json");
55
+ Debug.Error(this.GetName(), "rig unique code is not defined in config.json");
70
56
  }
71
57
  }
72
58
  Shutdown() {
@@ -0,0 +1,62 @@
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
@@ -0,0 +1,77 @@
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
@@ -0,0 +1,188 @@
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