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
+38-31Lines changed: 38 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,43 +1,50 @@
1
-
<!-- Note that this readme is embedded on API Documentation page within Streamr. Please don't use first-level headings (h1). -->
2
-
<!-- You should write this document so that it will work both as a stand-alone document in the public GitHub repo and as a section in the API docs. -->
1
+
<!-- Note that this readme is embedded on API Documentation page within Streamr. Please don't use first-level headings (h1). You should write this document so that it will work both as a stand-alone document in the public GitHub repo and as a section in the API docs. -->
2
+
<aname="js-client"></a>
3
+
## Streamr JavaScript Client
3
4
4
-
# streamr-client
5
+
By using this client, you can easily subscribe to realtime [Streamr](http://www.streamr.com) streams from JavaScript-based environments, such as browsers and [node.js](https://nodejs.org). This enables you to use Streamr as an over-the-internet pub/sub engine with powerful analytics and automation features.
5
6
6
-
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.
7
+
The 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.
7
8
8
-
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.
9
+
### Installation
9
10
10
-
## Dependencies
11
+
The client is available on [npm](https://www.npmjs.com/package/streamr-client) and can be installed simpy by:
In node.js, dependencies will be installed automatically with `npm install`. In the browser, make sure you include `socket.io-client` before `streamr-client`.
20
+
In node.js, dependencies will be installed automatically with `npm install`. In the browser, make sure you include `socket.io-client` before `streamr-client` in your HTML.
16
21
17
-
## Usage
22
+
###Usage
18
23
19
-
The `examples` directory contains snippets for both browser and node.js.
24
+
The included `examples` directory contains snippets for both browser and node.js.
20
25
21
26
```javascript
22
-
var client =newStreamrClient({
23
-
// Connection options can be omitted, these are the default values
24
-
server:'https://data.streamr.com',
25
-
autoConnect:true,
26
-
autoDisconnect:true
27
+
// Create a StreamrClient instance
28
+
var client =newStreamrClient({
29
+
// Connection options can be omitted, these are the default values
30
+
server:'https://data.streamr.com',
31
+
autoConnect:true,
32
+
autoDisconnect:true
27
33
})
34
+
35
+
// Subscribe to a stream
28
36
var sub =client.subscribe(
29
-
'stream-id',
30
-
function(message, streamId, timestamp, counter) {
31
-
// Do something with the message, which is an object
32
-
},
33
-
{
34
-
// Resend options, see below
35
-
}
37
+
'stream-id',
38
+
function(message, streamId, timestamp, counter) {
39
+
// Do something with a message, which is an object
40
+
},
41
+
{
42
+
// Resend options, see below
43
+
}
36
44
)
37
-
client.connect()
38
45
```
39
46
40
-
## Handling messages
47
+
###Handling messages
41
48
42
49
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:
43
50
@@ -49,7 +56,7 @@ timestamp| (optional) A javascript Date object containing the timestamp for this
49
56
counter | (optional) A sequence number for this message, if available.
50
57
51
58
52
-
## Connection options
59
+
###Connection options
53
60
54
61
Option | Default value | Description
55
62
------ | ------------- | -----------
@@ -59,7 +66,7 @@ autoDisconnect | true | If set to `true`, the client automatically disconnects
59
66
transports | null | Override default transport selection / upgrade scheme. For example, value `["websocket"]` will force use of sockets right from the beginning, while value `["polling"]` will allow only long-polling to be used.
60
67
61
68
62
-
## Resend options
69
+
###Resend options
63
70
64
71
Note that only one of the resend options can be used for a particular subscription. The default functionality is to resend nothing, only subscribe to messages from the subscription moment onwards.
65
72
@@ -71,7 +78,7 @@ resend_from | undefined | Resend from a specific message number.
71
78
resend_from_time | undefined | Resend from a specific Date (or millisecond timestamp).
72
79
resend_to | undefined | Can be used in conjunction with `resend_from` to limit the end of the resend. By default it is the newest message.
73
80
74
-
## Methods
81
+
###Methods
75
82
76
83
Name | Description
77
84
---- | -----------
@@ -85,7 +92,7 @@ getSubscriptions(`streamId`) | Returns a list of `Subscriptions` for `streamId`.
85
92
bind(eventName, function) | Binds a `function` to an event called `eventName`
86
93
unbind(eventName, function) | Unbinds the `function` from events called `eventName`
87
94
88
-
## Binding to events
95
+
###Binding to events
89
96
90
97
The client and the subscriptions can fire events as detailed below. You can bind to them using `bind`:
91
98
@@ -109,14 +116,14 @@ You can unbind using `unbind`:
109
116
```
110
117
111
118
112
-
## Events on the StreamrClient instance
119
+
###Events on the StreamrClient instance
113
120
114
121
Name | Handler Arguments | Description
115
122
---- | ----------------- | -----------
116
123
connected | | Fired when the client has connected (or reconnected).
117
124
disconnected | | Fired when the client has disconnected (or paused).
118
125
119
-
## Events on the Subscription object
126
+
###Events on the Subscription object
120
127
121
128
Name | Handler Arguments | Description
122
129
---- | ----------------- | -----------
@@ -126,9 +133,9 @@ resending | | Fired when the subscription starts resending.
126
133
resent | | Fired after `resending` when the subscription has finished resending.
127
134
no_resend | | Fired after `resending` in case there was nothing to resend.
128
135
129
-
## Logging
136
+
###Logging
130
137
131
-
This library supports the [debug](https://github.com/visionmedia/debug) library for logging.
138
+
The Streamr JavaScript client library supports [debug](https://github.com/visionmedia/debug) for logging.
132
139
133
140
In node.js, start your app like this: `DEBUG=StreamrClient node your-app.js`
0 commit comments