git ssb

0+

wanderer🌟 / js-primea-message



Tree: 51eb1321a6365be7d1be22b5f6fa4d20456791d7

Files: 51eb1321a6365be7d1be22b5f6fa4d20456791d7 / index.js

1161 bytesRaw
1/**
2 * This implements Messages for Primea
3 * @module primea-message
4 */
5module.exports = class Message {
6 /**
7 * @param {Object} opts
8 * @param {ArrayBuffer} opts.data - the payload of the message
9 * @param {Array<Object>} opts.ports - an array of ports to send in the message
10 */
11 constructor (opts = {}) {
12 const defaults = this.constructor.defaults
13 this._opts = Object.assign(defaults, opts)
14
15 // set by the kernel
16 this._hops = 0
17 this._fromTicks = 0
18 }
19
20 toJSON () {
21 return this._opts
22 }
23
24 /**
25 * Returns the messages payload
26 * @returns {ArrayBuffer}
27 */
28 get data () {
29 return this._opts.data
30 }
31
32 /**
33 * Returns an array of ports that a message is carrying
34 * @returns {[]}
35 */
36 get caps () {
37 return this._opts.caps
38 }
39
40 /**
41 * Returns the messages payload
42 * @returns {ArrayBuffer}
43 */
44 get ticks () {
45 return this._opts.ticks
46 }
47
48 /**
49 * returns the number of hops a packet has undergone
50 * @returns {integer}
51 */
52 get hops () {
53 return this._hops
54 }
55
56 static get defaults () {
57 return {
58 ticks: 0,
59 data: new ArrayBuffer([]),
60 caps: []
61 }
62 }
63}
64

Built with git-ssb-web