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

Commit 8243aa7

Browse files
committed
fix error in case same subscription is unsubscribed multiple times
1 parent 3930712 commit 8243aa7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

streamr-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ StreamrClient.prototype.unsubscribe = function(sub) {
356356
throw "unsubscribe: please give a Subscription object as an argument!"
357357

358358
// If this is the last subscription for this stream, unsubscribe the client too
359-
if (this.subsByStream[sub.streamId].length === 1 && this.connected && !this.disconnecting && sub.isSubscribed() && !sub.unsubscribing) {
359+
if (this.subsByStream[sub.streamId] !== undefined && this.subsByStream[sub.streamId].length === 1 && this.connected && !this.disconnecting && sub.isSubscribed() && !sub.unsubscribing) {
360360
sub.unsubscribing = true
361361
this._requestUnsubscribe(sub.streamId)
362362
}

test/test.streamr-client.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,25 @@ describe('StreamrClient', function() {
714714
})
715715
})
716716

717+
it('should not send another unsubscribed event if the same Subscription is unsubscribed multiple times', function(done) {
718+
var sub = client.subscribe("stream1", function(message) {})
719+
client.connect()
720+
721+
client.socket.once('subscribed', function() {
722+
client.unsubscribe(sub)
723+
})
724+
725+
client.socket.once('unsubscribed', function() {
726+
setTimeout(function() {
727+
client.unsubscribe(sub)
728+
done()
729+
client.socket.once('unsubscribed', function() {
730+
throw "Unsubscribed event sent more than once for same Subscription!"
731+
})
732+
})
733+
})
734+
})
735+
717736
it('should not unsubscribe the client from a stream when there are subscriptions remaining for that stream', function(done) {
718737
var sub1 = client.subscribe("stream1", function(message) {})
719738
var sub2 = client.subscribe("stream1", function(message) {})

0 commit comments

Comments
 (0)