     @rtm.once 'RealtimeManagerDidDispose', =>
       @rtm = null
       delete @stateMachine
-      @prepareCollaboration  if @amIHost
 
     @rtm.dispose()
 

    if @amIHost
      @endCollaborationForHost
        success: =>
          # TODO: move this into its own method.
          @statusBar.emit 'CollaborationEnded'
          sharedSuccessFn()
          @cleanupCollaboration()

    else
      @endCollaborationForParticipant

            callbacks.success()


  handleCollaborationEndedForHost: ->

    return  unless @stateMachine.state in ['Ending']

    @rtm.once 'RealtimeManagerWillDispose', =>
      @chat.emit 'CollaborationEnded'
      @chat.destroy()
      @chat = null
      @statusBar.emit 'CollaborationEnded'

    @rtm.once 'RealtimeManagerDidDispose', =>
      kd.utils.defer @bound 'prepareCollaboration'

    @cleanupCollaboration()


  endCollaborationForParticipant: (callbacks) ->

    @broadcastMessage { type: 'ParticipantWantsToLeave' }
