UNPKG

a2r-osc

Version:

An OSC implementation for node.js and the browser

79 lines (60 loc) 1.97 kB
// Generated by CoffeeScript 1.4.0 (function() { var PackStream, UnpackStream, osc, stream, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; stream = require("stream"); osc = require("./osc"); UnpackStream = (function(_super) { __extends(UnpackStream, _super); function UnpackStream(dict) { UnpackStream.__super__.constructor.call(this); this.dict = dict; this.writable = true; } UnpackStream.prototype.write = function(buffer, encoding) { var msg; if (Buffer.isBuffer(buffer)) { try { msg = osc.fromBuffer(buffer, this.dict); this.emit("message", msg); } catch (e) { this.emit("error", e); } } else { this.write(new Buffer(buffer, encoding)); } return true; }; UnpackStream.prototype.end = function(buffer, encoding) { if (buffer) { this.write(buffer, encoding); } return this.emit("end"); }; return UnpackStream; })(stream.Stream); PackStream = (function(_super) { __extends(PackStream, _super); function PackStream(dict) { PackStream.__super__.constructor.call(this); this.dict = dict; this.writable = false; this.readable = true; } PackStream.prototype.send = function(message) { var buffer; try { buffer = message.toBuffer(this.dict); this.emit("data", buffer); } catch (e) { this.emit("error", e); return false; } return true; }; return PackStream; })(stream.Stream); module.exports.UnpackStream = UnpackStream; module.exports.PackStream = PackStream; }).call(this);