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

Commit 81e0f3d

Browse files
committed
readme updated
1 parent c573ac8 commit 81e0f3d

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

README.md

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff 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+
<a name="js-client"></a>
3+
## Streamr JavaScript Client
34

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.
56

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.
78

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
910

10-
## Dependencies
11+
The client is available on [npm](https://www.npmjs.com/package/streamr-client) and can be installed simpy by:
12+
13+
`npm install streamr-client`
14+
15+
### Dependencies
1116

1217
* [socket.io-client](https://cdn.socket.io/socket.io-1.3.7.js)
1318
* [debug](https://github.com/visionmedia/debug) (optional)
1419

15-
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.
1621

17-
## Usage
22+
### Usage
1823

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.
2025

2126
```javascript
22-
var client = new StreamrClient({
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 = new StreamrClient({
29+
// Connection options can be omitted, these are the default values
30+
server: 'https://data.streamr.com',
31+
autoConnect: true,
32+
autoDisconnect: true
2733
})
34+
35+
// Subscribe to a stream
2836
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+
}
3644
)
37-
client.connect()
3845
```
3946

40-
## Handling messages
47+
### Handling messages
4148

4249
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:
4350

@@ -49,7 +56,7 @@ timestamp| (optional) A javascript Date object containing the timestamp for this
4956
counter | (optional) A sequence number for this message, if available.
5057

5158

52-
## Connection options
59+
### Connection options
5360

5461
Option | Default value | Description
5562
------ | ------------- | -----------
@@ -59,7 +66,7 @@ autoDisconnect | true  | If set to `true`, the client automatically disconnects
5966
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.
6067

6168

62-
## Resend options
69+
### Resend options
6370

6471
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.
6572

@@ -71,7 +78,7 @@ resend_from | undefined | Resend from a specific message number.
7178
resend_from_time | undefined | Resend from a specific Date (or millisecond timestamp).
7279
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.
7380

74-
## Methods
81+
### Methods
7582

7683
Name | Description
7784
---- | -----------
@@ -85,7 +92,7 @@ getSubscriptions(`streamId`) | Returns a list of `Subscriptions` for `streamId`.
8592
bind(eventName, function) | Binds a `function` to an event called `eventName`
8693
unbind(eventName, function) | Unbinds the `function` from events called `eventName`
8794

88-
## Binding to events
95+
### Binding to events
8996

9097
The client and the subscriptions can fire events as detailed below. You can bind to them using `bind`:
9198

@@ -109,14 +116,14 @@ You can unbind using `unbind`:
109116
```
110117

111118

112-
## Events on the StreamrClient instance
119+
### Events on the StreamrClient instance
113120

114121
Name | Handler Arguments | Description
115122
---- | ----------------- | -----------
116123
connected | | Fired when the client has connected (or reconnected).
117124
disconnected | | Fired when the client has disconnected (or paused).
118125

119-
## Events on the Subscription object
126+
### Events on the Subscription object
120127

121128
Name | Handler Arguments | Description
122129
---- | ----------------- | -----------
@@ -126,9 +133,9 @@ resending | | Fired when the subscription starts resending.
126133
resent | | Fired after `resending` when the subscription has finished resending.
127134
no_resend | | Fired after `resending` in case there was nothing to resend.
128135

129-
## Logging
136+
### Logging
130137

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.
132139

133140
In node.js, start your app like this: `DEBUG=StreamrClient node your-app.js`
134141

0 commit comments

Comments
 (0)