remoterigs-raspberrypi 0.1.0

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/src/rig.js ADDED
@@ -0,0 +1,65 @@
1
+ import Component from './component/component.js';
2
+ import Debug from './common/debug.js';
3
+ import SignalR from './common/signalr.js';
4
+ import { StatusModel, StatusType, RigModelLoadedModel } from './models/models.js';
5
+ export default class Rig {
6
+ constructor(rigModel) {
7
+ this.rig = rigModel;
8
+ this.components = new Array();
9
+ for (var i = 0; i < this.rig.logSettings.length; i++) {
10
+ var text = "logSettingType: " + Debug.GetStringValue(this.rig.logSettings[i].logSettingType);
11
+ if (this.rig.logSettings[i].parameter1 != undefined) {
12
+ text += " / parameter1: " + this.rig.logSettings[i].parameter1;
13
+ }
14
+ Debug.LogAlways("#" + this.rig.logSettings[i].id + " log setting", text, true);
15
+ }
16
+ Debug.LogAlways(this.GetName(), "Rig instance '" + this.rig.name + "' created", true);
17
+ }
18
+ CreateComponents() {
19
+ Debug.LogAlways(this.GetName(), "CreateComponents this.rig.rigModelViewModel.components.length: " + this.rig.rigModelViewModel.components.length, true);
20
+ for (var i = 0; i < this.rig.rigModelViewModel.components.length; i++) {
21
+ try {
22
+ this.components.push(new Component(this, this.rig.rigModelViewModel.components[i], this.rig.clientRTCConfigurationViewModel, null));
23
+ }
24
+ catch (ex) {
25
+ Debug.Error(this.GetName(), "FAILED TO CREATE CHILD COMPONENT: " + ex);
26
+ }
27
+ }
28
+ }
29
+ Init() {
30
+ for (var i = 0; i < this.components.length; i++) {
31
+ this.components[i].Init();
32
+ }
33
+ }
34
+ Shutdown() {
35
+ for (var i = 0; i < this.components.length; i++) {
36
+ this.components[i].Shutdown();
37
+ }
38
+ }
39
+ SendCurrent() {
40
+ var tStatusModel = new StatusModel();
41
+ tStatusModel.type = StatusType.RigModelLoaded;
42
+ var tRigLoadedModel = new RigModelLoadedModel();
43
+ tRigLoadedModel.rigId = this.rig.id;
44
+ tRigLoadedModel.rigModelVersion = this.rig.rigModelViewModel.version;
45
+ tStatusModel.value = tRigLoadedModel;
46
+ SignalR.UpdateStatus(tStatusModel);
47
+ for (var i = 0; i < this.components.length; i++) {
48
+ this.components[i].SendCurrent();
49
+ }
50
+ }
51
+ ProcessKeyEvent(event) {
52
+ for (var i = 0; i < this.components.length; i++) {
53
+ this.components[i].ProcessKeyEvent(event);
54
+ }
55
+ }
56
+ PutWebRTCMessage(message) {
57
+ for (var i = 0; i < this.components.length; i++) {
58
+ this.components[i].PutWebRTCMessage(message);
59
+ }
60
+ }
61
+ GetName() {
62
+ return "rig #" + this.rig.id;
63
+ }
64
+ }
65
+ //# sourceMappingURL=rig.js.map
package/src/server.js ADDED
@@ -0,0 +1,87 @@
1
+ // require
2
+ import fs from 'fs';
3
+ import Debug from './common/debug.js';
4
+ import SignalR from './common/signalr.js';
5
+ export default class Server {
6
+ static { this.signalr = ""; }
7
+ static { this.rig = null; }
8
+ static { this.rig_uniquecode = ""; }
9
+ constructor() {
10
+ //this.OnExit = this.OnExit.bind(this);
11
+ //this.OnSigInt = this.OnSigInt.bind(this);
12
+ //this.OnSigTerm = this.OnSigTerm.bind(this);
13
+ Debug.SetErrorCallback(() => {
14
+ if (Server.rig != null) {
15
+ Debug.LogAlways(this.GetName(), "ERROR SHUTDOWN!", true);
16
+ this.Shutdown();
17
+ }
18
+ });
19
+ }
20
+ Start() {
21
+ //this.InitHandlers();
22
+ fs.readFile("config.json", 'utf8', (error, data) => {
23
+ if (error != undefined) {
24
+ Debug.Error(this.GetName(), 'Error reading config: ' + error);
25
+ return;
26
+ }
27
+ try {
28
+ this.Load(JSON.parse(data));
29
+ }
30
+ catch (parseError) {
31
+ Debug.Error(this.GetName(), 'Error parsing config: ' + parseError);
32
+ }
33
+ this.SetupVariables();
34
+ SignalR.StartConnection(Server.rig_uniquecode);
35
+ });
36
+ }
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
+ Load(config) {
57
+ // Server
58
+ if (config.server.url != undefined) {
59
+ Server.serverurl = config.server.url;
60
+ }
61
+ else {
62
+ Debug.Error(this.GetName(), "Server IP address is not defined in config.json");
63
+ }
64
+ // rig
65
+ if (config.rig?.uniquecode != undefined) {
66
+ Server.rig_uniquecode = config.rig.uniquecode;
67
+ }
68
+ else {
69
+ Debug.Error(this.GetName(), "Rig unique code is not defined in config.json");
70
+ }
71
+ }
72
+ Shutdown() {
73
+ if (Server.rig != null) {
74
+ Debug.LogAlways(this.GetName(), "SHUTDOWN", true);
75
+ Server.rig.Shutdown();
76
+ SignalR.StopConnection();
77
+ Server.rig = null;
78
+ }
79
+ }
80
+ SetupVariables() {
81
+ Server.signalr = Server.serverurl + "/righub";
82
+ }
83
+ GetName() {
84
+ return "server";
85
+ }
86
+ }
87
+ //# sourceMappingURL=server.js.map