More base updates, including web socket handling and display logic
Ryan Blenis committed
Oct 9, 2019 at 01:22 UTC
f60f6963d588a60b360558100b878f5f0e1d59e8
4 files changed
+86
-8
agents/meshcore.min.js
+30
@@ -1491,6 +1491,36 @@ function createMeshCore(agent)
1491
// Unknown action, ignore it.
1492
break;
1493
}
1494
+ } else if (this.httprequest.protocol == 7) { // plugin data exchange
1495
+ var cmd = null;
1496
+ try { cmd = JSON.parse(data); } catch (e) { };
1497
+ if (cmd == null) { return; }
1498
+ if ((cmd.ctrlChannel == '102938') || ((cmd.type == 'offer') && (cmd.sdp != null))) { onTunnelControlData(cmd, this); return; } // If this is control data, handle it now.
1499
+ if (cmd.action == undefined) { return; }
1500
+ //sendConsoleText('CMD: ' + JSON.stringify(cmd));
1501
+
1502
+ if ((cmd.path != null) && (process.platform != 'win32') && (cmd.path[0] != '/')) { cmd.path = '/' + cmd.path; } // Add '/' to paths on non-windows
1503
+ //console.log(objToString(cmd, 0, ' '));
1504
+
1505
+ switch (cmd.action) {
1506
+ case 'plugin': {
1507
+ try {
1508
+ require(cmd.plugin).consoleaction(cmd, null, null, this);
1509
+ } catch (e) {
1510
+ /*var fs = require('fs');
1511
+ var logStream = fs.createWriteStream('log.txt', {'flags': 'a'});
1512
+ logStream.write('\nCouldnt load plugin '+e+e.stack);
1513
+ logStream.end('\n')*/
1514
+ throw e;
1515
+ }
1516
+
1517
+ break;
1518
+ }
1519
+ default: {
1520
+ // probably shouldn't happen, but just in case this feature is expanded
1521
+ }
1522
+ }
1523
+
1524
}
1525
//sendConsoleText("Got tunnel #" + this.httprequest.index + " data: " + data, this.httprequest.sessionid);
1526
}
meshuser.js
+11
@@ -2963,6 +2963,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2963
}
2964
break;
2965
}
2966
+ case 'plugin': {
2967
+ command.userid = user._id;
2968
+
2969
+ if (command.routeToNode === true) {
2970
+ routeCommandToNode(command);
2971
+ } else {
2972
+ // TODO
2973
+ }
2974
+
2975
+ break;
2976
+ }
2977
default: {
2978
// Unknown user action
2979
console.log('Unknown action from user ' + user.name + ': ' + command.action + '.');
pluginHandler.js
+22
-2
@@ -33,7 +33,7 @@ module.exports.pluginHandler = function (parent) {
33
obj.plugins[plugin] = require(obj.pluginPath + '/' + plugin + '/' + plugin + '.js')[plugin](obj);
34
obj.exports[plugin] = obj.plugins[plugin].exports;
35
} catch (e) {
36
- console.log("Error loading plugin: " + plugin + " (" + e + "). It has been disabled");
36
+ console.log("Error loading plugin: " + plugin + " (" + e + "). It has been disabled.", e.stack);
37
}
38
}
39
});
@@ -49,7 +49,27 @@ module.exports.pluginHandler = function (parent) {
49
str += ' obj.'+ p +'.'+ l + ' = '+ obj.plugins[p][l].toString()+'\r\n';
50
}
51
}
52
- str += 'return obj; };\r\n';
52
+
53
+ str += 'obj.enabled = '+ obj.enabled +';\r\n';
54
+ str += `obj.onDeviceRefeshEnd = function(nodeid, panel, refresh, event) {
55
+ for (const p of Object.keys(obj)) {
56
+ if (typeof obj[p].onDeviceRefreshEnd == 'function') {
57
+ obj[p].onDeviceRefreshEnd(nodeid, panel, refresh, event);
58
+ }
59
+ }
60
+ };
61
+ obj.registerPluginTab = function(pluginRegInfo) {
62
+ var d = pluginRegInfo();
63
+ QA('p19headers', '<span onclick="return pluginHandler.callPluginPage(\\''+d.tabId+'\\');">'+d.tabTitle+'</span>');
64
+ };
65
+ obj.callPluginPage = function(id) {
66
+ var pages = Q('p19pages').querySelectorAll("#p19pages>div");
67
+ for (const i of pages) {
68
+ i.style.display = 'none';
69
+ }
70
+ QV(id, true);
71
+ };
72
+ return obj; };`;
73
return str;
74
}
75
views/default.handlebars
+23
-6
@@ -844,9 +844,23 @@
844
</div>
845
<div id=p19 style="display:none">
846
<h1>Plugins - <span id=p19deviceName></span></h1>
847
- <div class="p19headers">
848
- </div>
849
- <div id=p19pages style=""></div>
847
+ <style>
848
+ #p19headers {
849
+ padding-right: 7px;
850
+ padding-bottom: 10px;
851
+ font-weight: bold;
852
+ border-bottom: 1px dotted blue;
853
+ }
854
+ #p19headers > span:nth-child(n+2) {
855
+ border-left: 1px solid black;
856
+ }
857
+ #p19headers > span {
858
+ padding-left: 4px;
859
+ padding-right: 4px;
860
+ }
861
+ </style>
862
+ <div id="p19headers"></div>
863
+ <div id=p19pages></div>
864
</div>
865
<br id="column_l_bottomgap" />
866
</div>
@@ -1015,7 +1029,8 @@
1029
var nightMode = (getstore('_nightMode', '0') == '1');
1030
var sessionActivity = Date.now();
1031
var updateSessionTimer = null;
1018
- var pluginHandler = {{{pluginHandler}}};
1032
+ var pluginHandlerBuilder = {{{pluginHandler}}};
1033
+ var pluginHandler = new pluginHandlerBuilder();
1034
1035
// Console Message Display Timers
1036
var p11DeskConsoleMsgTimer = null;
@@ -2309,8 +2324,7 @@
2324
case 'plugin': {
2325
if (typeof message.plugin == 'string') {
2326
try {
2312
- var ph = pluginHandler();
2313
- ph[message.plugin][message.method](server, message);
2327
+ pluginHandler[message.plugin][message.method](server, message);
2328
} catch (e) {
2329
console.log('Error loading plugin handler ('+ e + ')');
2330
}
@@ -4149,6 +4163,7 @@
4163
QH('p15deviceName', 'Console - ' + nname);
4164
QH('p16deviceName', nname);
4165
QH('p17deviceName', nname);
4166
+ QH('p19deviceName', nname);
4167
4168
// Node attributes
4169
var x = '<table style=width:100%>';
@@ -4404,6 +4419,8 @@
4419
p11clearConsoleMsg();
4420
p12clearConsoleMsg();
4421
p13clearConsoleMsg();
4422
+
4423
+ pluginHandler.onDeviceRefeshEnd(nodeid, panel, refresh, event);
4424
}
4425
setupDesktop(); // Always refresh the desktop, even if we are on the same device, we need to do some canvas switching.
4426
if (!panel) panel = 10;