diff --git a/.project b/.project new file mode 100755 index 0000000..8a4cf8a --- /dev/null +++ b/.project @@ -0,0 +1,18 @@ + + + NodeJSToFreeboardIO + + + + + + com.eclipsesource.jshint.ui.builder + + + + + + org.nodeclipse.ui.NodeNature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100755 index 0000000..4796467 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//datasources/plugin_node.js=UTF-8 +encoding/plugin_node_sample_server.js=UTF-8 diff --git a/README.md b/README.md index f52888b..d8bd9e9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,58 @@ -plugins -======= +freeboard.io-node.js +========= -Plugins for Freeboard.io +This is a datasource plugin to connect freeboard.io dashboards to real-time node.js servers. + + - Subscribe to real-time events using WebSockets (Sockets.io) + - Listen for events from different servers + - Restrict events from only certain [namespaces or rooms](http://socket.io/docs/rooms-and-namespaces/) + +Installation +-------------- + +1. Place the file ```/datasources/plugin_node.js``` in ```/js/freeboard/plugins``` of your freeboard.io installation. + +2. Edit your freeboard.io main HTML file and add the plugin to the header: + +```js + + + + +
+ +
+ +
+
+
+
+
+
+

freeboard

+
+
    +
  • +
  • +
  • +
+
+
+
+

DATASOURCES

+ +
+ + + + + + + + + + + + + + + +
NameLast Updated 
+ +
    +
  • +
  • + +
  • +
+
+
+ ADD +
+
+
+
+ +
+
+ +
+ +
+ + + + + diff --git a/plugin_node_sample_dashboard.json b/plugin_node_sample_dashboard.json new file mode 100755 index 0000000..8d9a55f --- /dev/null +++ b/plugin_node_sample_dashboard.json @@ -0,0 +1,100 @@ +{ + "allow_edit": true, + "plugins": [], + "panes": [ + { + "title": "Houses", + "width": 1, + "row": { + "2": 1, + "3": 1 + }, + "col": { + "2": 1, + "3": 1 + }, + "widgets": [ + { + "type": "text_widget", + "settings": { + "title": "House of Stark - Jon", + "size": "regular", + "value": "datasources[\"Jon\"].value", + "sparkline": true, + "animate": true + } + }, + { + "type": "text_widget", + "settings": { + "title": "House of Lannister - Tyrion", + "size": "regular", + "value": "datasources[\"Tyrion\"].value", + "sparkline": true, + "animate": true + } + } + ] + }, + { + "title": "Timezones", + "width": 1, + "row": { + "3": 1 + }, + "col": { + "3": 2 + }, + "widgets": [ + { + "type": "text_widget", + "settings": { + "title": "House of Stark - Jon", + "size": "regular", + "value": "new Date(datasources[\"Jon\"].time_stamp).toLocaleTimeString();", + "animate": false + } + }, + { + "type": "text_widget", + "settings": { + "title": "House of Lannister - Tyrion", + "size": "regular", + "value": "new Date(datasources[\"Tyrion\"].time_stamp).toLocaleTimeString();", + "animate": false + } + } + ] + } + ], + "datasources": [ + { + "name": "Jon", + "type": "node_js", + "settings": { + "url": "http://localhost:8989/shows", + "eventName": "house.stark.jon", + "rooms": [ + { + "roomName": "got", + "roomEvent": "subscribe" + } + ] + } + }, + { + "name": "Tyrion", + "type": "node_js", + "settings": { + "url": "http://localhost:8989/shows", + "eventName": "house.lannister.tyrion", + "rooms": [ + { + "roomName": "got", + "roomEvent": "subscribe" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/plugin_node_sample_example.png b/plugin_node_sample_example.png new file mode 100755 index 0000000..73a9964 Binary files /dev/null and b/plugin_node_sample_example.png differ diff --git a/plugin_node_sample_server.js b/plugin_node_sample_server.js new file mode 100755 index 0000000..9cd3391 --- /dev/null +++ b/plugin_node_sample_server.js @@ -0,0 +1,111 @@ +// β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” \\ +// β”‚ freeboard.io-node.js β”‚ \\ +// β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ \\ +// β”‚ Copyright Β© 2014 Hugo Sequeira (https://github.com/hugocore) β”‚ \\ +// β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ \\ +// β”‚ Licensed under the MIT license. β”‚ \\ +// β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ \\ +// β”‚ Simple node.js and sockets.io server to test the node.js plugin. β”‚ \\ +// β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ \\ + +/* + * Configurations and helpers + */ +var namespace = '/shows'; +var room = 'got'; +var refreshTimer = 1000; +var connectionscounter = 0; +var eventNames = ['house.stark.jon', 'house.lannister.tyrion']; +var serverport = 8989; + +/* + * Project dependencies + */ +var io = require('socket.io')(serverport); + +/* + * Collects data + */ + +// Implement the methods to handle the new events +function newEventCallback(eventName, message) { + + // Construct the json object to be propagated + var json = { + value: message.value, + time_stamp: message.time_stamp, + }; + + // Invokes propagation + propagatesEvent(eventName, JSON.stringify(json)); +} + +// Connection to external data sources +function connectToExternalSources() { + + // Simulate the connection and new messages with a timer function + setInterval(function() { + for (var i=0; i0) { + io.of(namespace).to(room).emit(eventName, event); + console.log("New event propagated in: Namespace='%s' Room='%s' EventName='%s' Event='%s'", namespace, room, eventName, event); + } +} + +/* + * Handle Sockets.io connections + */ + +// Event handlers +io.of(namespace).on('connection', function(socket) { + + console.log("New client connected."); + + // Do some logic for every new connection + connectionscounter++; + + // On subscribe events join client to room + socket.on('subscribe', function(room) { + socket.join(room); + console.log("Client joined room: " + room); + }); + + // On disconnect events + socket.on('disconnect', function(socket) { + console.log("Client disconnect from rooms."); + connectionscounter--; + }); + +}); + +function puts(message) { + console.log(message); +} + +/* + * Run + */ +console.log("Starting Node.js server with namespace='%s' and room='%s'", namespace, room); +connectToExternalSources(); \ No newline at end of file