       console.error "Cannot send when not connected"
     else
       message.id = ++@_messageID
+      @_pending[message.id] = message
       @ws.send JSON.stringify(message)
 
   _apiCall: (method, params, callback) ->

        if message.reply_to
          if message.ok
            console.log "Message "+message.reply_to+" was sent"
            # TODO: Now add to history
          else
            console.error "Error sending message "+message.reply_to+": "+message.error.msg
            # TODO: resend?

    @socketUrl      = null
    @ws             = null
    @_messageID     = 0
    @_pending       = {}

  #
  # Logging in and connection management functions
