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

Commit b753bd1

Browse files
committed
rename 'channel' to 'stream' in requests and responses
1 parent 9ed086b commit b753bd1

File tree

3 files changed

+77
-89
lines changed

3 files changed

+77
-89
lines changed

README.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!-- 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. -->
22
<a name="js-client"></a>
3-
## Streamr JavaScript Client
3+
## Streamr Javascript Client
44

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

77
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.
88

@@ -12,24 +12,14 @@ The client is available on [npm](https://www.npmjs.com/package/streamr-client) a
1212

1313
`npm install streamr-client`
1414

15-
### Dependencies
16-
17-
* [socket.io-client](https://cdn.socket.io/socket.io-1.3.7.js)
18-
* [debug](https://github.com/visionmedia/debug) (optional)
19-
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.
21-
2215
### Usage
2316

2417
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).
2518

2619
```javascript
2720
// Create a StreamrClient instance
2821
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
22+
// See below for connection options
3323
})
3424

3525
// Subscribe to a stream
@@ -60,19 +50,17 @@ counter | (optional) A sequence number for this message, if available.
6050

6151
Option | Default value | Description
6252
------ | ------------- | -----------
63-
server | api.streamr.com | Address of the server to connect to.
53+
url | ws://www.streamr.com/api/v1/ws | Address of the Streamr websocket endpoint to connect to.
6454
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.
67-
55+
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()`.
6856

6957
### Resend options
7058

7159
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.
7260

7361
Option | Default value | Description
7462
------ | ------------- | -----------
75-
resend_all | undefined | Set to `true` if you want all the messages for the channel resent from the earliest available message.
63+
resend_all | undefined | Set to `true` if you want all the messages for the stream resent from the earliest available message.
7664
resend_last | undefined | Resend the previous `N` messages.
7765
resend_from | undefined | Resend from a specific message number.
7866
resend_from_time | undefined | Resend from a specific Date (or millisecond timestamp).
@@ -135,7 +123,7 @@ no_resend | | Fired after `resending` in case there was nothing to resend.
135123

136124
### Logging
137125

138-
The Streamr JavaScript client library supports [debug](https://github.com/visionmedia/debug) for logging.
126+
The Streamr JS client library supports [debug](https://github.com/visionmedia/debug) for logging.
139127

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

streamr-client.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390

391391
createSubscribeRequest: function(stream, resendOptions) {
392392
var req = {
393-
channel: stream
393+
stream: stream
394394
}
395395
Object.keys(resendOptions).forEach(function(key) {
396396
req[key] = resendOptions[key]
@@ -405,7 +405,7 @@
405405
function Connection(options) {
406406
EventEmitter.call(this);
407407
if (!options.url) {
408-
throw "Server is not defined!"
408+
throw "URL is not defined!"
409409
}
410410
this.options = options
411411
this.connected = false
@@ -840,10 +840,10 @@
840840

841841
this.connection.on('subscribed', function(response) {
842842
if (response.error) {
843-
_this.handleError("Error subscribing to "+response.channel+": "+response.error)
843+
_this.handleError("Error subscribing to "+response.stream+": "+response.error)
844844
}
845845
else {
846-
var subs = _this.subsByStream[response.channel]
846+
var subs = _this.subsByStream[response.stream]
847847
delete subs._subscribing
848848

849849
debug('Client subscribed: %o', response)
@@ -860,9 +860,9 @@
860860
this.connection.on('unsubscribed', function(response) {
861861
debug("Client unsubscribed: %o", response)
862862

863-
if (_this.subsByStream[response.channel]) {
863+
if (_this.subsByStream[response.stream]) {
864864
// Copy the list to avoid concurrent modifications
865-
var l = _this.subsByStream[response.channel].slice()
865+
var l = _this.subsByStream[response.stream].slice()
866866
l.forEach(function(sub) {
867867
_this._removeSubscription(sub)
868868
sub.emit('unsubscribed')
@@ -952,9 +952,9 @@
952952
}
953953

954954
StreamrClient.prototype._checkAutoDisconnect = function() {
955-
// Disconnect if no longer subscribed to any channels
955+
// Disconnect if no longer subscribed to any streams
956956
if (this.options.autoDisconnect && Object.keys(this.subsByStream).length === 0) {
957-
debug("Disconnecting due to no longer being subscribed to any channels")
957+
debug("Disconnecting due to no longer being subscribed to any streams")
958958
this.disconnect()
959959
}
960960
}
@@ -985,7 +985,7 @@
985985

986986
// If this is the first subscription for this stream, send a subscription request to the server
987987
if (!subs._subscribing && subscribedSubs.length === 0) {
988-
var req = extend({}, sub.options, {type: 'subscribe', channel: sub.streamId})
988+
var req = extend({}, sub.options, {type: 'subscribe', stream: sub.streamId})
989989
debug("_requestSubscribe: subscribing client: %o", req)
990990
subs._subscribing = true
991991
_this.connection.send(req)
@@ -1004,7 +1004,7 @@
10041004
debug("Client unsubscribing stream %o", streamId)
10051005
this.connection.send({
10061006
type: 'unsubscribe',
1007-
channel: streamId
1007+
stream: streamId
10081008
})
10091009
}
10101010

@@ -1021,7 +1021,7 @@
10211021

10221022
sub.resending = true
10231023

1024-
var request = extend({}, options, resendOptions, {type: 'resend', channel: sub.streamId, sub: sub.id})
1024+
var request = extend({}, options, resendOptions, {type: 'resend', stream: sub.streamId, sub: sub.id})
10251025
debug("_requestResend: %o", request)
10261026
this.connection.send(request)
10271027
}

0 commit comments

Comments
 (0)