-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix broadcasting from a parent namespace
- Loading branch information
1 parent
bfca280
commit 22c688d
Showing
4 changed files
with
13 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,44 @@ | ||
package socket | ||
|
||
import ( | ||
"github.com/zishang520/engine.io/v2/types" | ||
"github.com/zishang520/socket.io-go-parser/v2/parser" | ||
) | ||
|
||
type ( | ||
ParentBroadcastAdapterBuilder struct { | ||
AdapterConstructor | ||
|
||
Children *types.Set[Namespace] | ||
} | ||
|
||
// A dummy adapter that only supports broadcasting to child (concrete) namespaces. | ||
parentBroadcastAdapter struct { | ||
Adapter | ||
|
||
children *types.Set[Namespace] | ||
} | ||
) | ||
|
||
func (b *ParentBroadcastAdapterBuilder) New(nsp Namespace) Adapter { | ||
return NewParentBroadcastAdapter(nsp, b.Children) | ||
return NewParentBroadcastAdapter(nsp) | ||
} | ||
|
||
func MakeParentBroadcastAdapter(children *types.Set[Namespace]) ParentBroadcastAdapter { | ||
func MakeParentBroadcastAdapter() ParentBroadcastAdapter { | ||
s := &parentBroadcastAdapter{ | ||
Adapter: MakeAdapter(), | ||
|
||
children: children, | ||
} | ||
|
||
s.Prototype(s) | ||
|
||
return s | ||
} | ||
|
||
func NewParentBroadcastAdapter(nsp Namespace, children *types.Set[Namespace]) ParentBroadcastAdapter { | ||
s := MakeParentBroadcastAdapter(children) | ||
func NewParentBroadcastAdapter(nsp Namespace) ParentBroadcastAdapter { | ||
s := MakeParentBroadcastAdapter() | ||
|
||
s.Construct(nsp) | ||
|
||
return s | ||
} | ||
|
||
func (s *parentBroadcastAdapter) Construct(nsp Namespace) { | ||
s.Adapter.Construct(nsp) | ||
} | ||
|
||
func (s *parentBroadcastAdapter) Broadcast(packet *parser.Packet, opts *BroadcastOptions) { | ||
for _, nsp := range s.children.Keys() { | ||
for _, nsp := range s.Nsp().(ParentNamespace).Children().Keys() { | ||
nsp.Adapter().Broadcast(packet, opts) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters