You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+52-10Lines changed: 52 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,30 @@
1
1
# streamr-client
2
2
3
-
streamr-client is a JavaScript client for connecting to Streamr data. You can subscribe to user interface widget updates or even raw data streams.
3
+
This is a JavaScript client for subscribing to realtime streams from [Streamr](http://www.streamr.com). Streamr is a realtime stream processing and analytics platform. This client allows you to write JS applications that leverage the stream computing and pub/sub features of Streamr. It works both in the browser and in node.js.
4
4
5
-
## Requirements
5
+
The streamr-client uses [socket.io](http://socket.io/) under the hood for streaming message delivery. It works in virtually all browsers by using websockets where available, or fallback methods on legacy browsers.
In node.js, dependencies will be installed automatically with `npm install`. In the browser, make sure you include `socket.io-client` before `streamr-client`.
8
13
9
14
## Usage
10
15
16
+
The `examples` directory contains snippets for both browser and node.js.
17
+
11
18
```javascript
12
19
client =newStreamrClient({
13
-
// Connection options and default values
14
-
server:'data.streamr.com',
20
+
// Connection options can be omitted, these are the default values
21
+
server:'https://data.streamr.com',
15
22
autoConnect:true,
16
23
autoDisconnect:true
17
24
})
18
-
client.subscribe(
25
+
var sub =client.subscribe(
19
26
'stream-id',
20
-
function(message, streamId, counter) {
27
+
function(message, streamId, timestamp, counter) {
21
28
// Do something with the message, which is an object
22
29
},
23
30
{
@@ -29,7 +36,7 @@ client.connect()
29
36
30
37
## Handling messages
31
38
32
-
The second argument to client.subscribe() is the callback function that will be called for each message as they arrive. Its arguments are as follows:
39
+
The second argument to `client.subscribe(streamId, callback, resendOptions)` is the callback function that will be called for each message as they arrive. Its arguments are as follows:
33
40
34
41
Argument | Description
35
42
-------- | -----------
@@ -75,16 +82,51 @@ getSubscriptions(`streamId`) | Returns a list of `Subscriptions` for `streamId`.
75
82
bind(eventName, function) | Binds a `function` to an event called `eventName`
76
83
unbind(eventName, function) | Unbinds the `function` from events called `eventName`
77
84
78
-
## Events on the client
85
+
## Binding to events
86
+
87
+
The client and the subscriptions can fire events as detailed below. You can bind to them using `bind`:
88
+
89
+
```javascript
90
+
functionhello() {
91
+
console.log('Hello!')
92
+
}
93
+
94
+
client.bind('connected', hello)
95
+
96
+
var sub =client.subscribe(...)
97
+
sub.bind('subscribed', function() {
98
+
console.log('Subscribed to '+sub.streamId)
99
+
})
100
+
```
101
+
102
+
You can unbind using `unbind`:
103
+
104
+
```javascript
105
+
client.unbind('connected', hello)
106
+
```
107
+
108
+
109
+
## Events on the StreamrClient instance
79
110
80
111
Name | Handler Arguments | Description
81
112
---- | ----------------- | -----------
82
113
connected | | Fired when the client has connected (or reconnected).
83
114
disconnected | | Fired when the client has disconnected (or paused).
84
115
85
-
## Events on the `Subscription` object
116
+
## Events on the Subscription object
86
117
87
118
Name | Handler Arguments | Description
88
119
---- | ----------------- | -----------
89
120
subscribed | {from: number} | Fired when a subscription request is acknowledged by the server.
90
121
unsubscribed | | Fired when an unsubscription is acknowledged by the server.
122
+
resending | | Fired when the subscription starts resending.
123
+
resent | | Fired after `resending` when the subscription has finished resending.
124
+
no_resend | | Fired after `resending` in case there was nothing to resend.
125
+
126
+
## Logging
127
+
128
+
This library supports the [debug](https://github.com/visionmedia/debug) library for logging.
129
+
130
+
In node.js, start your app like this: `DEBUG=StreamrClient node your-app.js`
131
+
132
+
In the browser, include `debug.js` and set `localStorage.debug = 'StreamrClient'`
0 commit comments