This repository was archived by the owner on Dec 21, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ) { } )
You can’t perform that action at this time.
0 commit comments