   constructor: (@url, @protocols)  ->
     @readyState = @CONNECTING
     @sent = []
-    WebSocket.sockets[@url] = this
+    WebSocket.instance = this
 
   open: ->
     @readyState = @OPEN
-    @onopen?()
+    @onopen()
 
   close: (code, reason) ->
     unless @readyState in [@CLOSING, @CLOSED]
       @readyState = @CLOSED
-      delete WebSocket.sockets[@url]
-      @onclose? code: code, reason: reason
+      @onclose code: code, reason: reason
 
-  error: -> @onerror?()
+  error: ->
+    @onerror()
 
   send: (data) ->
     unless @readyState is @OPEN
       throw new Error 'WebSocket is not open'
     @sent.push JSON.parse data
 
-  receive: (data) -> @onmessage? data: JSON.stringify data
+  receive: (data) ->
+    @onmessage data: JSON.stringify data
 
 Client = rewire '../client'
 Client.__set__ 'WebSocket', WebSocket

rewire = require 'rewire'

class WebSocket
  @sockets: {}

  CONNECTING: 0
  OPEN: 1


  beforeEach ->
    client = new Client url, protocols
    socket = WebSocket.instance

  it 'should open a new connection', ->
    assert.equal socket.url, url
