diff --git a/index.js b/index.js
index <HASH>..<HASH> 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,6 @@ var stream = require('stream')
 var util = require('util')
 
 function WebsocketStream(server, protocol) {
-  var self = this
   stream.Stream.call(this)
   this.readable = true
   this.writable = true
@@ -11,14 +10,13 @@ function WebsocketStream(server, protocol) {
     this.ws.on('message', this.onMessage.bind(this))
     this.ws.on('error', this.onError.bind(this))
     this.ws.on('close', this.onClose.bind(this))
-    this.ws.on('open', function() {
-      self.emit('open')
-    })
+    this.ws.on('open', this.onOpen.bind(this))
   } else {
     this.ws = new WebSocket(server, protocol)
     this.ws.onmessage = this.onMessage.bind(this)
     this.ws.onerror = this.onError.bind(this)
     this.ws.onclose = this.onClose.bind(this)
+    this.ws.onopen = this.onOpen.bind(this)
   }
 }
 
@@ -43,6 +41,10 @@ WebsocketStream.prototype.onClose = function(err) {
   this.emit('end')
 }
 
+WebsocketStream.prototype.onClose = function(err) {
+  this.emit('open')
+}
+
 WebsocketStream.prototype.write = function(data) {
   return this.ws.send(data)
 }
Register onopen callback on ws instance and emit 'open' event.