File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ import debugModule from "debug";
55
66const debug = debugModule ( "socket.io-redis" ) ;
77
8+ function looksLikeASocketId ( room : any ) {
9+ return typeof room === "string" && room . length === 20 ;
10+ }
11+
812export interface ShardedRedisAdapterOptions {
913 /**
1014 * The prefix for the Redis Pub/Sub channels.
@@ -128,7 +132,8 @@ class ShardedRedisAdapter extends ClusterAdapter {
128132 this . opts . subscriptionMode === "dynamic" &&
129133 message . type === MessageType . BROADCAST &&
130134 message . data . requestId === undefined &&
131- message . data . opts . rooms . length === 1 ;
135+ message . data . opts . rooms . length === 1 &&
136+ ! looksLikeASocketId ( message . data . opts . rooms [ 0 ] ) ;
132137 if ( useDynamicChannel ) {
133138 return this . dynamicChannel ( message . data . opts . rooms [ 0 ] ) ;
134139 } else {
Original file line number Diff line number Diff line change @@ -110,6 +110,14 @@ export function testSuite(createAdapter: any) {
110110 servers [ 0 ] . local . emit ( "test" ) ;
111111 } ) ;
112112
113+ it ( "broadcasts to a single client" , ( done ) => {
114+ clientSockets [ 0 ] . on ( "test" , shouldNotHappen ( done ) ) ;
115+ clientSockets [ 1 ] . on ( "test" , ( ) => done ( ) ) ;
116+ clientSockets [ 2 ] . on ( "test" , shouldNotHappen ( done ) ) ;
117+
118+ servers [ 0 ] . to ( serverSockets [ 1 ] . id ) . emit ( "test" ) ;
119+ } ) ;
120+
113121 it ( "broadcasts with multiple acknowledgements" , ( done ) => {
114122 clientSockets [ 0 ] . on ( "test" , ( cb ) => cb ( 1 ) ) ;
115123 clientSockets [ 1 ] . on ( "test" , ( cb ) => cb ( 2 ) ) ;
You can’t perform that action at this time.
0 commit comments