File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,11 +159,16 @@ export interface IWebSocketConnection {
159159 broadcast ( data : any , options ?: { room ?: string ; includeSelf ?: boolean } ) : void ;
160160
161161 /**
162- * Broadcasts a message to all connections in all rooms that this connection is a member of.
163- * If not in any rooms, broadcasts globally.
162+ * Broadcasts a message to all connections that share at least one room with
163+ * this connection.
164+ *
165+ * Each room this connection belongs to is iterated and the message is sent
166+ * to every other member of that room (deduplication is handled at the
167+ * manager level). If the connection has not joined any room, this method is
168+ * a no-op — it does **not** fall back to a global broadcast.
164169 *
165170 * @param data - The data to broadcast
166- * @param includeSelf - Whether to include the current connection
171+ * @param includeSelf - Whether to include the current connection in the broadcast
167172 */
168173 broadcastAllRooms ( data : any , includeSelf ?: boolean ) : void ;
169174
Original file line number Diff line number Diff line change @@ -138,24 +138,20 @@ export class WebSocketConnection implements IWebSocketConnection {
138138 }
139139
140140 broadcastAllRooms ( data : any , includeSelf = false ) : void {
141- if ( this . rooms . size === 0 ) {
142- this . manager . broadcast ( data , { excludeId : includeSelf ? undefined : this . id } ) ;
143- } else {
144- this . rooms . forEach ( room => {
145- this . manager . broadcast ( data , { room, excludeId : includeSelf ? undefined : this . id } ) ;
146- } ) ;
147- }
141+ this . rooms . forEach ( room => {
142+ this . manager . broadcast ( data , { room, excludeId : includeSelf ? undefined : this . id } ) ;
143+ } ) ;
148144 }
149145
150146 ping ( payload ?: string | Buffer ) {
151- if ( this . _closed ) {
147+ if ( this . _closed ) {
152148 return ;
153149 }
154150 this . ws . ping ( payload ) ;
155151 }
156152
157153 pong ( payload ?: string | Buffer ) {
158- if ( this . _closed ) {
154+ if ( this . _closed ) {
159155 return ;
160156 }
161157 this . ws . pong ( payload ) ;
You can’t perform that action at this time.
0 commit comments