 
 exports.CallServer = class CallServer extends require('events').EventEmitter
 
-  constructor: (port) ->
+  constructor: ->
 
     super()
 
     Unique_ID = 'Unique-ID'
 
-    server = new eslServer (res) ->
+    @server = new eslServer (res) =>
       res.connect (req,res) =>
         # Channel data
         channel_data = req.body

        res.on 'esl_event', (req,res) =>
          req.channel_data = channel_data
          req.unique_id = unique_id
          server.emit req.body['Event-Name'], req, res

        # Handle the incoming connection
        res.linger (req,res) ->
          res.filter Unique_ID, unique_id, (req,res) ->
            res.event_json 'ALL', (req,res) ->
              req.channel_data = channel_data
              req.unique_id = unique_id
              server.emit 'CONNECT', req, res

    # Start the server.
    server.listen port
    return server

#### Usage:
#
#     server = new esl.CallServer (port)
#
#     server.on 'CONNECT', (req,res) ->
#       # Start processing the call
#       # Channel data is available as req.channel_data
#       # For example:
#       uri = req.channel_data.variable_sip_req_uri
#
#     # Other FreeSwitch channel events are available as well:
#     server.on 'CHANNEL_ANSWER', (req,res) ->
#       util.log 'Call was answered'
#     server.on 'CHANNEL_HANGUP_COMPLETE', (req,res) ->
#       # Call was disconnected.
#


exports.createClient = () -> return new eslClient()

#### CallServer: a higher-level interface
#
# This interface is based on my
