var dojo = require('dojo'); var core = require('urb/core'); dojo.provide('urb.proxy'); var Proxy = dojo.declare('Proxy', core.EventEmitter, { constructor: function (name, filterId) { this.filterId = filterId; this.client = null; }, attach: function (client) { this.client = client; this.client.on('event', this.eventListener()); }, eventListener: function () { if (!this._eventListener) { this._eventListener = dojo.hitch(this, this.onEvent); } return this._eventListener; }, onEvent: function (event) { if (event.emitter != this.filterId) return; this.emit(event.topic, event.data); }, rpc: function (method, args) { var id = this.filterId; this.client.send({topic: 'rpc', data: {id: id, method: method, args: args} });
var dojo = require('dojo'); var core = require('urb/core'); dojo.provide('urb.net'); var ServerProtocol = dojo.declare('ServerProtocol', core.EventEmitter, { listen: function () { // start listening }, close: function () { // stop listening }, }); var ClientProtocol = dojo.declare('ClientProtocol', core.EventEmitter, { connect: function () { }, close: function () { }, send: function (message) { // pass }, parseMessage: function (message) { return JSON.parse(message); }, serializeMessage: function (message) { var dict = ToDict(message); return JSON.stringify(dict); } }); var ToDict = function (obj) {
var dojo = require('dojo'); var net = require('urb/net'); var proxy = require('urb/proxy'); dojo.provide('urb.device'); var DeviceClient = dojo.declare('DeviceClient', net.Client, { constructor: function (name, protocol, device) { this.device = device; this.device.on('event', this.deviceListener()); }, /** * Event handler for connect events. Notifies listeners. */ onConnect: function () { this.send({topic: 'deviceAdded', emitter: this.id(), data: this.device}); this.emit('connected', this); }, /** * Event handler for disconnect events. Notifies listeners. * */ onDisconnect: function () { this.emit('disconnected', this); }, /** * Handles receiving a new message from the remote DeviceServer. * * @param {object} message {@link Message}
var http = require('http'); var dojo = require('dojo'); var io = require('Socket.IO-node'); var urb_net = require('urb/net'); dojo.provide('urb.protocol.sioServer'); /** * NOTE(termie): Going crazy typing SocketIo so shortening to Sio */ var SioServerProtocol = dojo.declare('SioServerProtocol', urb_net.ServerProtocol, { constructor: function (port, server, options) { this._port = port; this._host = '0.0.0.0'; this._server = server; this._options = options; this._socket = null; this._clients = {}; }, listen: function () { if (!this._server) { this._server = http.createServer(function () {}); } this._server.listen(this._port, this._host); this._socket = io.listen(this._server, this._options); this._socket.on('clientConnect', dojo.hitch(this, this.onClientConnect)); this._socket.on('clientDisconnect',
var dojo = require('dojo'); var http = require('http'); var net = require('urb/net'); dojo.provide('urb.protocol.olad'); var OladClientProtocol = dojo.declare('OladClientProtocol', net.ClientProtocol, { constructor: function (host, port) { this.host = host || 'localhost'; this.port = port || 9090; }, send: function (message) { if (typeof message.universe == undefined || !message.ports) { throw 'OladClientProtocol only speaks DMXish stuff' } postData = 'u=' + message.universe + '&' + 'd=' + message.ports.join(','); console.log(postData); var self = this; var olad = http.createClient(this.port, this.host); var request = olad.request('POST', '/set_dmx', {'host': this.host, 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': postData.length, }); request.on('response', function (response) { console.log('STATUS: ' + response.statusCode); console.log('HEADERS: ' + JSON.stringify(response.headers)); response.setEncoding('utf8'); response.on('data', function (chunk) {
var dojo = require('dojo'); var net = require('urb/net'); dojo.provide('urb.protocol.sioClient'); // NOTE(termie): browser-only, expects socket.io to be loaded var SioClientProtocol = dojo.declare('SioClientProtocol', net.ClientProtocol, { constructor: function (host, options) { this._socket = new io.Socket(host, options); this._socket.addEvent('connect', dojo.hitch(this, this.emit, 'connect')); this._socket.addEvent('disconnect', dojo.hitch(this, this.emit, 'disconnect')); this._socket.addEvent('message', dojo.hitch(this, this.onMessage)); }, onMessage: function (message) { this.emit('message', this.parseMessage(message)); }, connect: function () { this._socket.connect(); }, send: function (message) { this._socket.send(this.serializeMessage(message)); } }); exports.SioClientProtocol = SioClientProtocol;