Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Option | Default value | Description
server | api.streamr.com | Address of the server to connect to.
autoConnect | true | If set to `true`, the client connects automatically on the first call to `subscribe()`. Otherwise an explicit call to `connect()` is required.
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()`.
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.


## Resend options

Expand Down
9 changes: 7 additions & 2 deletions streamr-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ function StreamrClient(options) {
// Automatically connect on first subscribe
autoConnect: true,
// Automatically disconnect on last unsubscribe
autoDisconnect: true
autoDisconnect: true,
// Allow client socket library to choose appropriate transport
transports: null
}
this.subsByStream = {}
this.subById = {}
Expand Down Expand Up @@ -384,7 +386,10 @@ StreamrClient.prototype.connect = function(reconnect) {
this.connecting = true
this.disconnecting = false

this.socket = io(this.options.server, {forceNew: true})
this.socket = io(this.options.server, {
forceNew: true,
transports: this.options.transports
})

this.socket.on('ui', function(data) {
if (typeof data == 'string' || data instanceof String) {
Expand Down
29 changes: 28 additions & 1 deletion test/test.streamr-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('StreamrClient', function() {
socket = createSocketMock()

var ioCalls = 0
global.io = function() {
global.io = function(uri, opts) {
ioCalls++

// Create new sockets for subsequent calls
Expand All @@ -112,6 +112,9 @@ describe('StreamrClient', function() {
socket.emit('connect')
})

socket.uri = uri;
socket.opts = opts;

return socket
}

Expand All @@ -121,6 +124,30 @@ describe('StreamrClient', function() {
})

describe("connect", function() {
it('should not pass transport details in io() call', function(done) {
client.connect()
client.socket.on("connect", function() {
assert.strictEqual(client.socket.opts["transports"], null)
done()
})
})

context('when client initialized with transport details', function () {
beforeEach(function () {
client = new StreamrClient({
transports: ["websocket"]
})
})

it('should pass transport details in io() call', function(done) {
client.connect()
client.socket.on("connect", function() {
assert.deepEqual(client.socket.opts["transports"], ["websocket"])
done()
})
})
})

it('should emit pending subscribes', function(done) {
var subscription = client.subscribe("stream1", function(message) {})
client.connect()
Expand Down