mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Start to add server-side events
This commit is contained in:
parent
77a6b0a71d
commit
95675bc6bc
19
red/events.js
Normal file
19
red/events.js
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright 2013 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var events = require("events");
|
||||
|
||||
module.exports = new events.EventEmitter();
|
17
red/nodes.js
17
red/nodes.js
@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
var util = require("util");
|
||||
var events = require("events");
|
||||
var EventEmitter = require("events").EventEmitter;
|
||||
var fs = require("fs");
|
||||
|
||||
var events = require("./events");
|
||||
|
||||
function getCallerFilename(type) {
|
||||
//if (type == "summary") {
|
||||
@ -59,9 +59,11 @@ var registry = (function() {
|
||||
return nodes[i];
|
||||
},
|
||||
clear: function() {
|
||||
events.emit("nodes-stopping");
|
||||
for (var n in nodes) {
|
||||
nodes[n].close();
|
||||
}
|
||||
events.emit("nodes-stopped");
|
||||
nodes = {};
|
||||
},
|
||||
|
||||
@ -72,7 +74,7 @@ var registry = (function() {
|
||||
return obj;
|
||||
})();
|
||||
|
||||
var ConsoleLogHandler = new events.EventEmitter();
|
||||
var ConsoleLogHandler = new EventEmitter();
|
||||
ConsoleLogHandler.on("log",function(msg) {
|
||||
util.log("["+msg.level+"] ["+msg.type+":"+(msg.name||msg.id)+"] "+msg.msg);
|
||||
});
|
||||
@ -128,7 +130,7 @@ function Node(n) {
|
||||
}
|
||||
this.wires = n.wires||[];
|
||||
}
|
||||
util.inherits(Node,events.EventEmitter);
|
||||
util.inherits(Node,EventEmitter);
|
||||
|
||||
Node.prototype.close = function() {
|
||||
// called when a node is removed
|
||||
@ -253,6 +255,8 @@ module.exports.load = function() {
|
||||
}
|
||||
|
||||
loadNodes("nodes");
|
||||
|
||||
events.emit("nodes-loaded");
|
||||
}
|
||||
|
||||
|
||||
@ -261,7 +265,10 @@ module.exports.getNode = function(nid) {
|
||||
return registry.get(nid);
|
||||
}
|
||||
module.exports.parseConfig = function(conf) {
|
||||
|
||||
registry.clear();
|
||||
|
||||
events.emit("nodes-starting");
|
||||
for (var i in conf) {
|
||||
var nn = null;
|
||||
var nt = node_type_registry.get(conf[i].type);
|
||||
@ -286,5 +293,7 @@ module.exports.parseConfig = function(conf) {
|
||||
if (deletedCredentials) {
|
||||
saveCredentialsFile();
|
||||
}
|
||||
events.emit("nodes-started");
|
||||
|
||||
}
|
||||
|
||||
|
13
red/red.js
13
red/red.js
@ -14,15 +14,22 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var events = require("./events");
|
||||
var server = require("./server");
|
||||
var nodes = require("./nodes");
|
||||
var library = require("./library");
|
||||
var settings = require("../settings");
|
||||
|
||||
module.exports = {
|
||||
|
||||
var events = require("events");
|
||||
|
||||
var RED = {
|
||||
nodes: nodes,
|
||||
app: server.app,
|
||||
server: server.server,
|
||||
settings: settings,
|
||||
library: library
|
||||
}
|
||||
library: library,
|
||||
events: events
|
||||
};
|
||||
|
||||
module.exports = RED;
|
||||
|
Loading…
Reference in New Issue
Block a user