我需要修改现有的CylonJS_socketIO解决方案,以便它适应另一个默认的socketIO实现。有麻烦,所以会感激任何反馈。我猜测它与传输对象有关,因为我在前端https://github.com/simb/FlashSocket.IO使用flashsocket客户端,但我不是节点忍者。我认为我不需要或要求快递。
这是默认的基本socketIO实现
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server,{transports:['flashsocket', 'websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']});
var port = Number(8080);
server.listen(port);
app.use(express.static(__dirname + '/'));
var temp;
var _this = this;
io.on('connection', function (socket) {
console.log('connection '+socket)
socket.on("data",function(d){console.log('data from flash: ',d);});
socket.emit("message","wtfwtwftwftwf hello from server");
socket.on('disconnect', function (socket) {
console.log("disconnect");
});
console.log('_this ='+_this);
_this.socket=socket;
});
这是CylonJS-socketIO代码,我必须通过合并以上某种方式来修改
'use strict';
var Cylon = require('cylon');
Cylon.robot({
name: 'tesla',
connections: {
edison: { adaptor: 'intel-iot' }
},
events: ['range_sent', 'turned_on', 'turned_off'],
commands: function() {
return {
range_on: this.rangeOn,
toggle: this.toggle
};
},
devices: {
maxbotix: { driver: 'maxbotix', pin: '0' },
led: { driver: 'led', pin: 13 }
},
work: function(my) {
var range = 0;
every((0.1).seconds(), function() {
range = my.maxbotix.range();
console.log('Maxbotix range: ', range);
this.rangeOn(range);
}.bind(this));
},
rangeOn: function(data) {
console.log('rangeOn in Server');
//this.led.turnOn();
this.emit('range_sent', { data: data });
},
toggle: function() {
this.led.toggle();
if (this.led.isOn()) {
this.emit('turned_on', { data: 'pass some data to the listener' });
} else {
this.emit('turned_off', { data: 'pass some data to the listener' });
}
}
});
Cylon.api(
'socketio',
{
host: '0.0.0.0',
port: '3000'
});
Cylon.start();