UNPKG

934 Btext/coffeescriptView Raw
1noflo = require 'noflo'
2
3class Merge extends noflo.Component
4 description: 'This component receives data on multiple input ports and
5 sends the same data out to the connected output port'
6 icon: 'compress'
7
8 constructor: ->
9 @inPorts = new noflo.InPorts
10 in:
11 datatype: 'all'
12 description: 'Packet to be forwarded'
13 @outPorts = new noflo.OutPorts
14 out:
15 datatype: 'all'
16
17 @inPorts.in.on 'connect', =>
18 @outPorts.out.connect()
19 @inPorts.in.on 'begingroup', (group) =>
20 @outPorts.out.beginGroup group
21 @inPorts.in.on 'data', (data) =>
22 @outPorts.out.send data
23 @inPorts.in.on 'endgroup', =>
24 @outPorts.out.endGroup()
25 @inPorts.in.on 'disconnect', =>
26 # Check that all ports have disconnected before emitting
27 for socket in @inPorts.in.sockets
28 return if socket.connected
29 @outPorts.out.disconnect()
30
31exports.getComponent = -> new Merge