diff --git a/examples/browser.html b/examples/browser.html
index 71b407890..130dfc447 100644
--- a/examples/browser.html
+++ b/examples/browser.html
@@ -26,23 +26,23 @@
)
// Event binding examples
- client.bind('connected', function() {
+ client.on('connected', function() {
log('A connection has been established!')
})
- subscription.bind('subscribed', function() {
+ subscription.on('subscribed', function() {
log('Subscribed to '+subscription.streamId)
})
- subscription.bind('resending', function() {
+ subscription.on('resending', function() {
log('Resending from '+subscription.streamId)
})
- subscription.bind('resent', function() {
+ subscription.on('resent', function() {
log('Resend complete for '+subscription.streamId)
})
- subscription.bind('no_resend', function() {
+ subscription.on('no_resend', function() {
log('Nothing to resend for '+subscription.streamId)
})
diff --git a/examples/node.js b/examples/node.js
index 99815dcf4..bf1cba783 100644
--- a/examples/node.js
+++ b/examples/node.js
@@ -20,22 +20,22 @@ var subscription = client.subscribe(
)
// Event binding examples
-client.bind('connected', function() {
+client.on('connected', function() {
console.log('A connection has been established!')
})
-subscription.bind('subscribed', function() {
+subscription.on('subscribed', function() {
console.log('Subscribed to '+subscription.streamId)
})
-subscription.bind('resending', function() {
+subscription.on('resending', function() {
console.log('Resending from '+subscription.streamId)
})
-subscription.bind('resent', function() {
+subscription.on('resent', function() {
console.log('Resend complete for '+subscription.streamId)
})
-subscription.bind('no_resend', function() {
+subscription.on('no_resend', function() {
console.log('Nothing to resend for '+subscription.streamId)
})
\ No newline at end of file
diff --git a/package.json b/package.json
index 86a687d05..e249ce521 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,8 @@
"license": "",
"dependencies": {
"debug": "*",
- "eventemitter3": "*"
+ "eventemitter3": "*",
+ "ws": "^3.0.0"
},
"devDependencies": {
"mocha": "*",
diff --git a/streamr-client.js b/streamr-client.js
index 3d96e541b..ec4496782 100644
--- a/streamr-client.js
+++ b/streamr-client.js
@@ -3,14 +3,20 @@
(function() {
var debug
- if (typeof window !== 'undefined') {
+ if (typeof module !== 'undefined') {
+ debug = require('debug')('StreamrClient')
+ } else {
debug = (window.debug ? window.debug('StreamrClient') : function() {
if (window.consoleLoggingEnabled)
console.log.apply(console, arguments)
})
}
- else {
- debug = require('debug')('StreamrClient')
+
+ var WebSocket
+ if (typeof module !== 'undefined') {
+ WebSocket = require('ws')
+ } else {
+ WebSocket = window.WebSocket
}
var BYE_KEY = "_bye"
diff --git a/test/test.streamr-client.js b/test/test.streamr-client.js
index beb2a9b24..0f788a59a 100644
--- a/test/test.streamr-client.js
+++ b/test/test.streamr-client.js
@@ -160,7 +160,6 @@ describe('StreamrClient', function() {
return socket
});
- global.WebSocket = require('ws')
StreamrClient = require('../streamr-client')
})