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";
5
5
6
6
const debug = debugModule ( "socket.io-redis" ) ;
7
7
8
+ function looksLikeASocketId ( room : any ) {
9
+ return typeof room === "string" && room . length === 20 ;
10
+ }
11
+
8
12
export interface ShardedRedisAdapterOptions {
9
13
/**
10
14
* The prefix for the Redis Pub/Sub channels.
@@ -128,7 +132,8 @@ class ShardedRedisAdapter extends ClusterAdapter {
128
132
this . opts . subscriptionMode === "dynamic" &&
129
133
message . type === MessageType . BROADCAST &&
130
134
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 ] ) ;
132
137
if ( useDynamicChannel ) {
133
138
return this . dynamicChannel ( message . data . opts . rooms [ 0 ] ) ;
134
139
} else {
Original file line number Diff line number Diff line change @@ -110,6 +110,14 @@ export function testSuite(createAdapter: any) {
110
110
servers [ 0 ] . local . emit ( "test" ) ;
111
111
} ) ;
112
112
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
+
113
121
it ( "broadcasts with multiple acknowledgements" , ( done ) => {
114
122
clientSockets [ 0 ] . on ( "test" , ( cb ) => cb ( 1 ) ) ;
115
123
clientSockets [ 1 ] . on ( "test" , ( cb ) => cb ( 2 ) ) ;
You can’t perform that action at this time.
0 commit comments