我正在连接到Particle.io事件流并尝试使用流中的事件名称和事件数据作为参数调用Meteor方法。
var Particle = Meteor.npmRequire('particle-api-js');
var particle = new Particle();
var particleLogin = particle.login({
username: Meteor.settings.particle_username,
password: Meteor.settings.particle_password
});
particleLogin.then(
function(data) {
var token = data.body.access_token;
console.log(token);
var eventStream = particle.getEventStream({
deviceId: Meteor.settings.PhotonName,
auth: token
});
eventStream.then(function(stream) {
stream.on('event', function(data) {
console.log(data.name + ": " + data.data);
Meteor.call('newStreamData', data.name, data.data); // Produces aforementioned error
});
});
}
)
我已尝试从Meteor.bindEnvironment块中包含调用,但没有任何反应。
stream.on('event', Meteor.bindEnvironment(function(data) {
console.log(data.name + ": " + data.data); // Never gets called
Meteor.call('newStreamData', data.name, data.data); // Never gets called
}));