Files: dab3811ca5fd385b1f4a2ee97f904ae240f426af / port.js
515 bytesRaw
1 | const EventEmitter = require('events') |
2 | |
3 | module.exports = class Port extends EventEmitter { |
4 | constructor (name) { |
5 | super() |
6 | this.name = name |
7 | this.connected = false |
8 | } |
9 | |
10 | connect (destPort) { |
11 | if (!this.connected) { |
12 | this.destPort = destPort |
13 | destPort.destPort = this |
14 | this.connected = true |
15 | } |
16 | } |
17 | |
18 | async send (message) { |
19 | message.hops++ |
20 | this.destPort.recieve(message) |
21 | } |
22 | |
23 | async recieve (message) { |
24 | message.from.push(this.name) |
25 | this.emit('message', message) |
26 | } |
27 | } |
28 |
Built with git-ssb-web