|
1 | 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 | 2 | <a name="js-client"></a> |
3 | | -## Streamr JavaScript Client |
| 3 | +## Streamr Javascript Client |
4 | 4 |
|
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 | +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. |
6 | 6 |
|
7 | | -The client uses [web sockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) under the hood for streaming message delivery. |
| 7 | +The client uses websockets for streaming message delivery. It should work in all modern browsers. |
8 | 8 |
|
9 | 9 | ### Installation |
10 | 10 |
|
11 | 11 | The client is available on [npm](https://www.npmjs.com/package/streamr-client) and can be installed simpy by: |
12 | 12 |
|
13 | 13 | `npm install streamr-client` |
14 | 14 |
|
15 | | -### Dependencies |
16 | | - |
17 | | -* [debug](https://github.com/visionmedia/debug) (optional) |
18 | | - |
19 | | -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. |
20 | | - |
21 | 15 | ### Usage |
22 | 16 |
|
23 | 17 | Here's a quick example. More detailed examples for the browser and node.js can be found [here](https://github.com/streamr-dev/streamr-client/tree/master/examples). |
24 | 18 |
|
25 | 19 | ```javascript |
26 | 20 | // Create a StreamrClient instance |
27 | 21 | var client = new StreamrClient({ |
28 | | - // Connection options can be omitted, these are the default values |
29 | | - server: 'https://data.streamr.com', |
30 | | - autoConnect: true, |
31 | | - autoDisconnect: true |
| 22 | + // See below for connection options |
32 | 23 | }) |
33 | 24 |
|
34 | 25 | // Subscribe to a stream |
@@ -60,20 +51,18 @@ counter | (optional) A sequence number for this message, if available. |
60 | 51 |
|
61 | 52 | Option | Default value | Description |
62 | 53 | ------ | ------------- | ----------- |
63 | | -server | api.streamr.com | Address of the server to connect to. |
| 54 | +url | ws://www.streamr.com/api/v1/ws | Address of the Streamr websocket endpoint to connect to. |
64 | 55 | autoConnect | true | If set to `true`, the client connects automatically on the first call to `subscribe()`. Otherwise an explicit call to `connect()` is required. |
65 | | -autoDisconnect | true | If set to `true`, the client automatically disconnects when the last channel is unsubscribed. Otherwise the connection is left open and can be disconnected explicitly by calling `disconnect()`. |
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. |
| 56 | +autoDisconnect | true | If set to `true`, the client automatically disconnects when the last stream is unsubscribed. Otherwise the connection is left open and can be disconnected explicitly by calling `disconnect()`. |
67 | 57 | authKey | null | Define default authKey to use when none is specified in subscribe |
68 | 58 |
|
69 | | - |
70 | 59 | ### Resend options |
71 | 60 |
|
72 | 61 | 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. |
73 | 62 |
|
74 | 63 | Option | Default value | Description |
75 | 64 | ------ | ------------- | ----------- |
76 | | -resend_all | undefined | Set to `true` if you want all the messages for the channel resent from the earliest available message. |
| 65 | +resend_all | undefined | Set to `true` if you want all the messages for the stream resent from the earliest available message. |
77 | 66 | resend_last | undefined | Resend the previous `N` messages. |
78 | 67 | resend_from | undefined | Resend from a specific message number. |
79 | 68 | resend_from_time | undefined | Resend from a specific Date (or millisecond timestamp). |
@@ -136,7 +125,7 @@ no_resend | | Fired after `resending` in case there was nothing to resend. |
136 | 125 |
|
137 | 126 | ### Logging |
138 | 127 |
|
139 | | -The Streamr JavaScript client library supports [debug](https://github.com/visionmedia/debug) for logging. |
| 128 | +The Streamr JS client library supports [debug](https://github.com/visionmedia/debug) for logging. |
140 | 129 |
|
141 | 130 | In node.js, start your app like this: `DEBUG=StreamrClient node your-app.js` |
142 | 131 |
|
|
0 commit comments