 
 debug = require('debug')('msgflo:fbp')
 EventEmitter = require('events').EventEmitter
+
+fbpPort = (port) ->
+  m =
+    id: port.id
+    type: port.type or "any"
+    description: port.description or ""
+    addressable: false
+    required: false # TODO: implement
+  return m
+
+fbpComponentFromMsgflo = (name, component) ->
+  if component.definition
+    # full info available
+    info =
+      name: name
+      description: component.label or component.cmd or ""
+      icon: component.definition.icon
+      subgraph: false
+      inPorts: component.definition.inports.map fbpPort
+      outPorts: component.definition.outports.map fbpPort
+  else
+    # just inifial info
+    info =
+      name: name
+      description: component.cmd
+      icon: null
+      subgraph: false
+      inPorts: []
+      outPorts: []
+
+  return info
 
 handleMessage = (proto, sub, cmd, payload, ctx) ->
   debug 'RECV:', sub, cmd, payload

      debug 'components-changed', names
      for name in names
        component = allComponents[name]
        # TODO: let Library emit a new change when discovery message comes in,
        # which has inPorts/outPorts info etc
        info =
          name: name
          description: component.cmd
          icon: null
          subgraph: false
          inPorts: []
          outPorts: []
        @transport.sendAll 'component', 'component', info

    @coordinator.on 'data', (from, fromPort, to, toPort, data) =>


  # Component
  else if sub == 'component' and cmd == 'list'


    debug 'attempting to list components'
    components = []
    for name, component of proto.coordinator.library.components
      info = fbpComponentFromMsgflo name, component
      components.push info

    for info in components
      proto.transport.send 'component', 'component', info, ctx
    proto.transport.send 'component', 'componentsready', components.length, ctx
    debug 'sent components', components.length

