@@ -143,6 +143,51 @@ var adapter = require('../');
143143 } ) ;
144144 } ) ;
145145
146+ it ( 'broadcasts to multiple rooms at a time' , function ( done ) {
147+ create ( function ( server1 , client1 ) {
148+ create ( function ( server2 , client2 ) {
149+ create ( function ( server3 , client3 ) {
150+ server1 . on ( 'connection' , function ( c1 ) {
151+ c1 . join ( 'foo' ) ;
152+ c1 . join ( 'bar' ) ;
153+ } ) ;
154+
155+ server2 . on ( 'connection' , function ( c2 ) {
156+ // does not join, performs broadcast
157+ c2 . on ( 'do broadcast' , function ( ) {
158+ c2 . broadcast . to ( 'foo' ) . to ( 'bar' ) . emit ( 'broadcast' ) ;
159+ } ) ;
160+ } ) ;
161+
162+ server3 . on ( 'connection' , function ( c3 ) {
163+ // does not join, signals broadcast
164+ client2 . emit ( 'do broadcast' ) ;
165+ } ) ;
166+
167+ var called = false ;
168+ client1 . on ( 'broadcast' , function ( ) {
169+ if ( called ) return done ( new Error ( 'Called more than once' ) )
170+ called = true ;
171+ setTimeout ( function ( ) {
172+ client1 . disconnect ( ) ;
173+ client2 . disconnect ( ) ;
174+ client3 . disconnect ( ) ;
175+ done ( ) ;
176+ } , 100 ) ;
177+ } ) ;
178+
179+ client2 . on ( 'broadcast' , function ( ) {
180+ throw new Error ( 'Not in room' ) ;
181+ } ) ;
182+
183+ client3 . on ( 'broadcast' , function ( ) {
184+ throw new Error ( 'Not in room' ) ;
185+ } ) ;
186+ } ) ;
187+ } ) ;
188+ } ) ;
189+ } ) ;
190+
146191 it ( 'doesn\'t broadcast when using the local flag' , function ( done ) {
147192 create ( function ( server1 , client1 ) {
148193 create ( function ( server2 , client2 ) {
0 commit comments