 if window?
   window.Stomp = Stomp
 else
-  exports.Stomp = Stomp+  exports.Stomp = Stomp
+  WebSocket = require('./test/server.mock.js').StompServerMock
    client = this
    @debug?("Opening Web Socket...")
    @ws = new WebSocket(@url)
    @ws.onmessage = (evt) ->
      client.debug?('<<< ' + evt.data)
      frame = Stomp.unmarshal(evt.data)
      if frame.command is "CONNECTED" and client.connectCallback
        client.connectCallback(frame)
      else if frame.command is "MESSAGE"
        onreceive = client.subscriptions[frame.headers.subscription]
        onreceive?(frame)
      else if frame.command is "RECEIPT"
        client.onreceipt?(frame)
      else if frame.command is "ERROR"
        client.onerror?(frame)
    @ws.onclose   = ->
      msg = "Whoops! Lost connection to " + client.url
      client.debug?(msg)
      errorCallback?(msg)
    @ws.onopen    = ->
      client.debug?('Web Socket Opened...')
      client._transmit("CONNECT", {login: login_, passcode: passcode_})
    @login = login_
    @passcode = passcode_
    @connectCallback = connectCallback
  
  disconnect: (disconnectCallback) ->
    @_transmit("DISCONNECT")
    @ws.close()
    disconnectCallback?()
  
  send: (destination, headers={}, body='') ->

  constructor: (@url) ->
    # used to index subscribers
    @counter = 0 
    @connected = false
    # subscription callbacks indexed by subscriber's ID
    @subscriptions = {};
  
