 
     close: (event) =>
       event.stopPropagation() if event
+
+      @ws.close()
+
+      sessionStorage.removeItem 'sessionId'
+      sessionStorage.removeItem 'unfinished_message'
+
+      @closeWindow()
+
+    closeWindow: =>
       remainerHeight = @el.height() - @el.find('.zammad-chat-header').outerHeight()
       @el.animate { bottom: -remainerHeight }, 500, @onCloseAnimationEnd
 


      @maybeAddTimestamp()

      @lastAddedType = 'message--agent'
      unread = document.hidden ? " zammad-chat-message--unread" : ""
      @el.find('.zammad-chat-body').append @view('message')
        message: data.message.content
        id: data.id
        from: 'agent'
      @scrollToBottom()

    open: =>
      return if @isOpen

      @showLoader()

      @el
        .addClass('zammad-chat-is-open')
        .animate { bottom: 0 }, 500, @onOpenAnimationEnd

      @isOpen = true



      @ws.onerror = (e) =>
        @log 'debug', 'ws:onerror', e

    onWebSocketOpen: =>
      @sessionId = sessionStorage.getItem('sessionId')

      @log 'debug', 'ws connected'

      @send 'chat_status_customer',
        session_id: @sessionId

      @setAgentOnlineState(true)

    reconnect: =>
      # set status to connecting
