 
   # Sent by mobile clients to request chrome application to repeat their 'request' message.
   _onRepeat: (data) ->
-    @ws.send(@_lastRequest)
+    @ws.send(@_lastRequest) if @_lastRequest?
 
   # Sent by mobile clients to indicate the chrome application that one client is able to handle the 'request' message.
   _onAccept: (data) ->

    @_leaveRoom()

  _joinRoom: (pairingId) ->
    return @_connectionPromise if @ws?
    d = Q.defer()
    @_connectionPromise = d.promise
    @ws = new WebSocket(@constructor.BASE_URL)

      when "challenge" then @_onChallenge(data)

  _onClose: (e) ->
    [@ws.onclose, @ws.onmessage] = [undefined, undefined]
    [@ws, @_connectionPromise] = [undefined, undefined]
    @_joinRoom()

  _send: (data) ->
    @_joinRoom().then(=> @_send(data)) if ! @_connectionPromise?
    @_connectionPromise.then =>
      @ws.send(data)

