Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 47f6b5a

Browse files
aapzuhpihkala
authored andcommitted
client has its own ws now. examples fixed (#11)
1 parent 5cc2f64 commit 47f6b5a

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

examples/browser.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@
2626
)
2727

2828
// Event binding examples
29-
client.bind('connected', function() {
29+
client.on('connected', function() {
3030
log('A connection has been established!')
3131
})
3232

33-
subscription.bind('subscribed', function() {
33+
subscription.on('subscribed', function() {
3434
log('Subscribed to '+subscription.streamId)
3535
})
3636

37-
subscription.bind('resending', function() {
37+
subscription.on('resending', function() {
3838
log('Resending from '+subscription.streamId)
3939
})
4040

41-
subscription.bind('resent', function() {
41+
subscription.on('resent', function() {
4242
log('Resend complete for '+subscription.streamId)
4343
})
4444

45-
subscription.bind('no_resend', function() {
45+
subscription.on('no_resend', function() {
4646
log('Nothing to resend for '+subscription.streamId)
4747
})
4848
</script>

examples/node.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ var subscription = client.subscribe(
2020
)
2121

2222
// Event binding examples
23-
client.bind('connected', function() {
23+
client.on('connected', function() {
2424
console.log('A connection has been established!')
2525
})
2626

27-
subscription.bind('subscribed', function() {
27+
subscription.on('subscribed', function() {
2828
console.log('Subscribed to '+subscription.streamId)
2929
})
3030

31-
subscription.bind('resending', function() {
31+
subscription.on('resending', function() {
3232
console.log('Resending from '+subscription.streamId)
3333
})
3434

35-
subscription.bind('resent', function() {
35+
subscription.on('resent', function() {
3636
console.log('Resend complete for '+subscription.streamId)
3737
})
3838

39-
subscription.bind('no_resend', function() {
39+
subscription.on('no_resend', function() {
4040
console.log('Nothing to resend for '+subscription.streamId)
4141
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"license": "",
1818
"dependencies": {
1919
"debug": "*",
20-
"eventemitter3": "*"
20+
"eventemitter3": "*",
21+
"ws": "^3.0.0"
2122
},
2223
"devDependencies": {
2324
"mocha": "*",

streamr-client.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
(function() {
44

55
var debug
6-
if (typeof window !== 'undefined') {
6+
if (typeof module !== 'undefined') {
7+
debug = require('debug')('StreamrClient')
8+
} else {
79
debug = (window.debug ? window.debug('StreamrClient') : function() {
810
if (window.consoleLoggingEnabled)
911
console.log.apply(console, arguments)
1012
})
1113
}
12-
else {
13-
debug = require('debug')('StreamrClient')
14+
15+
var WebSocket
16+
if (typeof module !== 'undefined') {
17+
WebSocket = require('ws')
18+
} else {
19+
WebSocket = window.WebSocket
1420
}
1521

1622
var BYE_KEY = "_bye"

test/test.streamr-client.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ describe('StreamrClient', function() {
160160
return socket
161161
});
162162

163-
global.WebSocket = require('ws')
164163
StreamrClient = require('../streamr-client')
165164
})
166165

0 commit comments

Comments
 (0)