UNPKG

1.48 kBtext/coffeescriptView Raw
1noflo = require 'noflo'
2
3class Group extends noflo.Component
4 description: 'Adds a set of groups around the packets received at each connection'
5 icon: 'tags'
6 constructor: ->
7 @groups = []
8 @newGroups = []
9 @threshold = null # How many groups to be saved?
10
11 @inPorts = new noflo.InPorts
12 in:
13 datatype: 'all'
14 group:
15 datatype: 'string'
16 description: 'The group to add around forwarded packets'
17 threshold:
18 datatype: 'int'
19 description: 'Maximum number of groups kept around'
20 required: no
21 @outPorts = new noflo.OutPorts
22 out:
23 datatype: 'all'
24 required: no
25
26 @inPorts.in.on 'connect', () =>
27 @outPorts.out.beginGroup group for group in @newGroups
28
29 @inPorts.in.on 'begingroup', (group) =>
30 @outPorts.out.beginGroup group
31
32 @inPorts.in.on 'data', (data) =>
33 @outPorts.out.send data
34
35 @inPorts.in.on 'endgroup', (group) =>
36 @outPorts.out.endGroup()
37
38 @inPorts.in.on 'disconnect', () =>
39 @outPorts.out.endGroup() for group in @newGroups
40 @outPorts.out.disconnect()
41 @groups = []
42
43 @inPorts.group.on 'data', (data) =>
44 # Get rid of groups in the past to make room for the new one
45 if @threshold
46 diff = @newGroups.length - @threshold + 1
47 if diff > 0
48 @newGroups = @newGroups.slice(diff)
49
50 @newGroups.push data
51
52 @inPorts.threshold.on 'data', (@threshold) =>
53
54exports.getComponent = -> new Group