 
   send: (message) ->
     console.log "Chat Client wants to send message", message
-    @startChat() unless @started
+    @startChat() unless @state == stateEnum.STARTED
     @sendMessage(message)
 
   startChat: ->
-    return if @startPending
+    return if @state == stateEnum.START_PENDING
+    @state = stateEnum.START_PENDING
     @pollMessages()
-    @startPending = true
-    console.log "Chat Client Chat Started"
+    console.log "Chat Client Chat Start Peding"
 
   pollMessages: ->
-    return if @killed
+    return if @state == stateEnum.KILLED
     console.log "Chat Client is polling for messages"
     $.get @endpoint, (data) =>
-      @started = true
+      @state = stateEnum.STARTED
       @dismissWelcome()
       @dequeueMessages()
       @renderMessages data.events

        if (event.type == 'participantStateChanged' &&
            event.state == 'disconnected' &&
            event.participant_type == 'WebUser')
          @started = false

      setTimeout () =>
        @pollMessages()
      , 1000 if !@killed && @started

  sendMessage: (message) ->
    return unless message
    return @queueMessage(message) unless @started

    $.post @endpoint, { event: { content: message } }, (data) =>
      @renderMessages data.events

    $.ajax
      url: @endpoint
      type: 'DELETE'
    console.log "Chat Terminated"

    @state = stateEnum.KILLED
    console.log "Chat Client Chat Terminated"
