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