Files: fc3efb6d1a8e5ef2e4cbd0017fa9649b221b8793 / message.js
977 bytesRaw
1 | const EventEmitter = require('events') |
2 | const {ID} = require('./systemObjects.js') |
3 | |
4 | /** |
5 | * This implements Messages for Primea |
6 | * @module primea-message |
7 | */ |
8 | module.exports = class Message extends EventEmitter { |
9 | /** |
10 | * @param {Object} opts |
11 | * @param {ArrayBuffer} opts.data - the payload of the message |
12 | * @param {Array<Object>} opts.caps - an array of capabilities to send in the message |
13 | */ |
14 | constructor (opts) { |
15 | super() |
16 | const defaults = this.constructor.defaults |
17 | this._opts = Object.assign(defaults, opts) |
18 | Object.keys(this._opts).forEach(key => { |
19 | Object.defineProperty(this, key, { |
20 | get: function () { |
21 | return this._opts[key] |
22 | }, |
23 | set: function (y) { |
24 | this._opts[key] = y |
25 | } |
26 | }) |
27 | }) |
28 | } |
29 | |
30 | static get defaults () { |
31 | return { |
32 | ticks: 0, |
33 | funcRef: null, |
34 | funcArguments: [], |
35 | funcParameters: [], |
36 | _fromId: new ID(Buffer.alloc(20)), |
37 | _fromTicks: 0 |
38 | } |
39 | } |
40 | } |
41 |
Built with git-ssb-web