@@ -36,6 +36,16 @@ export interface SaveStateOptions {
3636 immediate ?: boolean ;
3737}
3838
39+ /**
40+ * Options for the `_broadcastWithOptions` method.
41+ */
42+ export interface BroadcastInstanceOptions {
43+ /**
44+ * The connection IDs to be excluded from the broadcast.
45+ */
46+ exclude ?: string [ ] ;
47+ }
48+
3949/** Actor type alias with all `any` types. Used for `extends` in classes referencing this actor. */
4050// biome-ignore lint/suspicious/noExplicitAny: Needs to be used in `extends`
4151export type AnyActorInstance = ActorInstance < any , any , any , any > ;
@@ -1013,6 +1023,16 @@ export class ActorInstance<S, CP, CS, V> {
10131023 * @param args - The arguments to send with the event.
10141024 */
10151025 _broadcast < Args extends Array < unknown > > ( name : string , ...args : Args ) {
1026+ return this . _broadcastWithOptions ( { } , name , ...args ) ;
1027+ }
1028+
1029+ /**
1030+ * Broadcasts an event to all connected clients with options.
1031+ * @param opts - Options for the broadcast.
1032+ * @param name - The name of the event.
1033+ * @param args - The arguments to send with the event.
1034+ */
1035+ _broadcastWithOptions < Args extends Array < unknown > > ( opts : BroadcastInstanceOptions , name : string , ...args : Args ) {
10161036 this . #assertReady( ) ;
10171037
10181038 // Send to all connected clients
@@ -1028,8 +1048,14 @@ export class ActorInstance<S, CP, CS, V> {
10281048 } ,
10291049 } ) ;
10301050
1051+ const excludeList = opts . exclude ?? [ ] ;
1052+
10311053 // Send message to clients
10321054 for ( const connection of subscriptions ) {
1055+ if ( excludeList . includes ( connection . id ) ) {
1056+ continue ;
1057+ }
1058+
10331059 connection . _sendMessage ( toClientSerializer ) ;
10341060 }
10351061 }
0 commit comments