微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JetBus Web 消息总线

程序名称:JetBus

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

JetBus 介绍

Jet 是一个用于 Web 的轻量级和实时的消息总线。支持浏览器和 Node.js node-
jet
,提供 Lua 版本 lua-
jet
和基于 Arduino 的版本 Arduino-
Jet

示例代码

var jet = require('node-jet');

var peer = new jet.Peer({
  url: 'ws://jet.nodejitsu.com:80'
});

peer.connect().then(function() {
  console.log('peer is connected to daemon');
});

var machineName = new jet.State('machine/name', 'animal');
machineName.on('set', function(newName) {
  setMachineName(newName); // does something appropriate
});

peer.add(machineName).then(function() {
  console.log('machine/name has been added to daemon');
}).catch(function(err) {
  console.log('Could not add machine/name to daemon', err);
});

// add a state
var cpuLoad = new jet.State('cpu/load', readcpuLoad());

peer.add(cpuLoad).then(function() {
  // async post new value
  setTimeout(function () {
    cpuLoad.value(readcpuLoad());
  },3000);
});

添加方法

// add a method
var greet = new jet.Method('greet');
greet.on('call', function(name) {
    if (name.first === 'John') {
      throw 'John is a bad guy!';
    }
    var greeting = 'Hello ' + name.first + ' ' + name.last;
    console.log(greeting);
    return greeting;
});

peer.add(greet);

JetBus 官网

http://jetbus.io/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐