         switch event['type']
           when 'call'
             @remoteUserID = event['remoteUserID']
+          when 'hangUp'
+            @onHangedUp()
+            @_hangedUp = true
+            @_sendMessage(JSON.stringify(type: 'hangUpAnswer'))
+            @_stop()
+          when 'hangUpAnswer'
+            @_stop()
           when 'offer'
             @_onOffer(event)
           when 'answer'

class @WebRTC
  constructor: (userID, @localOutput, @remoteOutput) ->
    @_startOutput(@localOutput.tagName.toUpperCase() == 'VIDEO')
    @wsRails = new WebSocketRails(location.host + "/websocket?webrtc=true&user_identifier=" + userID)

          candidate: event.candidate.candidate
        )

    peer.oniceconnectionstatechange = (event) =>
      switch peer.iceConnectionState
        when 'disconnected'
          @onReconnectingStarted()
        when 'connected', 'completed'
          if @_hangedUp
            @onConnected()
          @_hangedUp = false

    peer.addStream(@_localStream)
    peer.addEventListener('addstream', onRemoteStreamAdded, false)
    peer.addEventListener('removestream', onRemoteStreamRemoved, false)
