You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

9 years ago
/**
* Copyright 2015, 2016 IBM Corp.
9 years ago
*
* 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.
**/
module.exports = function(RED) {
"use strict";
var express = require("express");
var io = require('socket.io')(RED.server);
9 years ago
var WorldMap = function(n) {
RED.nodes.createNode(this,n);
var node = this;
//node.log("Serving map from "+__dirname+" as "+RED.settings.httpNodeRoot.slice(0,-1)+"/worldmap");
9 years ago
RED.httpNode.use("/worldmap", express.static(__dirname + '/worldmap'));
io.on('connection', function(socket) {
node.on('input', function(msg) {
socket.emit("worldmapdata",msg.payload);
});
});
9 years ago
}
RED.nodes.registerType("worldmap",WorldMap);
var WorldMapIn = function(n) {
RED.nodes.createNode(this,n);
var node = this;
io.on('connection', function(socket) {
socket.on('worldmap', function(data) {
node.send({payload:data, topic:"worldmap"});
});
socket.on('disconnect', function() {
node.send({payload:{action:"disconnect"}, topic:"worldmap"});
});
});
}
RED.nodes.registerType("worldmap in",WorldMapIn);
9 years ago
}