@@ -614,6 +614,122 @@ describe('socket.io', function(){
614
614
} ) ;
615
615
} ) ;
616
616
} ) ;
617
+
618
+ it ( 'should find all clients in a namespace' , function ( done ) {
619
+ var srv = http ( ) ;
620
+ var sio = io ( srv ) ;
621
+ var chatSids = [ ] ;
622
+ var otherSid = null ;
623
+ srv . listen ( function ( ) {
624
+ var c1 = client ( srv , '/chat' ) ;
625
+ var c2 = client ( srv , '/chat' , { forceNew : true } ) ;
626
+ var c3 = client ( srv , '/other' , { forceNew : true } ) ;
627
+ var total = 3 ;
628
+ sio . of ( '/chat' ) . on ( 'connection' , function ( socket ) {
629
+ chatSids . push ( socket . id ) ;
630
+ -- total || getClients ( ) ;
631
+ } ) ;
632
+ sio . of ( '/other' ) . on ( 'connection' , function ( socket ) {
633
+ otherSid = socket . id ;
634
+ -- total || getClients ( ) ;
635
+ } ) ;
636
+ } ) ;
637
+ function getClients ( ) {
638
+ sio . of ( '/chat' ) . clients ( function ( error , sids ) {
639
+ expect ( error ) . to . be . undefined ;
640
+ expect ( sids ) . to . contain ( chatSids [ 0 ] ) ;
641
+ expect ( sids ) . to . contain ( chatSids [ 1 ] ) ;
642
+ expect ( sids ) . to . not . contain ( otherSid ) ;
643
+ done ( ) ;
644
+ } ) ;
645
+ }
646
+ } ) ;
647
+
648
+ it ( 'should find all clients in a namespace room' , function ( done ) {
649
+ var srv = http ( ) ;
650
+ var sio = io ( srv ) ;
651
+ var chatFooSid = null ;
652
+ var chatBarSid = null ;
653
+ var otherSid = null ;
654
+ srv . listen ( function ( ) {
655
+ var c1 = client ( srv , '/chat' ) ;
656
+ var c2 = client ( srv , '/chat' , { forceNew : true } ) ;
657
+ var c3 = client ( srv , '/other' , { forceNew : true } ) ;
658
+ var chatIndex = 0 ;
659
+ var total = 3 ;
660
+ sio . of ( '/chat' ) . on ( 'connection' , function ( socket ) {
661
+ if ( chatIndex ++ ) {
662
+ socket . join ( 'foo' , function ( ) {
663
+ chatFooSid = socket . id ;
664
+ -- total || getClients ( ) ;
665
+ } ) ;
666
+ } else {
667
+ socket . join ( 'bar' , function ( ) {
668
+ chatBarSid = socket . id ;
669
+ -- total || getClients ( ) ;
670
+ } ) ;
671
+ }
672
+ } ) ;
673
+ sio . of ( '/other' ) . on ( 'connection' , function ( socket ) {
674
+ socket . join ( 'foo' , function ( ) {
675
+ otherSid = socket . id ;
676
+ -- total || getClients ( ) ;
677
+ } ) ;
678
+ } ) ;
679
+ } ) ;
680
+ function getClients ( ) {
681
+ sio . of ( '/chat' ) . in ( 'foo' ) . clients ( function ( error , sids ) {
682
+ expect ( error ) . to . be . undefined ;
683
+ expect ( sids ) . to . contain ( chatFooSid ) ;
684
+ expect ( sids ) . to . not . contain ( chatBarSid ) ;
685
+ expect ( sids ) . to . not . contain ( otherSid ) ;
686
+ done ( ) ;
687
+ } ) ;
688
+ }
689
+ } ) ;
690
+
691
+ it ( 'should find all clients across namespace rooms' , function ( done ) {
692
+ var srv = http ( ) ;
693
+ var sio = io ( srv ) ;
694
+ var chatFooSid = null ;
695
+ var chatBarSid = null ;
696
+ var otherSid = null ;
697
+ srv . listen ( function ( ) {
698
+ var c1 = client ( srv , '/chat' ) ;
699
+ var c2 = client ( srv , '/chat' , { forceNew : true } ) ;
700
+ var c3 = client ( srv , '/other' , { forceNew : true } ) ;
701
+ var chatIndex = 0 ;
702
+ var total = 3 ;
703
+ sio . of ( '/chat' ) . on ( 'connection' , function ( socket ) {
704
+ if ( chatIndex ++ ) {
705
+ socket . join ( 'foo' , function ( ) {
706
+ chatFooSid = socket . id ;
707
+ -- total || getClients ( ) ;
708
+ } ) ;
709
+ } else {
710
+ socket . join ( 'bar' , function ( ) {
711
+ chatBarSid = socket . id ;
712
+ -- total || getClients ( ) ;
713
+ } ) ;
714
+ }
715
+ } ) ;
716
+ sio . of ( '/other' ) . on ( 'connection' , function ( socket ) {
717
+ socket . join ( 'foo' , function ( ) {
718
+ otherSid = socket . id ;
719
+ -- total || getClients ( ) ;
720
+ } ) ;
721
+ } ) ;
722
+ } ) ;
723
+ function getClients ( ) {
724
+ sio . of ( '/chat' ) . clients ( function ( error , sids ) {
725
+ expect ( error ) . to . be . undefined ;
726
+ expect ( sids ) . to . contain ( chatFooSid ) ;
727
+ expect ( sids ) . to . contain ( chatBarSid ) ;
728
+ expect ( sids ) . to . not . contain ( otherSid ) ;
729
+ done ( ) ;
730
+ } ) ;
731
+ }
732
+ } ) ;
617
733
} ) ;
618
734
619
735
describe ( 'socket' , function ( ) {
0 commit comments